Search in sources :

Example 1 with HandlerChainInvoker

use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.

the class SOAPHandlerInterceptorTest method testGetUnderstoodHeadersReturnsNull.

@Test
public void testGetUnderstoodHeadersReturnsNull() {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new SOAPHandler<SOAPMessageContext>() {

        public boolean handleMessage(SOAPMessageContext smc) {
            return true;
        }

        public boolean handleFault(SOAPMessageContext smc) {
            return true;
        }

        public Set<QName> getHeaders() {
            return null;
        }

        public void close(MessageContext messageContext) {
        }
    });
    HandlerChainInvoker invoker = new HandlerChainInvoker(list);
    IMocksControl control = createNiceControl();
    Binding binding = control.createMock(Binding.class);
    expect(binding.getHandlerChain()).andReturn(list).anyTimes();
    SoapMessage message = control.createMock(SoapMessage.class);
    Exchange exchange = control.createMock(Exchange.class);
    expect(message.getExchange()).andReturn(exchange).anyTimes();
    expect(message.keySet()).andReturn(new HashSet<>());
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
    control.replay();
    SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
    Set<QName> understood = li.getUnderstoodHeaders();
    assertNotNull(understood);
    assertTrue(understood.isEmpty());
}
Also used : Binding(javax.xml.ws.Binding) Set(java.util.Set) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) Handler(javax.xml.ws.handler.Handler) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Test(org.junit.Test)

Example 2 with HandlerChainInvoker

use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.

the class LogicalHandlerOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    if (binding.getHandlerChain().isEmpty()) {
        return;
    }
    HandlerChainInvoker invoker = getInvoker(message);
    if (invoker.getLogicalHandlers().isEmpty()) {
        return;
    }
    XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
    Node nd = message.getContent(Node.class);
    SOAPMessage m = message.getContent(SOAPMessage.class);
    Document document = null;
    if (m != null) {
        document = m.getSOAPPart();
    } else if (nd != null) {
        document = nd.getOwnerDocument();
    } else {
        document = DOMUtils.newDocument();
        message.setContent(Node.class, document);
    }
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment());
    // Replace stax writer with DomStreamWriter
    message.setContent(XMLStreamWriter.class, writer);
    message.put(ORIGINAL_WRITER, origWriter);
    message.getInterceptorChain().add(ending);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 3 with HandlerChainInvoker

use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.

the class SOAPHandlerFaultOutInterceptor method handleMessageInternal.

private void handleMessageInternal(SoapMessage message) {
    MessageContext context = createProtocolMessageContext(message);
    HandlerChainInvoker invoker = getInvoker(message);
    invoker.setProtocolMessageContext(context);
    try {
        if (!invoker.invokeProtocolHandlersHandleFault(isRequestor(message), context)) {
        // handleAbort(message, context);
        }
    } catch (RuntimeException exception) {
        /*
             * handleFault throws exception, in this case we need to replace
             * SOAPFault with the exception thrown from HandleFault so that the
             * exception can be dispatched.
             */
        try {
            SOAPMessage originalMsg = message.getContent(SOAPMessage.class);
            SOAPBody body = originalMsg.getSOAPPart().getEnvelope().getBody();
            body.removeContents();
            SOAPFault soapFault = body.addFault();
            if (exception instanceof SOAPFaultException) {
                SOAPFaultException sf = (SOAPFaultException) exception;
                soapFault.setFaultString(sf.getFault().getFaultString());
                SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName());
                soapFault.setFaultActor(sf.getFault().getFaultActor());
                if (sf.getFault().hasDetail()) {
                    Node nd = originalMsg.getSOAPPart().importNode(sf.getFault().getDetail().getFirstChild(), true);
                    soapFault.addDetail().appendChild(nd);
                }
            } else if (exception instanceof Fault) {
                SoapFault sf = SoapFault.createFault((Fault) exception, message.getVersion());
                soapFault.setFaultString(sf.getReason());
                SAAJUtils.setFaultCode(soapFault, sf.getFaultCode());
                if (sf.hasDetails()) {
                    soapFault.addDetail();
                    Node nd = originalMsg.getSOAPPart().importNode(sf.getDetail(), true);
                    nd = nd.getFirstChild();
                    while (nd != null) {
                        soapFault.getDetail().appendChild(nd);
                        nd = nd.getNextSibling();
                    }
                }
            } else {
                soapFault.setFaultString(exception.getMessage());
                SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandleFault"));
            }
        } catch (SOAPException e) {
            // do nothing
            e.printStackTrace();
        }
    }
    onCompletion(message);
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SoapFault(org.apache.cxf.binding.soap.SoapFault) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 4 with HandlerChainInvoker

use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.

the class SOAPHandlerInterceptor method handleMessageInternal.

private boolean handleMessageInternal(SoapMessage message) {
    MessageContext context = createProtocolMessageContext(message);
    if (context == null) {
        return true;
    }
    HandlerChainInvoker invoker = getInvoker(message);
    invoker.setProtocolMessageContext(context);
    if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
        handleAbort(message, context);
    }
    // If this is the outbound and end of MEP, call MEP completion
    if (isRequestor(message) && invoker.getLogicalHandlers().isEmpty() && !isOutbound(message) && isMEPComlete(message)) {
        onCompletion(message);
    } else if (isOutbound(message) && isMEPComlete(message)) {
        onCompletion(message);
    }
    return false;
}
Also used : HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext)

Example 5 with HandlerChainInvoker

use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.

the class LogicalHandlerFaultInInterceptor method handleMessage.

@Override
public void handleMessage(Message message) {
    if (binding.getHandlerChain().isEmpty()) {
        return;
    }
    HandlerChainInvoker invoker = getInvoker(message);
    if (invoker.getLogicalHandlers().isEmpty()) {
        return;
    }
    LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(message);
    invoker.setLogicalMessageContext(lctx);
    boolean requestor = isRequestor(message);
    if (!invoker.invokeLogicalHandlersHandleFault(requestor, lctx)) {
        if (!requestor) {
        // server side, wont get here
        } else {
        // Client side inbound, thus no response expected, do nothing, the close will
        // be handled by MEPComplete later
        }
    }
    // If this is the inbound and end of MEP, call MEP completion
    if (!isOutbound(message) && isMEPComlete(message)) {
        onCompletion(message);
    }
}
Also used : HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker)

Aggregations

HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)12 MessageContext (javax.xml.ws.handler.MessageContext)8 SOAPMessage (javax.xml.soap.SOAPMessage)7 QName (javax.xml.namespace.QName)6 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 Binding (javax.xml.ws.Binding)5 Handler (javax.xml.ws.handler.Handler)5 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)5 Fault (org.apache.cxf.interceptor.Fault)5 Exchange (org.apache.cxf.message.Exchange)5 IMocksControl (org.easymock.IMocksControl)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 MessageImpl (org.apache.cxf.message.MessageImpl)4