0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one
0003: * or more contributor license agreements. See the NOTICE file
0004: * distributed with this work for additional information
0005: * regarding copyright ownership. The ASF licenses this file
0006: * to you under the Apache License, Version 2.0 (the
0007: * "License"); you may not use this file except in compliance
0008: * with the License. You may obtain a copy of the License at
0009: *
0010: * http://www.apache.org/licenses/LICENSE-2.0
0011: *
0012: * Unless required by applicable law or agreed to in writing,
0013: * software distributed under the License is distributed on an
0014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015: * KIND, either express or implied. See the License for the
0016: * specific language governing permissions and limitations
0017: * under the License.
0018: */
0019: package org.apache.axis2.jaxws.handler;
0020:
0021: import java.util.ArrayList;
0022: import java.util.Set;
0023:
0024: import javax.xml.ws.ProtocolException;
0025: import javax.xml.ws.handler.Handler;
0026: import javax.xml.ws.handler.LogicalHandler;
0027: import javax.xml.ws.handler.soap.SOAPHandler;
0028: import javax.xml.ws.handler.soap.SOAPMessageContext;
0029:
0030: import junit.framework.TestCase;
0031:
0032: import org.apache.axis2.jaxws.core.MessageContext;
0033: import org.apache.axis2.jaxws.message.Protocol;
0034:
0035: /*
0036: * There are myriad scenarios to test here:
0037: * Handler implementations can implement two classes: SOAPHandler or LogicalHandler (2)
0038: * They implement two critical methods: handleMessage and handleFault (2)
0039: * These methods have four possible results: true, false, ProtocolException, other exception
0040: *
0041: * Besides the possible behaviors of the Handler implementations, we also
0042: * have to consider whether the message is incoming or outgoing, whether
0043: * it's a response or a request, and if a response is expected.
0044: *
0045: * Do our best to cover all scenarios.
0046: *
0047: * The testHandleMessage_* methods test the HandlerChainProcessor.processChain() method
0048: * The testHandleFault_* methods test the HandlerChainProcessor.processFault() method
0049: *
0050: */
0051: public class HandlerChainProcessorTests extends TestCase {
0052:
0053: // String result is how we'll verify the right methods from
0054: // the Handler implementations were called
0055: private String result = new String();
0056:
0057: private enum ResultDesired {
0058: TRUE, FALSE, PROTOCOL_EXCEPTION, OTHER_EXCEPTION
0059: };
0060:
0061: // use the following to dictate how the Handler methods behave
0062: private ResultDesired soaphandler1_MessageResultDesired;
0063: private ResultDesired soaphandler1_FaultResultDesired;
0064: private ResultDesired soaphandler2_MessageResultDesired;
0065: private ResultDesired soaphandler2_FaultResultDesired;
0066: private ResultDesired logicalhandler1_MessageResultDesired;
0067: private ResultDesired logicalhandler1_FaultResultDesired;
0068: private ResultDesired logicalhandler2_MessageResultDesired;
0069: private ResultDesired logicalhandler2_FaultResultDesired;
0070:
0071: ArrayList<Handler> handlers = new ArrayList<Handler>();
0072:
0073: @Override
0074: protected void setUp() throws Exception {
0075: // HandlerChainProcessor expects a sorted chain
0076: handlers.add(new LogicalHandler2());
0077: handlers.add(new LogicalHandler1());
0078: handlers.add(new SOAPHandler1());
0079: handlers.add(new SOAPHandler2());
0080: }
0081:
0082: /*
0083: * empty list
0084: */
0085: public void testHandleMessage_empty1() {
0086:
0087: Exception local_exception = null;
0088:
0089: HandlerChainProcessor processor1 = new HandlerChainProcessor(
0090: null, Protocol.soap11);
0091: HandlerChainProcessor processor2 = new HandlerChainProcessor(
0092: new ArrayList<Handler>(), Protocol.soap11);
0093: try {
0094: MessageContext mc1 = new MessageContext();
0095: mc1.setMEPContext(new MEPContext(mc1));
0096: processor1.processChain(mc1.getMEPContext(),
0097: HandlerChainProcessor.Direction.IN,
0098: HandlerChainProcessor.MEP.REQUEST, true);
0099: MessageContext mc2 = new MessageContext();
0100: mc2.setMEPContext(new MEPContext(mc2));
0101: processor2.processChain(mc2.getMEPContext(),
0102: HandlerChainProcessor.Direction.IN,
0103: HandlerChainProcessor.MEP.REQUEST, true);
0104: } catch (Exception e) {
0105: local_exception = e;
0106: }
0107:
0108: // no exceptions!
0109: assertNull(local_exception);
0110: }
0111:
0112: /*
0113: * one protocol handler
0114: * processing expected: Logical and SOAP, reverse order, close
0115: */
0116: public void testHandleMessage_oneproto1() {
0117:
0118: // reset result
0119: result = "";
0120:
0121: // use a local list
0122: ArrayList<Handler> local_list = new ArrayList<Handler>();
0123: local_list.add(new SOAPHandler1());
0124:
0125: // we want all good responses:
0126: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0127: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0128:
0129: HandlerChainProcessor processor = new HandlerChainProcessor(
0130: local_list, Protocol.soap11);
0131: MessageContext mc1 = new MessageContext();
0132: mc1.setMEPContext(new MEPContext(mc1));
0133: processor.processChain(mc1.getMEPContext(),
0134: HandlerChainProcessor.Direction.IN,
0135: HandlerChainProcessor.MEP.REQUEST, false);
0136:
0137: assertEquals("S1m:S1c:", result);
0138:
0139: }
0140:
0141: /*
0142: * one protocol handler in a logical context
0143: * no handlers will be processed
0144: */
0145: public void testHandleMessage_oneproto2() {
0146:
0147: // reset result
0148: result = "";
0149:
0150: // use a local list
0151: ArrayList<Handler> local_list = new ArrayList<Handler>();
0152: local_list.add(new SOAPHandler1());
0153:
0154: // we want all good responses:
0155: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0156: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0157:
0158: HandlerChainProcessor processor = new HandlerChainProcessor(
0159: local_list, Protocol.soap11);
0160: MessageContext mc1 = new MessageContext();
0161: mc1.setMEPContext(new MEPContext(mc1));
0162: processor.processChain(mc1.getMEPContext(),
0163: HandlerChainProcessor.Direction.IN,
0164: HandlerChainProcessor.MEP.REQUEST, false);
0165:
0166: assertEquals("S1m:S1c:", result);
0167: }
0168:
0169: /*
0170: * one logical handler
0171: * processing expected: Logical and SOAP, reverse order, close
0172: */
0173: public void testHandleMessage_onelogical() {
0174:
0175: // reset result
0176: result = "";
0177:
0178: // use a local list
0179: ArrayList<Handler> local_list = new ArrayList<Handler>();
0180: local_list.add(new LogicalHandler1());
0181:
0182: // we want all good responses:
0183: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0184: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0185:
0186: HandlerChainProcessor processor = new HandlerChainProcessor(
0187: local_list, Protocol.soap11);
0188: MessageContext mc1 = new MessageContext();
0189: mc1.setMEPContext(new MEPContext(mc1));
0190: processor.processChain(mc1.getMEPContext(),
0191: HandlerChainProcessor.Direction.IN,
0192: HandlerChainProcessor.MEP.REQUEST, false);
0193:
0194: assertEquals("L1m:L1c:", result);
0195: }
0196:
0197: /*
0198: * incoming request (we must be on the server), response expected
0199: * processing expected: Logical and SOAP, reverse order, no closing
0200: */
0201: public void testHandleMessage_true1() {
0202:
0203: // reset result
0204: result = "";
0205:
0206: // we want all good responses:
0207: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0208: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0209: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0210: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0211: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0212: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0213: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0214: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0215:
0216: HandlerChainProcessor processor = new HandlerChainProcessor(
0217: handlers, Protocol.soap11);
0218: MessageContext mc1 = new MessageContext();
0219: mc1.setMEPContext(new MEPContext(mc1));
0220: processor.processChain(mc1.getMEPContext(),
0221: HandlerChainProcessor.Direction.IN,
0222: HandlerChainProcessor.MEP.REQUEST, true);
0223:
0224: assertEquals("S2m:S1m:L1m:L2m:", result);
0225:
0226: }
0227:
0228: /*
0229: * incoming request (we must be on the server), response NOT expected
0230: * processing expected: Logical and SOAP, reverse order, close
0231: */
0232: public void testHandleMessage_true2() {
0233:
0234: // reset result
0235: result = "";
0236:
0237: // we want all good responses:
0238: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0239: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0240: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0241: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0242: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0243: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0244: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0245: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0246:
0247: HandlerChainProcessor processor = new HandlerChainProcessor(
0248: handlers, Protocol.soap11);
0249: MessageContext mc1 = new MessageContext();
0250: mc1.setMEPContext(new MEPContext(mc1));
0251: processor.processChain(mc1.getMEPContext(),
0252: HandlerChainProcessor.Direction.IN,
0253: HandlerChainProcessor.MEP.REQUEST, false);
0254:
0255: assertEquals("S2m:S1m:L1m:L2m:L2c:L1c:S1c:S2c:", result);
0256:
0257: }
0258:
0259: /*
0260: * incoming response (we must be on the client), response expected (ignored)
0261: * processing expected: Logical and SOAP, reverse order, close
0262: */
0263: public void testHandleMessage_true3() {
0264:
0265: // reset result
0266: result = "";
0267:
0268: // we want all good responses:
0269: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0270: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0271: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0272: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0273: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0274: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0275: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0276: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0277:
0278: HandlerChainProcessor processor = new HandlerChainProcessor(
0279: handlers, Protocol.soap11);
0280: MessageContext mc1 = new MessageContext();
0281: mc1.setMEPContext(new MEPContext(mc1));
0282: processor.processChain(mc1.getMEPContext(),
0283: HandlerChainProcessor.Direction.IN,
0284: HandlerChainProcessor.MEP.RESPONSE, true);
0285:
0286: /*
0287: * since this is client inbound response, the original outbound invocation
0288: * would have been L2m:L1m:S1m:S2m, so the closes would be S2c:S1c:L1c:L2c
0289: */
0290:
0291: assertEquals("S2m:S1m:L1m:L2m:S2c:S1c:L1c:L2c:", result);
0292:
0293: }
0294:
0295: /*
0296: * outgoing request (we must be on the client), response expected
0297: * processing expected: Logical and SOAP, normal order, no closing
0298: */
0299: public void testHandleMessage_true4() {
0300:
0301: // reset result
0302: result = "";
0303:
0304: // we want all good responses:
0305: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0306: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0307: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0308: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0309: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0310: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0311: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0312: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0313:
0314: HandlerChainProcessor processor = new HandlerChainProcessor(
0315: handlers, Protocol.soap11);
0316: MessageContext mc1 = new MessageContext();
0317: mc1.setMEPContext(new MEPContext(mc1));
0318: processor.processChain(mc1.getMEPContext(),
0319: HandlerChainProcessor.Direction.OUT,
0320: HandlerChainProcessor.MEP.REQUEST, true);
0321:
0322: assertEquals("L2m:L1m:S1m:S2m:", result);
0323: }
0324:
0325: /*
0326: * outgoing request (we must be on the client), response NOT expected
0327: * processing expected: Logical and SOAP, normal order, close
0328: */
0329: public void testHandleMessage_true5() {
0330:
0331: // reset result
0332: result = "";
0333:
0334: // we want all good responses:
0335: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0336: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0337: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0338: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0339: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0340: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0341: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0342: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0343:
0344: HandlerChainProcessor processor = new HandlerChainProcessor(
0345: handlers, Protocol.soap11);
0346: MessageContext mc1 = new MessageContext();
0347: mc1.setMEPContext(new MEPContext(mc1));
0348: processor.processChain(mc1.getMEPContext(),
0349: HandlerChainProcessor.Direction.OUT,
0350: HandlerChainProcessor.MEP.REQUEST, false);
0351:
0352: assertEquals("L2m:L1m:S1m:S2m:S2c:S1c:L1c:L2c:", result);
0353: }
0354:
0355: /*
0356: * outgoing response (we must be on the server), response expected (ignored)
0357: * processing expected: Logical and SOAP, normal order, close
0358: */
0359: public void testHandleMessage_true6() {
0360:
0361: // reset result
0362: result = "";
0363:
0364: // we want all good responses:
0365: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0366: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0367: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0368: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0369: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0370: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0371: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0372: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0373:
0374: HandlerChainProcessor processor = new HandlerChainProcessor(
0375: handlers, Protocol.soap11);
0376: MessageContext mc1 = new MessageContext();
0377: mc1.setMEPContext(new MEPContext(mc1));
0378: processor.processChain(mc1.getMEPContext(),
0379: HandlerChainProcessor.Direction.OUT,
0380: HandlerChainProcessor.MEP.RESPONSE, true);
0381:
0382: /*
0383: * since this is server outbound response, the original inbound invocation
0384: * would have been S2m:S1m:L1m:L2m, so the closes would be L2c:L1c:S1c:S2c
0385: */
0386:
0387: assertEquals("L2m:L1m:S1m:S2m:L2c:L1c:S1c:S2c:", result);
0388: }
0389:
0390: /*
0391: * At this point we know the sorting and closing logic is all good,
0392: * all that's left is to make sure the SOAP handlers are excluded when
0393: * we're in a LogicalMessageContext.
0394: *
0395: * outgoing response (we must be on the server), response expected (ignored)
0396: * processing expected: Logical only, normal order, close
0397: */
0398: public void testHandleMessage_true7() {
0399:
0400: // reset result
0401: result = "";
0402:
0403: // we want all good responses:
0404: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0405: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0406: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0407: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0408: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0409: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0410: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0411: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0412:
0413: HandlerChainProcessor processor = new HandlerChainProcessor(
0414: handlers, Protocol.soap11);
0415: MessageContext mc1 = new MessageContext();
0416: mc1.setMEPContext(new MEPContext(mc1));
0417: processor.processChain(mc1.getMEPContext(),
0418: HandlerChainProcessor.Direction.OUT,
0419: HandlerChainProcessor.MEP.RESPONSE, true);
0420:
0421: /*
0422: * since this is server outbound response, the original invocation
0423: * would have been S2m:S1m:L1m:L2m, so the closes would be L2c:L1c:S1c:S2c
0424: */
0425:
0426: assertEquals("L2m:L1m:S1m:S2m:L2c:L1c:S1c:S2c:", result);
0427: }
0428:
0429: /*
0430: * incoming request (we must be on the server), response expected
0431: * a middle Handler.handleMessage returns false
0432: * processing expected: Logical and SOAP, reverse order, message reversed, close
0433: */
0434: public void testHandleMessage_false1() {
0435:
0436: // reset result
0437: result = "";
0438:
0439: // we want one false response:
0440: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0441: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0442: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0443: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0444: logicalhandler1_MessageResultDesired = ResultDesired.FALSE;
0445: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0446: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0447: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0448:
0449: HandlerChainProcessor processor = new HandlerChainProcessor(
0450: handlers, Protocol.soap11);
0451: MessageContext mc1 = new MessageContext();
0452: mc1.setMEPContext(new MEPContext(mc1));
0453: processor.processChain(mc1.getMEPContext(),
0454: HandlerChainProcessor.Direction.IN,
0455: HandlerChainProcessor.MEP.REQUEST, true);
0456:
0457: assertEquals("S2m:S1m:L1m:S1m:S2m:L1c:S1c:S2c:", result);
0458: }
0459:
0460: /*
0461: * outgoing request (we must be on the client), response expected
0462: * a middle Handler.handleMessage returns false
0463: * processing expected: Logical and SOAP, normal order, message reversed, close
0464: */
0465: public void testHandleMessage_false2() {
0466:
0467: // reset result
0468: result = "";
0469:
0470: // we want one false response:
0471: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0472: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0473: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0474: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0475: logicalhandler1_MessageResultDesired = ResultDesired.FALSE;
0476: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0477: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0478: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0479:
0480: HandlerChainProcessor processor = new HandlerChainProcessor(
0481: handlers, Protocol.soap11);
0482: MessageContext mc1 = new MessageContext();
0483: mc1.setMEPContext(new MEPContext(mc1));
0484: processor.processChain(mc1.getMEPContext(),
0485: HandlerChainProcessor.Direction.OUT,
0486: HandlerChainProcessor.MEP.REQUEST, true);
0487:
0488: assertEquals("L2m:L1m:L2m:L1c:L2c:", result);
0489: }
0490:
0491: /*
0492: * outgoing request (we must be on the client), response NOT expected
0493: * a middle Handler.handleMessage returns false
0494: * processing expected: Logical and SOAP, normal order, message NOT reversed, close
0495: */
0496: public void testHandleMessage_false3() {
0497:
0498: // reset result
0499: result = "";
0500:
0501: // we want one false response:
0502: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0503: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0504: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0505: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0506: logicalhandler1_MessageResultDesired = ResultDesired.FALSE;
0507: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0508: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0509: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0510:
0511: HandlerChainProcessor processor = new HandlerChainProcessor(
0512: handlers, Protocol.soap11);
0513: MessageContext mc1 = new MessageContext();
0514: mc1.setMEPContext(new MEPContext(mc1));
0515: processor.processChain(mc1.getMEPContext(),
0516: HandlerChainProcessor.Direction.OUT,
0517: HandlerChainProcessor.MEP.REQUEST, false);
0518:
0519: assertEquals("L2m:L1m:L1c:L2c:", result);
0520: }
0521:
0522: /*
0523: * incoming request (we must be on the server), response expected
0524: * a middle Handler.handleMessage throws ProtocolException
0525: * processing expected: Logical and SOAP, reverse order, message reversed, handleFault, close
0526: */
0527: public void testHandleMessage_protocolex_true1() {
0528:
0529: // reset result
0530: result = "";
0531:
0532: // we want one false response:
0533: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0534: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0535: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0536: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0537: logicalhandler1_MessageResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0538: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0539: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0540: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0541:
0542: HandlerChainProcessor processor = new HandlerChainProcessor(
0543: handlers, Protocol.soap11);
0544: MessageContext mc1 = new MessageContext();
0545: mc1.setMEPContext(new MEPContext(mc1));
0546: processor.processChain(mc1.getMEPContext(),
0547: HandlerChainProcessor.Direction.IN,
0548: HandlerChainProcessor.MEP.REQUEST, true);
0549:
0550: // handleFault processing
0551: assertEquals("S2m:S1m:L1m:S1f:S2f:L1c:S1c:S2c:", result);
0552: }
0553:
0554: /*
0555: * incoming request (we must be on the server), response NOT expected
0556: * a middle Handler.handleMessage throws ProtocolException
0557: * processing expected: Logical and SOAP, reverse order, message NOT reversed, close
0558: */
0559: public void testHandleMessage_protocolex_true2() {
0560:
0561: // reset result
0562: result = "";
0563:
0564: // we want one false response:
0565: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0566: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0567: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0568: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0569: logicalhandler1_MessageResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0570: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0571: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0572: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0573:
0574: HandlerChainProcessor processor = new HandlerChainProcessor(
0575: handlers, Protocol.soap11);
0576: MessageContext mc1 = new MessageContext();
0577: mc1.setMEPContext(new MEPContext(mc1));
0578: processor.processChain(mc1.getMEPContext(),
0579: HandlerChainProcessor.Direction.IN,
0580: HandlerChainProcessor.MEP.REQUEST, false);
0581:
0582: // no handleFault calls
0583: assertEquals("S2m:S1m:L1m:L1c:S1c:S2c:", result);
0584: }
0585:
0586: /*
0587: * incoming request (we must be on the server), response expected
0588: * a middle Handler.handleMessage throws RuntimeException
0589: * processing expected: Logical and SOAP, reverse order, message reversed, (no handleFault), close
0590: */
0591: public void testHandleMessage_runtimeex_true() {
0592:
0593: // reset result
0594: result = "";
0595:
0596: // we want one false response:
0597: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0598: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0599: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0600: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0601: logicalhandler1_MessageResultDesired = ResultDesired.OTHER_EXCEPTION;
0602: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0603: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0604: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0605:
0606: HandlerChainProcessor processor = new HandlerChainProcessor(
0607: handlers, Protocol.soap11);
0608: MessageContext mc1 = new MessageContext();
0609: mc1.setMEPContext(new MEPContext(mc1));
0610: Exception e = null;
0611: try {
0612: processor.processChain(mc1.getMEPContext(),
0613: HandlerChainProcessor.Direction.IN,
0614: HandlerChainProcessor.MEP.REQUEST, true);
0615: } catch (RuntimeException re) {
0616: e = re;
0617: }
0618:
0619: assertNotNull(e);
0620: // no handleFault calls
0621: assertEquals("S2m:S1m:L1m:L1c:S1c:S2c:", result);
0622: }
0623:
0624: /*
0625: * incoming request (we must be on the server), response expected
0626: * a middle Handler.handleMessage throws ProtocolException, later a Handler.handleFault returns false
0627: * processing expected: Logical and SOAP, reverse order, message reversed, handleFault, close
0628: */
0629: public void testHandleMessage_protocolex_false() {
0630:
0631: // reset result
0632: result = "";
0633:
0634: // we want one false response:
0635: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0636: soaphandler1_FaultResultDesired = ResultDesired.FALSE;
0637: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0638: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0639: logicalhandler1_MessageResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0640: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0641: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0642: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0643:
0644: HandlerChainProcessor processor = new HandlerChainProcessor(
0645: handlers, Protocol.soap11);
0646: MessageContext mc1 = new MessageContext();
0647: mc1.setMEPContext(new MEPContext(mc1));
0648: processor.processChain(mc1.getMEPContext(),
0649: HandlerChainProcessor.Direction.IN,
0650: HandlerChainProcessor.MEP.REQUEST, true);
0651:
0652: // handleFault processing, but notice S2f does not get called
0653: assertEquals("S2m:S1m:L1m:S1f:L1c:S1c:S2c:", result);
0654: }
0655:
0656: /*
0657: * incoming request (we must be on the server), response expected
0658: * a middle Handler.handleMessage throws ProtocolException, later a Handler.handleFault throws ProtocolException
0659: * processing expected: Logical and SOAP, reverse order, message reversed, handleFault, close
0660: */
0661: public void testHandleMessage_protocolex_protocolex() {
0662:
0663: // reset result
0664: result = "";
0665:
0666: // we want one false response:
0667: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0668: soaphandler1_FaultResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0669: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0670: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0671: logicalhandler1_MessageResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0672: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0673: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0674: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0675:
0676: HandlerChainProcessor processor = new HandlerChainProcessor(
0677: handlers, Protocol.soap11);
0678: MessageContext mc1 = new MessageContext();
0679: mc1.setMEPContext(new MEPContext(mc1));
0680: Exception e = null;
0681: try {
0682: // handleFault processing, but notice S2f does not get called, and we get an exception
0683: processor.processChain(mc1.getMEPContext(),
0684: HandlerChainProcessor.Direction.IN,
0685: HandlerChainProcessor.MEP.REQUEST, true);
0686: } catch (ProtocolException pe) {
0687: e = pe;
0688: }
0689:
0690: assertNotNull(e);
0691: assertEquals("S2m:S1m:L1m:S1f:L1c:S1c:S2c:", result);
0692: }
0693:
0694: /*
0695: * incoming request (we must be on the server), response expected
0696: * a middle Handler.handleMessage throws ProtocolException, later a Handler.handleFault throws ProtocolException
0697: * processing expected: Logical and SOAP, reverse order, handleFault, close
0698: */
0699: public void testHandleMessage_protocolex_runtimeex() {
0700:
0701: // reset result
0702: result = "";
0703:
0704: // we want one false response:
0705: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0706: soaphandler1_FaultResultDesired = ResultDesired.OTHER_EXCEPTION;
0707: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0708: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0709: logicalhandler1_MessageResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0710: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0711: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0712: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0713:
0714: HandlerChainProcessor processor = new HandlerChainProcessor(
0715: handlers, Protocol.soap11);
0716: MessageContext mc1 = new MessageContext();
0717: mc1.setMEPContext(new MEPContext(mc1));
0718: Exception e = null;
0719: try {
0720: // same results as testHandlers_protocolex_protocolex
0721: processor.processChain(mc1.getMEPContext(),
0722: HandlerChainProcessor.Direction.IN,
0723: HandlerChainProcessor.MEP.REQUEST, true);
0724: } catch (RuntimeException pe) {
0725: e = pe;
0726: }
0727:
0728: assertNotNull(e);
0729: assertEquals("S2m:S1m:L1m:S1f:L1c:S1c:S2c:", result);
0730: }
0731:
0732: /*
0733: * empty list
0734: */
0735: public void testHandleFault_empty1() {
0736:
0737: Exception local_exception = null;
0738:
0739: HandlerChainProcessor processor1 = new HandlerChainProcessor(
0740: null, Protocol.soap11);
0741: HandlerChainProcessor processor2 = new HandlerChainProcessor(
0742: new ArrayList<Handler>(), Protocol.soap11);
0743: try {
0744: MessageContext mc1 = new MessageContext();
0745: mc1.setMEPContext(new MEPContext(mc1));
0746: processor1.processFault(mc1.getMEPContext(),
0747: HandlerChainProcessor.Direction.IN);
0748: MessageContext mc2 = new MessageContext();
0749: mc2.setMEPContext(new MEPContext(mc2));
0750: processor2.processFault(mc2.getMEPContext(),
0751: HandlerChainProcessor.Direction.IN);
0752: } catch (Exception e) {
0753: local_exception = e;
0754: }
0755:
0756: // no exceptions!
0757: assertNull(local_exception);
0758: }
0759:
0760: /*
0761: * outgoing response (we must be on the server), response expected (ignored)
0762: * processing expected: Logical and SOAP, normal order, handleFault, close
0763: */
0764: public void testHandleFault_true1() {
0765:
0766: // reset result
0767: result = "";
0768:
0769: // we want one false response:
0770: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0771: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0772: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0773: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0774: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0775: logicalhandler1_FaultResultDesired = ResultDesired.TRUE;
0776: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0777: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0778:
0779: HandlerChainProcessor processor = new HandlerChainProcessor(
0780: handlers, Protocol.soap11);
0781: MessageContext mc1 = new MessageContext();
0782: mc1.setMEPContext(new MEPContext(mc1));
0783: processor.processFault(mc1.getMEPContext(),
0784: HandlerChainProcessor.Direction.OUT);
0785:
0786: assertEquals("L2f:L1f:S1f:S2f:L2c:L1c:S1c:S2c:", result);
0787: }
0788:
0789: /*
0790: * outgoing response (we must be on the server)
0791: * a middle Handler.handleFault returns false
0792: * processing expected: Logical and SOAP, normal order, handleFault, close (all)
0793: */
0794: public void testHandleFault_false1() {
0795:
0796: // reset result
0797: result = "";
0798:
0799: // we want one false response:
0800: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0801: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0802: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0803: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0804: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0805: logicalhandler1_FaultResultDesired = ResultDesired.FALSE;
0806: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0807: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0808:
0809: HandlerChainProcessor processor = new HandlerChainProcessor(
0810: handlers, Protocol.soap11);
0811: MessageContext mc1 = new MessageContext();
0812: mc1.setMEPContext(new MEPContext(mc1));
0813: processor.processFault(mc1.getMEPContext(),
0814: HandlerChainProcessor.Direction.OUT);
0815:
0816: // notice all handlers are closed in this scenario
0817: assertEquals("L2f:L1f:L2c:L1c:S1c:S2c:", result);
0818: }
0819:
0820: /*
0821: * incoming response (we must be on the client)
0822: * a middle Handler.handleFault throws ProtocolException
0823: * processing expected: Logical and SOAP, reverse order, handleFault, close (all)
0824: */
0825: public void testHandleFault_protocolex() {
0826:
0827: // reset result
0828: result = "";
0829:
0830: // we want one false response:
0831: soaphandler1_MessageResultDesired = ResultDesired.TRUE;
0832: soaphandler1_FaultResultDesired = ResultDesired.TRUE;
0833: soaphandler2_MessageResultDesired = ResultDesired.TRUE;
0834: soaphandler2_FaultResultDesired = ResultDesired.TRUE;
0835: logicalhandler1_MessageResultDesired = ResultDesired.TRUE;
0836: logicalhandler1_FaultResultDesired = ResultDesired.PROTOCOL_EXCEPTION;
0837: logicalhandler2_MessageResultDesired = ResultDesired.TRUE;
0838: logicalhandler2_FaultResultDesired = ResultDesired.TRUE;
0839:
0840: HandlerChainProcessor processor = new HandlerChainProcessor(
0841: handlers, Protocol.soap11);
0842: MessageContext mc1 = new MessageContext();
0843: mc1.setMEPContext(new MEPContext(mc1));
0844: Exception e = null;
0845: try {
0846: // notice all handlers are closed in this scenario, and we get an exception
0847: processor.processFault(mc1.getMEPContext(),
0848: HandlerChainProcessor.Direction.IN);
0849: } catch (ProtocolException pe) {
0850: e = pe;
0851: }
0852:
0853: assertNotNull(e);
0854: assertEquals("S2f:S1f:L1f:S2c:S1c:L1c:L2c:", result);
0855: }
0856:
0857: private class SOAPHandler1 implements
0858: SOAPHandler<SOAPMessageContext> {
0859:
0860: public Set getHeaders() {
0861: return null;
0862: }
0863:
0864: public void close(
0865: javax.xml.ws.handler.MessageContext messagecontext) {
0866: result = result.concat("S1c:");
0867: }
0868:
0869: public boolean handleFault(SOAPMessageContext messagecontext) {
0870: result = result.concat("S1f:");
0871: if (soaphandler1_FaultResultDesired == ResultDesired.TRUE)
0872: return true;
0873: else if (soaphandler1_FaultResultDesired == ResultDesired.FALSE)
0874: return false;
0875: else if (soaphandler1_FaultResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0876: throw new ProtocolException();
0877: else if (soaphandler1_FaultResultDesired == ResultDesired.OTHER_EXCEPTION)
0878: throw new RuntimeException();
0879:
0880: // default
0881: return true;
0882: }
0883:
0884: public boolean handleMessage(SOAPMessageContext messagecontext) {
0885: result = result.concat("S1m:");
0886: if (soaphandler1_MessageResultDesired == ResultDesired.TRUE)
0887: return true;
0888: else if (soaphandler1_MessageResultDesired == ResultDesired.FALSE)
0889: return false;
0890: else if (soaphandler1_MessageResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0891: throw new ProtocolException();
0892: else if (soaphandler1_MessageResultDesired == ResultDesired.OTHER_EXCEPTION)
0893: throw new RuntimeException();
0894:
0895: // default
0896: return true;
0897: }
0898:
0899: }
0900:
0901: private class SOAPHandler2 implements
0902: SOAPHandler<SOAPMessageContext> {
0903:
0904: public Set getHeaders() {
0905: return null;
0906: }
0907:
0908: public void close(
0909: javax.xml.ws.handler.MessageContext messagecontext) {
0910: result = result.concat("S2c:");
0911: }
0912:
0913: public boolean handleFault(SOAPMessageContext messagecontext) {
0914: result = result.concat("S2f:");
0915: if (soaphandler2_FaultResultDesired == ResultDesired.TRUE)
0916: return true;
0917: else if (soaphandler2_FaultResultDesired == ResultDesired.FALSE)
0918: return false;
0919: else if (soaphandler2_FaultResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0920: throw new ProtocolException();
0921: else if (soaphandler2_FaultResultDesired == ResultDesired.OTHER_EXCEPTION)
0922: throw new RuntimeException();
0923:
0924: // default
0925: return true;
0926: }
0927:
0928: public boolean handleMessage(SOAPMessageContext messagecontext) {
0929: result = result.concat("S2m:");
0930: if (soaphandler2_MessageResultDesired == ResultDesired.TRUE)
0931: return true;
0932: else if (soaphandler2_MessageResultDesired == ResultDesired.FALSE)
0933: return false;
0934: else if (soaphandler2_MessageResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0935: throw new ProtocolException();
0936: else if (soaphandler2_MessageResultDesired == ResultDesired.OTHER_EXCEPTION)
0937: throw new RuntimeException();
0938:
0939: // default
0940: return true;
0941: }
0942:
0943: }
0944:
0945: private class LogicalHandler1 implements
0946: LogicalHandler<LogicalMessageContext> {
0947:
0948: public void close(
0949: javax.xml.ws.handler.MessageContext messagecontext) {
0950: result = result.concat("L1c:");
0951: }
0952:
0953: public boolean handleFault(LogicalMessageContext messagecontext) {
0954: result = result.concat("L1f:");
0955: if (logicalhandler1_FaultResultDesired == ResultDesired.TRUE)
0956: return true;
0957: else if (logicalhandler1_FaultResultDesired == ResultDesired.FALSE)
0958: return false;
0959: else if (logicalhandler1_FaultResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0960: throw new ProtocolException();
0961: else if (logicalhandler1_FaultResultDesired == ResultDesired.OTHER_EXCEPTION)
0962: throw new RuntimeException();
0963:
0964: // default
0965: return true;
0966: }
0967:
0968: public boolean handleMessage(
0969: LogicalMessageContext messagecontext) {
0970: result = result.concat("L1m:");
0971: if (logicalhandler1_MessageResultDesired == ResultDesired.TRUE)
0972: return true;
0973: else if (logicalhandler1_MessageResultDesired == ResultDesired.FALSE)
0974: return false;
0975: else if (logicalhandler1_MessageResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
0976: throw new ProtocolException();
0977: else if (logicalhandler1_MessageResultDesired == ResultDesired.OTHER_EXCEPTION)
0978: throw new RuntimeException();
0979:
0980: // default
0981: return true;
0982: }
0983:
0984: }
0985:
0986: private class LogicalHandler2 implements
0987: LogicalHandler<LogicalMessageContext> {
0988:
0989: public void close(
0990: javax.xml.ws.handler.MessageContext messagecontext) {
0991: result = result.concat("L2c:");
0992: }
0993:
0994: public boolean handleFault(LogicalMessageContext messagecontext) {
0995: result = result.concat("L2f:");
0996: if (logicalhandler2_FaultResultDesired == ResultDesired.TRUE)
0997: return true;
0998: else if (logicalhandler2_FaultResultDesired == ResultDesired.FALSE)
0999: return false;
1000: else if (logicalhandler2_FaultResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
1001: throw new ProtocolException();
1002: else if (logicalhandler2_FaultResultDesired == ResultDesired.OTHER_EXCEPTION)
1003: throw new RuntimeException();
1004:
1005: // default
1006: return true;
1007: }
1008:
1009: public boolean handleMessage(
1010: LogicalMessageContext messagecontext) {
1011: result = result.concat("L2m:");
1012: if (logicalhandler2_MessageResultDesired == ResultDesired.TRUE)
1013: return true;
1014: else if (logicalhandler2_MessageResultDesired == ResultDesired.FALSE)
1015: return false;
1016: else if (logicalhandler2_MessageResultDesired == ResultDesired.PROTOCOL_EXCEPTION)
1017: throw new ProtocolException();
1018: else if (logicalhandler2_MessageResultDesired == ResultDesired.OTHER_EXCEPTION)
1019: throw new RuntimeException();
1020:
1021: // default
1022: return true;
1023: }
1024:
1025: }
1026:
1027: }
|