1
16
17 package org.apache.wsrp4j.util;
18
19 import javax.xml.namespace.QName;
20
21 import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse;
22 import oasis.names.tc.wsrp.v1.types.ClonePortlet;
23 import oasis.names.tc.wsrp.v1.types.CookieProtocol;
24 import oasis.names.tc.wsrp.v1.types.DestroyFailed;
25 import oasis.names.tc.wsrp.v1.types.DestroyPortlets;
26 import oasis.names.tc.wsrp.v1.types.DestroyPortletsResponse;
27 import oasis.names.tc.wsrp.v1.types.GetMarkup;
28 import oasis.names.tc.wsrp.v1.types.GetPortletDescription;
29 import oasis.names.tc.wsrp.v1.types.GetPortletProperties;
30 import oasis.names.tc.wsrp.v1.types.GetPortletPropertyDescription;
31 import oasis.names.tc.wsrp.v1.types.GetServiceDescription;
32 import oasis.names.tc.wsrp.v1.types.InitCookie;
33 import oasis.names.tc.wsrp.v1.types.InteractionParams;
34 import oasis.names.tc.wsrp.v1.types.MarkupContext;
35 import oasis.names.tc.wsrp.v1.types.MarkupParams;
36 import oasis.names.tc.wsrp.v1.types.MarkupResponse;
37 import oasis.names.tc.wsrp.v1.types.MissingParametersFault;
38 import oasis.names.tc.wsrp.v1.types.ModifyRegistration;
39 import oasis.names.tc.wsrp.v1.types.PerformBlockingInteraction;
40 import oasis.names.tc.wsrp.v1.types.PortletContext;
41 import oasis.names.tc.wsrp.v1.types.PortletDescription;
42 import oasis.names.tc.wsrp.v1.types.PortletDescriptionResponse;
43 import oasis.names.tc.wsrp.v1.types.PortletPropertyDescriptionResponse;
44 import oasis.names.tc.wsrp.v1.types.PropertyList;
45 import oasis.names.tc.wsrp.v1.types.RegistrationContext;
46 import oasis.names.tc.wsrp.v1.types.RegistrationData;
47 import oasis.names.tc.wsrp.v1.types.ReleaseSessions;
48 import oasis.names.tc.wsrp.v1.types.Resource;
49 import oasis.names.tc.wsrp.v1.types.ResourceList;
50 import oasis.names.tc.wsrp.v1.types.RuntimeContext;
51 import oasis.names.tc.wsrp.v1.types.ServiceDescription;
52 import oasis.names.tc.wsrp.v1.types.SessionContext;
53 import oasis.names.tc.wsrp.v1.types.SetPortletProperties;
54 import oasis.names.tc.wsrp.v1.types.Templates;
55 import oasis.names.tc.wsrp.v1.types.UpdateResponse;
56 import oasis.names.tc.wsrp.v1.types.UserContext;
57
58 import org.apache.wsrp4j.log.LogManager;
59 import org.apache.wsrp4j.log.Logger;
60
61
70 public class ParameterChecker {
71
72 private Logger logger = LogManager.getLogManager().getLogger(
74 ParameterChecker.class);
75
76
79 public ParameterChecker() {
80 }
81
82
85 private boolean isCheckEnabled() {
86 if (logger.isLogging(Logger.TRACE_HIGH)) {
87 return true;
88 }
89 return false;
90 }
91
92
95
96
108 public void check(GetServiceDescription request)
109 throws MissingParametersFault {
110 if (isCheckEnabled()) {
111 if (request instanceof GetServiceDescription) {
113
114 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
116
117 }
118 else {
119 throwMissingParametersFault("Input object is not from type GetServiceDescription or is null");
120 }
121 }
122 }
123
124
136 public void check(ModifyRegistration request)
137 throws MissingParametersFault {
138 if (isCheckEnabled()) {
139 if (request instanceof ModifyRegistration) {
141
142 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
144 check(request.getRegistrationData(), Constants.NILLABLE_FALSE);
145
146 }
147 else {
148 throwMissingParametersFault("Input object is not from type ModifyRegistration or is null");
149 }
150 }
151 }
152
153
168 public void check(GetMarkup request) throws MissingParametersFault {
169 if (isCheckEnabled()) {
170 if (request instanceof GetMarkup) {
172
173 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
175 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
176 check(request.getRuntimeContext(), Constants.NILLABLE_FALSE);
177 check(request.getUserContext(), Constants.NILLABLE_TRUE);
178 check(request.getMarkupParams(), Constants.NILLABLE_FALSE);
179
180 }
181 else {
182 throwMissingParametersFault("Input object is not from type GetMarkup or is null");
183 }
184 }
185 }
186
187
203 public void check(PerformBlockingInteraction request)
204 throws MissingParametersFault {
205 if (isCheckEnabled()) {
206 if (request instanceof PerformBlockingInteraction) {
208
209 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
211 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
212 check(request.getRuntimeContext(), Constants.NILLABLE_FALSE);
213 check(request.getUserContext(), Constants.NILLABLE_TRUE);
214 check(request.getMarkupParams(), Constants.NILLABLE_FALSE);
215 check(request.getInteractionParams(), Constants.NILLABLE_FALSE);
216
217 }
218 else {
219 throwMissingParametersFault("Input object is not from type PerformBlockingInteraction or is null");
220 }
221 }
222 }
223
224
235 public void check(InitCookie request) throws MissingParametersFault {
236 if (isCheckEnabled()) {
237 if (request instanceof InitCookie) {
239
240 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
241
242 }
243 else {
244
245 throwMissingParametersFault("Input object is not from type InitCookie or is null");
246 }
247 }
248 }
249
250
263 public void check(GetPortletDescription request)
264 throws MissingParametersFault {
265 if (isCheckEnabled()) {
266 if (request instanceof GetPortletDescription) {
268 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
269 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
270 check(request.getUserContext(), Constants.NILLABLE_TRUE);
271
272 }
273 else {
274 throwMissingParametersFault("Input object is not from type GetPortletDescription or is null");
275 }
276 }
277 }
278
279
292 public void check(ClonePortlet request) throws MissingParametersFault {
293 if (isCheckEnabled()) {
294 if (request instanceof ClonePortlet) {
296
297 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
299 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
300 check(request.getUserContext(), Constants.NILLABLE_TRUE);
301
302 }
303 else {
304
305 throwMissingParametersFault("Input object is not a ClonePortlet or is null");
306 }
307 }
308 }
309
310
322 public void check(DestroyPortlets request) throws MissingParametersFault {
323 if (isCheckEnabled()) {
324 if (request instanceof DestroyPortlets) {
326
327 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
329 check(request.getPortletHandles(), Constants.NILLABLE_FALSE);
330
331 }
332 else {
333
334 throwMissingParametersFault("Input object is not a DestroyPortlets or is null");
335 }
336 }
337 }
338
339
353 public void check(SetPortletProperties request)
354 throws MissingParametersFault {
355 if (isCheckEnabled()) {
356 if (request instanceof SetPortletProperties) {
358
359 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
361 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
362 check(request.getUserContext(), Constants.NILLABLE_TRUE);
363 check(request.getPropertyList(), Constants.NILLABLE_FALSE);
364
365 }
366 else {
367
368 throwMissingParametersFault("Input object is not a SetPortletProperties or is null");
369 }
370 }
371 }
372
373
387 public void check(GetPortletProperties request)
388 throws MissingParametersFault {
389 if (isCheckEnabled()) {
390 if (request instanceof GetPortletProperties) {
392
393 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
395 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
396 check(request.getUserContext(), Constants.NILLABLE_TRUE);
397 check(request.getNames(), Constants.NILLABLE_TRUE);
398
399 }
400 else {
401 throwMissingParametersFault("Input object is not a GetPortletProperties or is null");
402 }
403 }
404 }
405
406
419 public void check(GetPortletPropertyDescription request)
420 throws MissingParametersFault {
421 if (isCheckEnabled()) {
422 if (request instanceof GetPortletPropertyDescription) {
424
425 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
427 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
428 check(request.getUserContext(), Constants.NILLABLE_TRUE);
429
430 }
431 else {
432
433 throwMissingParametersFault("Input object is not a GetPortletPropertyDescription or is null");
434 }
435 }
436 }
437
438
450 public void check(ReleaseSessions request) throws MissingParametersFault {
451 if (isCheckEnabled()) {
452 if (request instanceof ReleaseSessions) {
454
455 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
457
458 check(request.getSessionIDs(), Constants.NILLABLE_FALSE);
460
461 }
462 else {
463
464 throwMissingParametersFault("Input object is not a ReleaseSession or is null");
465 }
466 }
467 }
468
469
472
473
484 public void check(ServiceDescription response)
485 throws MissingParametersFault {
486 if (isCheckEnabled()) {
487 if (response instanceof ServiceDescription) {
489
490 if (response != null) {
491
492 }
493 else if (response.getOfferedPortlets() != null) {
494
495 PortletDescription[] portletDesc = response
496 .getOfferedPortlets();
497
498 for (int i = 0; i < portletDesc.length; i++) {
499
500 check(portletDesc[i]);
501 }
502
503 }
504 else if (response.getRequiresInitCookie() != null) {
505
506 check(response.getRequiresInitCookie(), true);
507
508 }
509 else if (response.getResourceList() != null) {
510
511 check(response.getResourceList(), true);
512
513 }
514 else {
515
516 throwMissingParametersFault("No valid service description.");
517 }
518 }
519 else {
520
521 throwMissingParametersFault("No valid service description response found.");
522 }
523 }
524 }
525
526
540 public void check(BlockingInteractionResponse response)
541 throws MissingParametersFault {
542 if (isCheckEnabled()) {
543 if (response instanceof BlockingInteractionResponse) {
545
546 if (response.getUpdateResponse() != null
547 && response.getRedirectURL() == null) {
548
549 check(response.getUpdateResponse());
550
551 }
552 else if (response.getRedirectURL() != null
553 && response.getUpdateResponse() == null) {
554
555
557 }
558 else {
559
560 throwMissingParametersFault("No valid blocking interaction response. UpdateResponse"
561 + "and redirect url are mutually exclusive");
562 }
563 }
564 else {
565
566 throwMissingParametersFault("No valid blocking interaction response found.");
567 }
568 }
569 }
570
571
585 private void check(UpdateResponse response) throws MissingParametersFault {
586
587 if (response instanceof UpdateResponse) {
589
590 check(response.getSessionContext(), Constants.NILLABLE_TRUE);
591 check(response.getPortletContext(), Constants.NILLABLE_TRUE);
592 check(response.getMarkupContext(), Constants.NILLABLE_TRUE);
593
594
596 }
597 else {
598
599 throwMissingParametersFault("No valid update response found.");
600 }
601 }
602
603
615 public void check(MarkupResponse response) throws MissingParametersFault {
616 if (isCheckEnabled()) {
617 if (response instanceof MarkupResponse) {
619
620 check(response.getMarkupContext(), Constants.NILLABLE_FALSE);
621 check(response.getSessionContext(), Constants.NILLABLE_TRUE);
622
623 }
624 else {
625
626 throwMissingParametersFault("No valid markup response found.");
627 }
628 }
629 }
630
631
643 public void check(PortletDescriptionResponse response)
644 throws MissingParametersFault {
645 if (isCheckEnabled()) {
646 if (response instanceof PortletDescriptionResponse) {
648
649 check(response.getPortletDescription());
650 check(response.getResourceList(), Constants.NILLABLE_TRUE);
651
652 }
653 else {
654
655 throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
656 }
657 }
658 }
659
660
671 public void check(PortletPropertyDescriptionResponse response)
672 throws MissingParametersFault {
673 if (isCheckEnabled()) {
674 if (response instanceof PortletPropertyDescriptionResponse) {
676
677
679 check(response.getResourceList(), Constants.NILLABLE_TRUE);
680
681 }
682 else {
683
684 throwMissingParametersFault("No valid PortletPropertyDescriptionResponse response found.");
685 }
686 }
687 }
688
689
700 public void check(DestroyPortletsResponse response)
701 throws MissingParametersFault {
702 if (isCheckEnabled()) {
703 if (response instanceof DestroyPortletsResponse) {
705
706 check(response.getDestroyFailed(), Constants.NILLABLE_TRUE);
707
708 }
709 else {
710
711 throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
712 }
713 }
714 }
715
716
719
720
732 public void check(PortletDescription element) throws MissingParametersFault {
733 if (isCheckEnabled()) {
734 if (element instanceof PortletDescription) {
736
737 if (element.getPortletHandle() == null) {
738 throwMissingParametersFault("A portlet handle has to be set in the portlet description.");
739 }
740
741 if (element.getMarkupTypes() == null) {
742 throwMissingParametersFault("Markup types have to be defined in the portlet description.");
743 }
744
745 }
746 else {
747
748 throwMissingParametersFault("No valid portlet description found.");
749 }
750 }
751 }
752
753
764 public void check(Templates element) throws MissingParametersFault {
765 if (isCheckEnabled()) {
766 if (element instanceof Templates) {
768 if (element.getDefaultTemplate() == null) {
769 throwMissingParametersFault("DefaultTemplate has not been set!");
770 }
771
772 if (element.getSecureDefaultTemplate() == null) {
773 throwMissingParametersFault("SecureDefaultTemplate Template has not been set!");
774 }
775 }
776 else {
777 throwMissingParametersFault("Consumer has to provide templates!");
778 }
779 }
780 }
781
782
796 private void check(SessionContext context, boolean nillable)
797 throws MissingParametersFault {
798 if (context != null) {
799 if (context.getSessionID() == null) {
800 throwMissingParametersFault("No valid session context found. No session handle set.");
801 }
802 else {
803 }
807 if (context.getExpires() == 0) {
808 throwMissingParametersFault("No valid session context found. No session expire set.");
809 }
810 }
811 else {
812 if (!nillable) {
813 throwMissingParametersFault("No valid session context found.");
814 }
815 }
816 }
817
818
832 private void check(MarkupContext context, boolean nillable)
833 throws MissingParametersFault {
834 if (context != null) {
835 boolean bMarkupBinary = false, bMarkupString = false;
836 if (context.getMarkupBinary() != null) {
837 bMarkupBinary = true;
838 }
839 if (context.getMarkupString() != null) {
840 bMarkupString = true;
841 }
842
843 if (bMarkupBinary ^ bMarkupString) {
845 if (context.getMimeType() == null) {
846 throwMissingParametersFault("MimeType not set in MarkupContext.");
847 }
848 else {
849 if (context.getLocale() == null) {
850 throwMissingParametersFault("Locale not set in MarkupContext.");
851 }
852 }
853 }
854 }
855 else {
856 if (!nillable) {
857 throwMissingParametersFault("No valid markup context found.");
858 }
859 }
860 }
861
862
875 public void check(PropertyList propertyList, boolean nillable)
876 throws MissingParametersFault {
877 if (isCheckEnabled()) {
878 if (propertyList != null) {
880 if (propertyList.getProperties() == null) {
882 throwMissingParametersFault("PropertyList[] in PropertyList is null");
883 }
884
885 }
886 else {
887 if (nillable == false) {
889 throwMissingParametersFault("PropertyList object is null");
890 }
891 }
892 }
893 }
894
895
909 public void check(RegistrationData registrationData, boolean nillable)
910 throws MissingParametersFault {
911 if (isCheckEnabled()) {
912 if (registrationData != null) {
914 if (registrationData.getConsumerName() == null) {
916 throwMissingParametersFault("ConsumerName in RegistrationData is null");
917 }
918 if (registrationData.getConsumerAgent() == null) {
920 throwMissingParametersFault("ConsumerAgent in RegistrationData is null");
921 }
922
923 }
924 else {
925 if (nillable == false) {
927 throwMissingParametersFault("RegistrationData object is null");
928 }
929 }
930 }
931 }
932
933
950 private void check(String[] array, boolean nillable)
951 throws MissingParametersFault {
952 if (array != null) {
954 if (array.length == 0) {
956 throwMissingParametersFault("String[] array length is zero (0)");
957 }
958 }
959 else {
960 if (nillable == false) {
962 throwMissingParametersFault("String array[] object is null");
963 }
964 }
965 }
966
967
981 private void check(InteractionParams interactionParams, boolean nillable)
982 throws MissingParametersFault {
983 if (interactionParams != null) {
985 if (interactionParams.getPortletStateChange() == null) {
987 throwMissingParametersFault("PortletStateChange in InteractionParams is null");
988 }
989 }
990 else {
991 if (nillable == false) {
993 throwMissingParametersFault("InteractionParams object is null");
994 }
995 }
996 }
997
998
1013 public void check(RegistrationContext registrationContext, boolean nillable)
1014 throws MissingParametersFault {
1015 if (isCheckEnabled()) {
1016 if (registrationContext != null) {
1018 if (registrationContext.getRegistrationHandle() == null) {
1020 throwMissingParametersFault("RegistrationHandle in RegistrationContext is null");
1021 }
1022 }
1023 else {
1024 if (nillable == false) {
1026 throwMissingParametersFault("RegistrationContext object is null");
1027 }
1028 }
1029 }
1030 }
1031
1032
1046 public void check(PortletContext portletContext, boolean nillable)
1047 throws MissingParametersFault {
1048 if (isCheckEnabled()) {
1049 if (portletContext != null) {
1051 if (portletContext.getPortletHandle() == null) {
1053 throwMissingParametersFault("PortletHandle in PortletContext is null");
1054 }
1055 }
1056 else {
1057 if (nillable == false) {
1059 throwMissingParametersFault("PortletContext object is null");
1060 }
1061 }
1062 }
1063 }
1064
1065
1080 private void check(RuntimeContext runtimeContext, boolean nillable)
1081 throws MissingParametersFault {
1082 if (runtimeContext != null) {
1084 if (runtimeContext.getUserAuthentication() == null) {
1086 throwMissingParametersFault("UserAuthentication in RuntimeContext is null");
1087 }
1088
1089 if (runtimeContext.getPortletInstanceKey() != null) {
1091 }
1094 }
1095 else {
1096 if (nillable == false) {
1098 throwMissingParametersFault("RuntimeContext object is null");
1099 }
1100 }
1101 }
1102
1103
1113 private void check(DestroyFailed[] destroyFailedArray, boolean nillable)
1114 throws MissingParametersFault {
1115 if (destroyFailedArray != null) {
1117 if (destroyFailedArray.length > 0) {
1118 for (int x = 0; x < destroyFailedArray.length; x++) {
1119 if (destroyFailedArray[x].getPortletHandle() == null) {
1121 throwMissingParametersFault("Missing Portlet handle in DestroyFailed object.");
1122 }
1123
1124 if (destroyFailedArray[x].getReason() == null) {
1126 throwMissingParametersFault("Missing Reason in DestroyFailed object.");
1127 }
1128 }
1129 }
1130 else {
1131 throwMissingParametersFault("DestroyFailedArray length is zero (0).");
1132 }
1133 }
1134 else {
1135 if (nillable == false) {
1137 throwMissingParametersFault("DestroyFailed[] object is null");
1138 }
1139 }
1140 }
1141
1142
1156 private void check(UserContext userContext, boolean nillable)
1157 throws MissingParametersFault {
1158 if (userContext != null) {
1160 if (userContext.getUserContextKey() == null) {
1162 throwMissingParametersFault("UserContextKey in UserContext is null");
1163 }
1164 }
1165 else {
1166 if (nillable == false) {
1168 throwMissingParametersFault("UserContext object is null");
1169 }
1170 }
1171 }
1172
1173
1181 private void check(ResourceList resourceList, boolean nillable)
1182 throws MissingParametersFault {
1183 if (resourceList != null) {
1185 if (resourceList.getResources() == null) {
1187 throwMissingParametersFault("Resource[] is null");
1188 }
1189 else {
1190 Resource[] resourceArray = resourceList.getResources();
1191 if (resourceArray.length < 1) {
1192 throwMissingParametersFault("ResourceArray length is zero (0).");
1193 }
1194 }
1195 }
1196 else {
1197 if (nillable == false) {
1199 throwMissingParametersFault("ResourceList object is null");
1200 }
1201 }
1202 }
1203
1204
1212 private void check(CookieProtocol requiresInit, boolean nillable)
1213 throws MissingParametersFault {
1214 if (requiresInit != null) {
1216 if (requiresInit.toString().equals(CookieProtocol._none)) {
1217 }
1218 else if (requiresInit.toString().equals(CookieProtocol._perGroup)) {
1219 }
1220 else if (requiresInit.toString().equals(CookieProtocol._perUser)) {
1221 }
1222 else {
1223 throwMissingParametersFault("Invalid value ("
1224 + requiresInit.toString()
1225 + ") of CookieProtocol object.");
1226 }
1227 }
1228 else {
1229 if (nillable == false) {
1231 throwMissingParametersFault("RequiresInitCookie object is null");
1232 }
1233 }
1234 }
1235
1236
1255 private void check(MarkupParams markupParams, boolean nillable)
1256 throws MissingParametersFault {
1257 if (markupParams != null) {
1259 if (markupParams.getClientData() == null) {
1261 throwMissingParametersFault("ClientData in MarkupParams is null");
1262 }
1263 if (markupParams.getLocales() == null) {
1264 throwMissingParametersFault("Locales in MarkupParams is null");
1265 }
1266 if (markupParams.getMimeTypes() == null) {
1267 throwMissingParametersFault("MimeTypes in MarkupParams is null");
1268 }
1269 if (markupParams.getMode() == null) {
1270 throwMissingParametersFault("Mode in MarkupParams is null");
1271 }
1272 if (markupParams.getWindowState() == null) {
1273 throwMissingParametersFault("WindowState in MarkupParams is null");
1274 }
1275 }
1276 else {
1277 if (nillable == false) {
1279 throwMissingParametersFault("MarkupParams object is null");
1280 }
1281 }
1282 }
1283
1284
1293 private void throwMissingParametersFault(String msg)
1294 throws MissingParametersFault {
1295 MissingParametersFault e = new MissingParametersFault();
1296 e.setFaultCode(new QName("urn:oasis:names:tc:wsrp:v1:types",
1297 "Interface.MissingParameters"));
1298 e.setFaultString(msg);
1299 throw e;
1300 }
1301}