Search in sources :

Example 1 with LogicalMessage

use of javax.xml.ws.LogicalMessage in project scout.rt by eclipse.

the class AbstractValidationHandler method handleMessage.

@Override
public boolean handleMessage(LogicalMessageContext context) {
    if (MessageContexts.isOutboundMessage(context)) {
        return true;
    }
    LogicalMessage message = context.getMessage();
    Source payload = message.getPayload();
    Schema xsd = getXsd();
    try {
        xsd.newValidator().validate(payload);
    } catch (SAXException e) {
        throw new WebServiceException("Soap request message is not valid.", e);
    } catch (IOException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Schema(javax.xml.validation.Schema) LogicalMessage(javax.xml.ws.LogicalMessage) IOException(java.io.IOException) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException)

Example 2 with LogicalMessage

use of javax.xml.ws.LogicalMessage 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 3 with LogicalMessage

use of javax.xml.ws.LogicalMessage 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 4 with LogicalMessage

use of javax.xml.ws.LogicalMessage in project cxf by apache.

the class HandlerInvocationTest method testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers.

@Test
public void testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers() throws Exception {
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {

        public boolean handleFault(LogicalMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    Source source = msg.getPayload();
                    assertNotNull(source);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {

        public boolean handleFault(SOAPMessageContext ctx) {
            super.handleFault(ctx);
            Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            if (!outbound) {
                try {
                    SOAPMessage msg = ctx.getMessage();
                    assertNotNull(msg);
                } catch (Exception e) {
                    e.printStackTrace();
                    fail(e.toString());
                }
            }
            return true;
        }
    };
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
    try {
        handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultException");
        fail("did not get expected SOAPFaultException");
    } catch (SOAPFaultException e) {
    // e.printStackTrace();
    /*            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos, true);
            e.printStackTrace(ps);
            assertTrue("Did not get expected exception message",  baos.toString()
                .indexOf("HandleMessage throws exception") > -1);
            assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
                .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
    }
/*        assertEquals("handle message was not invoked", 1, handler1.getHandleMessageInvoked());
        assertEquals("handle message was not invoked", 1, handler2.getHandleMessageInvoked());
        assertEquals("handle message was not invoked", 1, soapHandler1.getHandleMessageInvoked());
        assertEquals("handle message was not invoked", 1, soapHandler2.getHandleMessageInvoked());

        assertEquals("handle message was not invoked", 1, handler1.getHandleFaultInvoked());
        assertEquals("handle message was not invoked", 1, handler2.getHandleFaultInvoked());
        assertEquals("handle message was not invoked", 1, soapHandler1.getHandleFaultInvoked());
        assertEquals("handle message was not invoked", 1, soapHandler2.getHandleFaultInvoked());

        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) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) LogicalMessage(javax.xml.ws.LogicalMessage) SOAPMessage(javax.xml.soap.SOAPMessage) Source(javax.xml.transform.Source) 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) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 5 with LogicalMessage

use of javax.xml.ws.LogicalMessage in project cxf by apache.

the class ModifyNumberHandler method handleMessage.

public final boolean handleMessage(LogicalMessageContext messageContext) {
    try {
        // get the LogicalMessage from our context
        LogicalMessage msg = messageContext.getMessage();
        // check the payload, if its an AddNumbers request, we'll intervene
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Object payload = msg.getPayload(jaxbContext);
        Object value = payload;
        if (payload instanceof JAXBElement) {
            value = ((JAXBElement<?>) payload).getValue();
        }
        if (value instanceof AddNumbers) {
            AddNumbers req = (AddNumbers) value;
            int a = req.getArg0();
            req.setArg0(a * 10);
            msg.setPayload(payload, jaxbContext);
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException) AddNumbers(org.apache.handlers.types.AddNumbers) JAXBContext(javax.xml.bind.JAXBContext) LogicalMessage(javax.xml.ws.LogicalMessage) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

LogicalMessage (javax.xml.ws.LogicalMessage)14 ProtocolException (javax.xml.ws.ProtocolException)9 WebServiceException (javax.xml.ws.WebServiceException)8 Source (javax.xml.transform.Source)7 LogicalMessageContext (javax.xml.ws.handler.LogicalMessageContext)6 Test (org.junit.Test)6 JAXBContext (javax.xml.bind.JAXBContext)5 TransformerException (javax.xml.transform.TransformerException)5 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)5 HandlerTest (org.apache.handler_test.HandlerTest)5 PingException (org.apache.handler_test.PingException)5 PingResponse (org.apache.handler_test.types.PingResponse)4 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)3 AddNumbers (org.apache.handlers.types.AddNumbers)3 AddNumbersResponse (org.apache.handlers.types.AddNumbersResponse)3 PingOneWay (org.apache.handler_test.types.PingOneWay)2 ObjectFactory (org.apache.handlers.types.ObjectFactory)2 IOException (java.io.IOException)1