Search in sources :

Example 16 with SOAPMessageContext

use of javax.xml.ws.handler.soap.SOAPMessageContext in project jbossws-cxf by jbossws.

the class CustomHandler method handleMessage.

@Override
public boolean handleMessage(SOAPMessageContext context) {
    log.debug("handleMessage...");
    try {
        SOAPMessageContext msgContext = context;
        SOAPBody body = msgContext.getMessage().getSOAPBody();
        String bodyStr = DOMWriter.printNode(body, false);
        if (bodyStr.indexOf("http://example.org/sei") < 0)
            throw new WebServiceException("Invalid body: " + bodyStr);
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException)

Example 17 with SOAPMessageContext

use of javax.xml.ws.handler.soap.SOAPMessageContext in project jbossws-cxf by jbossws.

the class ManualResourcesHandler method ensureInjectionsAndInitialization.

private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
    if (!this.correctState) {
        throw new WebServiceException("Unfunctional manual JNDI lookups in @PostConstruct annotated methods");
    }
    doManualJndiLookup();
    if (!this.correctState) {
        throw new WebServiceException("Unfunctional manual JNDI lookups in handler execution methods");
    }
    try {
        SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
        SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
        soapElement = (SOAPElement) soapElement.getChildElements().next();
        String oldValue = soapElement.getValue();
        String newValue = oldValue + ":" + direction + ":ManualResourcesHandler";
        soapElement.setValue(newValue);
        log.debug("oldValue: " + oldValue);
        log.debug("newValue: " + newValue);
        return true;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 18 with SOAPMessageContext

use of javax.xml.ws.handler.soap.SOAPMessageContext in project wildfly by wildfly.

the class TestHandler method ensureInjectionsAndInitialization.

private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
    if (!this.correctState) {
        throw new WebServiceException("Unfunctional injections");
    }
    try {
        SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
        SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
        soapElement = (SOAPElement) soapElement.getChildElements().next();
        String oldValue = soapElement.getValue();
        String newValue = oldValue + ":" + direction + ":TestHandler";
        soapElement.setValue(newValue);
        log.debug("oldValue: " + oldValue);
        log.debug("newValue: " + newValue);
        return true;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 19 with SOAPMessageContext

use of javax.xml.ws.handler.soap.SOAPMessageContext 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 20 with SOAPMessageContext

use of javax.xml.ws.handler.soap.SOAPMessageContext 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());
    invoker.setLogicalMessageContext(lmc);
    boolean 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);
        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)

Aggregations

SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)45 SOAPMessage (javax.xml.soap.SOAPMessage)33 WebServiceException (javax.xml.ws.WebServiceException)24 SOAPException (javax.xml.soap.SOAPException)22 SOAPElement (javax.xml.soap.SOAPElement)18 Test (org.junit.Test)13 SOAPBody (javax.xml.soap.SOAPBody)12 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)10 QName (javax.xml.namespace.QName)7 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)7 IOException (java.io.IOException)6 List (java.util.List)6 Set (java.util.Set)6 ContentType (javax.mail.internet.ContentType)6 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)6 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)6 Handler (javax.xml.ws.handler.Handler)6 MessageContext (javax.xml.ws.handler.MessageContext)6 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)6 ArrayList (java.util.ArrayList)5