Search in sources :

Example 1 with LogicalMessageContextImpl

use of org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl in project cxf by apache.

the class HandlerChainInvokerTest method testHandleMessageThrowsProtocolExceptionOutbound.

@Test
public void testHandleMessageThrowsProtocolExceptionOutbound() {
    message = new SoapMessage(message);
    lmc = new LogicalMessageContextImpl(message);
    pmc = new WrappedMessageContext(message);
    ProtocolException pe = new ProtocolException("banzai");
    protocolHandlers[2].setException(pe);
    invoker.setRequestor(true);
    assertTrue(invoker.isOutbound());
    boolean continueProcessing = true;
    invoker.setLogicalMessageContext(lmc);
    continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
    assertTrue(continueProcessing);
    // create an empty SOAP body for testing
    try {
        pmc = new SOAPMessageContextImpl(message);
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapMessage = factory.createMessage();
        ((SOAPMessageContext) pmc).setMessage(soapMessage);
    } catch (SOAPException e) {
    // do nothing
    }
    try {
        invoker.setProtocolMessageContext(pmc);
        continueProcessing = invoker.invokeProtocolHandlers(false, pmc);
        fail("did not get expected exception");
    } catch (ProtocolException e) {
        assertEquals("banzai", e.getMessage());
    }
    assertFalse((Boolean) pmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
    assertFalse((Boolean) lmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
    assertTrue(invoker.isInbound());
    // the message is replaced by fault message
    Source responseMessage = lmc.getMessage().getPayload();
    // System.out.println(getSourceAsString(responseMessage));
    assertTrue(getSourceAsString(responseMessage).indexOf("banzai") > -1);
    // assertFalse(continueProcessing);
    assertEquals(1, logicalHandlers[0].getHandleMessageCount());
    assertEquals(1, logicalHandlers[1].getHandleMessageCount());
    assertEquals(1, logicalHandlers[2].getHandleMessageCount());
    assertEquals(1, logicalHandlers[3].getHandleMessageCount());
    assertEquals(1, protocolHandlers[0].getHandleMessageCount());
    assertEquals(1, protocolHandlers[1].getHandleMessageCount());
    assertEquals(1, protocolHandlers[2].getHandleMessageCount());
    assertEquals(0, protocolHandlers[3].getHandleMessageCount());
    assertTrue(logicalHandlers[3].getInvokeOrderOfHandleMessage() < protocolHandlers[0].getInvokeOrderOfHandleMessage());
    assertTrue(protocolHandlers[1].getInvokeOrderOfHandleMessage() < protocolHandlers[2].getInvokeOrderOfHandleMessage());
    assertEquals(1, logicalHandlers[0].getCloseCount());
    assertEquals(1, logicalHandlers[1].getCloseCount());
    assertEquals(1, logicalHandlers[2].getCloseCount());
    assertEquals(1, logicalHandlers[3].getCloseCount());
    assertEquals(1, protocolHandlers[0].getCloseCount());
    assertEquals(1, protocolHandlers[1].getCloseCount());
    assertEquals(1, protocolHandlers[2].getCloseCount());
    assertEquals(0, protocolHandlers[3].getCloseCount());
    assertTrue(protocolHandlers[2].getInvokeOrderOfClose() < protocolHandlers[1].getInvokeOrderOfClose());
    assertTrue(protocolHandlers[0].getInvokeOrderOfClose() < logicalHandlers[3].getInvokeOrderOfClose());
    assertEquals(1, logicalHandlers[0].getHandleFaultCount());
    assertEquals(1, logicalHandlers[1].getHandleFaultCount());
    assertEquals(1, logicalHandlers[2].getHandleFaultCount());
    assertEquals(1, logicalHandlers[3].getHandleFaultCount());
    assertEquals(1, protocolHandlers[0].getHandleFaultCount());
    assertEquals(1, protocolHandlers[1].getHandleFaultCount());
    assertEquals(0, protocolHandlers[2].getHandleFaultCount());
    assertEquals(0, protocolHandlers[3].getHandleFaultCount());
    assertTrue(protocolHandlers[0].getInvokeOrderOfHandleFault() < logicalHandlers[3].getInvokeOrderOfHandleFault());
    assertTrue(protocolHandlers[2].getInvokeOrderOfHandleFault() < protocolHandlers[1].getInvokeOrderOfHandleFault());
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) MessageFactory(javax.xml.soap.MessageFactory) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) SOAPMessage(javax.xml.soap.SOAPMessage) Source(javax.xml.transform.Source) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessageContextImpl(org.apache.cxf.jaxws.handler.soap.SOAPMessageContextImpl) Test(org.junit.Test)

Example 2 with LogicalMessageContextImpl

use of org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl in project cxf by apache.

the class LogicalMessageImplTest method testGetPayloadOfJAXB.

@Test
public void testGetPayloadOfJAXB() throws Exception {
    // using Dispatch
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Message message = new MessageImpl();
    Exchange e = new ExchangeImpl();
    message.setExchange(e);
    LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
    JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);
    LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
    lmi.setPayload(el, ctx);
    Object obj = lmi.getPayload(ctx);
    assertTrue(obj instanceof JAXBElement);
    JAXBElement<?> el2 = (JAXBElement<?>) obj;
    assertTrue(el2.getValue() instanceof AddNumbers);
    AddNumbers resp = (AddNumbers) el2.getValue();
    assertEquals(req.getArg0(), resp.getArg0());
    assertEquals(req.getArg1(), resp.getArg1());
}
Also used : Message(org.apache.cxf.message.Message) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Exchange(org.apache.cxf.message.Exchange) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) MessageImpl(org.apache.cxf.message.MessageImpl) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 3 with LogicalMessageContextImpl

use of org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl in project cxf by apache.

the class HandlerChainInvokerTest method setUp.

@Before
public void setUp() {
    AbstractHandlerBase.clear();
    @SuppressWarnings("rawtypes") List<Handler> handlers = new ArrayList<>();
    for (int i = 0; i < logicalHandlers.length; i++) {
        logicalHandlers[i] = new TestLogicalHandler();
        handlers.add(logicalHandlers[i]);
    }
    for (int i = 0; i < protocolHandlers.length; i++) {
        protocolHandlers[i] = new TestProtocolHandler();
        handlers.add(protocolHandlers[i]);
    }
    invoker = new HandlerChainInvoker(handlers);
    message = new MessageImpl();
    Exchange e = new ExchangeImpl();
    message.setExchange(e);
    lmc = new LogicalMessageContextImpl(message);
    pmc = new WrappedMessageContext(message);
/*
        payload = new DOMSource();
        message.setContent(Source.class, payload);*/
}
Also used : ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) Exchange(org.apache.cxf.message.Exchange) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Aggregations

LogicalMessageContextImpl (org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl)3 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 Source (javax.xml.transform.Source)1 ProtocolException (javax.xml.ws.ProtocolException)1 Handler (javax.xml.ws.handler.Handler)1 LogicalHandler (javax.xml.ws.handler.LogicalHandler)1 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 LogicalMessageImpl (org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl)1 SOAPMessageContextImpl (org.apache.cxf.jaxws.handler.soap.SOAPMessageContextImpl)1