Search in sources :

Example 1 with PingResponse

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

the class TestHandler method addHandlerId.

private void addHandlerId(LogicalMessage msg, T ctx, boolean outbound) {
    Object obj = msg.getPayload(jaxbCtx);
    if (obj instanceof PingResponse) {
        PingResponse origResp = (PingResponse) obj;
        PingResponse newResp = new PingResponse();
        newResp.getHandlersInfo().addAll(origResp.getHandlersInfo());
        newResp.getHandlersInfo().add(getHandlerId());
        msg.setPayload(newResp, jaxbCtx);
    } else if (obj instanceof Ping || obj instanceof PingWithArgs) {
        getHandlerInfoList(ctx).add(getHandlerId());
    }
}
Also used : PingWithArgs(org.apache.handler_test.types.PingWithArgs) Ping(org.apache.handler_test.types.Ping) PingResponse(org.apache.handler_test.types.PingResponse)

Example 2 with PingResponse

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

the class TestHandler method handleMessage.

public boolean handleMessage(T ctx) {
    methodCalled("handleMessage");
    printHandlerInfo("handleMessage", isOutbound(ctx));
    boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    boolean ret = getHandleMessageRet();
    if (!isServerSideHandler()) {
        return true;
    }
    try {
        verifyJAXWSProperties(ctx);
    } catch (PingException e) {
        e.printStackTrace();
        throw new ProtocolException(e);
    }
    Object obj = ctx.getMessage().getPayload(jaxbCtx);
    if (obj instanceof Ping || obj instanceof PingResponse) {
        ret = handlePingMessage(outbound, ctx);
    } else if (obj instanceof PingWithArgs) {
        ret = handlePingWithArgsMessage(outbound, ctx);
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) Ping(org.apache.handler_test.types.Ping) PingResponse(org.apache.handler_test.types.PingResponse) PingException(org.apache.handler_test.PingException)

Example 3 with PingResponse

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

the class TestHandler method checkServerOutBindStopHandler.

private boolean checkServerOutBindStopHandler(boolean outbound, T ctx) {
    if (outbound) {
        LogicalMessage msg = ctx.getMessage();
        Object obj = msg.getPayload(jaxbCtx);
        if (obj instanceof PingResponse) {
            // only check if we need call for the server response handler false
            PingResponse origResp = (PingResponse) obj;
            for (String handler : origResp.getHandlersInfo()) {
                if (handler.indexOf("server") == 0 && handler.indexOf(getHandlerId()) > 0 && handler.indexOf("stop") > 0) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PingResponse(org.apache.handler_test.types.PingResponse) LogicalMessage(javax.xml.ws.LogicalMessage)

Example 4 with PingResponse

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

the class HandlerInvocationTest method testSOAPHandlerHandleMessageReturnFalseClientOutbound.

@Test
public void testSOAPHandlerHandleMessageReturnFalseClientOutbound() throws Exception {
    final String clientHandlerMessage = "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);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {

        public boolean handleMessage(SOAPMessageContext ctx) {
            super.handleMessage(ctx);
            Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            if (outbound) {
                return false;
            }
            return true;
        }
    };
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
    List<String> resp = handlerTest.ping();
    assertEquals(clientHandlerMessage, resp.get(0));
    assertEquals(2, handler1.getHandleMessageInvoked());
    assertEquals(2, handler2.getHandleMessageInvoked());
    assertEquals(2, soapHandler1.getHandleMessageInvoked());
    assertEquals(1, soapHandler2.getHandleMessageInvoked());
    assertEquals("close must be called", 1, handler1.getCloseInvoked());
    assertEquals("close must be called", 1, handler2.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());
    assertTrue(soapHandler2.getInvokeOrderOfClose() < soapHandler1.getInvokeOrderOfClose());
    assertTrue(soapHandler1.getInvokeOrderOfClose() < handler2.getInvokeOrderOfClose());
    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) 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) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 5 with PingResponse

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

the class HandlerInvocationTest method getHandlerNames.

List<String> getHandlerNames(SOAPBody soapBody) throws Exception {
    Element elNode = DOMUtils.getFirstElement(soapBody);
    List<String> stringList = null;
    JAXBContext jaxbCtx = JAXBContext.newInstance(PingResponse.class);
    Unmarshaller um = jaxbCtx.createUnmarshaller();
    Object obj = um.unmarshal(elNode);
    if (obj instanceof PingResponse) {
        PingResponse pr = PingResponse.class.cast(obj);
        stringList = pr.getHandlersInfo();
    }
    return stringList;
}
Also used : Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) PingResponse(org.apache.handler_test.types.PingResponse) Unmarshaller(javax.xml.bind.Unmarshaller)

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