Search in sources :

Example 6 with PingResponse

use of org.apache.handler_test.types.PingResponse in project cxf by apache.

the class HandlerInvocationTest method testLogicalHandlerHandleMessageReturnFalseClientOutBound.

@Test
public void testLogicalHandlerHandleMessageReturnFalseClientOutBound() throws Exception {
    final String clientHandlerMessage = "handler2 client side";
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {

        public boolean handleMessage(LogicalMessageContext ctx) {
            super.handleMessage(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    assertNotNull("logical message is null", msg);
                    JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils.getPackageName(PingOneWay.class));
                    PingResponse resp = new PingResponse();
                    resp.getHandlersInfo().add(clientHandlerMessage);
                    msg.setPayload(resp, jaxbCtx);
                    return false;
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    TestHandler<LogicalMessageContext> handler3 = new TestHandler<>(false);
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, handler3, soapHandler1);
    List<String> resp = handlerTest.ping();
    assertEquals(clientHandlerMessage, resp.get(0));
    assertEquals("the first handler must be invoked twice", 2, handler1.getHandleMessageInvoked());
    assertEquals("the second handler must be invoked once only on outbound", 1, handler2.getHandleMessageInvoked());
    assertEquals("the third handler must not be invoked", 0, handler3.getHandleMessageInvoked());
    assertEquals("the last handler must not be invoked", 0, soapHandler1.getHandleMessageInvoked());
    // outbound MEP processing ceased, the message direction was changed to inbound, essentially this is
    // only one MEP. So close is called only once at the end of inbound MEP, and the close order is
    // reversed to the outbound handler invoking order.
    assertEquals("close must be called", 1, handler1.getCloseInvoked());
    assertEquals("close must be called", 1, handler2.getCloseInvoked());
    assertEquals("close must be called", 0, handler3.getCloseInvoked());
    assertEquals("close must be called", 0, soapHandler1.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) JAXBContext(javax.xml.bind.JAXBContext) PingResponse(org.apache.handler_test.types.PingResponse) LogicalMessage(javax.xml.ws.LogicalMessage) PingException(org.apache.handler_test.PingException) ProtocolException(javax.xml.ws.ProtocolException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TransformerException(javax.xml.transform.TransformerException) WebServiceException(javax.xml.ws.WebServiceException) PingOneWay(org.apache.handler_test.types.PingOneWay) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 7 with PingResponse

use of org.apache.handler_test.types.PingResponse in project cxf by apache.

the class TestHandler method handlePingWithArgsMessage.

private boolean handlePingWithArgsMessage(boolean outbound, T ctx) {
    LogicalMessage msg = ctx.getMessage();
    Object payload = msg.getPayload(jaxbCtx);
    addHandlerId(ctx.getMessage(), ctx, outbound);
    boolean ret = true;
    if (payload instanceof PingWithArgs) {
        String arg = ((PingWithArgs) payload).getHandlersCommand();
        StringTokenizer strtok = new StringTokenizer(arg, " ");
        String hid = "";
        String direction = "";
        String command = "";
        if (strtok.countTokens() >= 3) {
            hid = strtok.nextToken();
            direction = strtok.nextToken();
            command = strtok.nextToken();
        }
        if (!getHandlerId().equals(hid)) {
            return true;
        }
        if ("stop".equals(command)) {
            if (!outbound && "inbound".equals(direction)) {
                PingResponse resp = new PingResponse();
                resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
                msg.setPayload(resp, jaxbCtx);
                ret = false;
            } else if (outbound && "outbound".equals(direction)) {
                ret = false;
            }
        } else if ("throw".equals(command)) {
            String exceptionType = null;
            String exceptionText = "HandleMessage throws exception";
            if (strtok.hasMoreTokens()) {
                exceptionType = strtok.nextToken();
            }
            if (strtok.hasMoreTokens()) {
                exceptionText = strtok.nextToken();
            }
            if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            }
        }
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) StringTokenizer(java.util.StringTokenizer) PingResponse(org.apache.handler_test.types.PingResponse) LogicalMessage(javax.xml.ws.LogicalMessage)

Aggregations

PingResponse (org.apache.handler_test.types.PingResponse)7 LogicalMessage (javax.xml.ws.LogicalMessage)4 ProtocolException (javax.xml.ws.ProtocolException)4 JAXBContext (javax.xml.bind.JAXBContext)3 PingException (org.apache.handler_test.PingException)3 PingWithArgs (org.apache.handler_test.types.PingWithArgs)3 TransformerException (javax.xml.transform.TransformerException)2 WebServiceException (javax.xml.ws.WebServiceException)2 LogicalMessageContext (javax.xml.ws.handler.LogicalMessageContext)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 HandlerTest (org.apache.handler_test.HandlerTest)2 Ping (org.apache.handler_test.types.Ping)2 PingOneWay (org.apache.handler_test.types.PingOneWay)2 Test (org.junit.Test)2 StringTokenizer (java.util.StringTokenizer)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)1 Element (org.w3c.dom.Element)1