Search in sources :

Example 21 with MessageFactory

use of javax.xml.soap.MessageFactory 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)

Example 22 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class GreeterDOMSourceMessageProvider method invoke.

public DOMSource invoke(DOMSource request) {
    DOMSource response = new DOMSource();
    try {
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapReq = factory.createMessage();
        soapReq.getSOAPPart().setContent(request);
        System.out.println("Incoming Client Request as a DOMSource data in MESSAGE Mode");
        soapReq.writeTo(System.out);
        System.out.println("\n");
        SOAPMessage greetMeResponse = null;
        try (InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp2.xml")) {
            greetMeResponse = factory.createMessage(null, is);
        }
        response.setNode(greetMeResponse.getSOAPPart());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 23 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class GreeterSoapMessageProvider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    SOAPMessage response = null;
    try {
        System.out.println("Incoming Client Request as a SOAPMessage");
        MessageFactory factory = MessageFactory.newInstance();
        try (InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp1.xml")) {
            response = factory.createMessage(null, is);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 24 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class RMSoapOutInterceptorTest method setupOutboundMessage.

private SoapMessage setupOutboundMessage() throws Exception {
    Exchange ex = new ExchangeImpl();
    Message message = new MessageImpl();
    SoapMessage soapMessage = new SoapMessage(message);
    RMProperties rmps = new RMProperties();
    rmps.exposeAs(RM10Constants.NAMESPACE_URI);
    RMContextUtils.storeRMProperties(soapMessage, rmps, true);
    AddressingProperties maps = new AddressingProperties();
    RMContextUtils.storeMAPs(maps, soapMessage, true, false);
    ex.setOutMessage(soapMessage);
    soapMessage.setExchange(ex);
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    SOAPMessage soap = factory.createMessage();
    QName bodyName = new QName("http://cxf.apache.org", "dummy", "d");
    soap.getSOAPBody().addBodyElement(bodyName);
    soapMessage.setContent(SOAPMessage.class, soap);
    return soapMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) MessageImpl(org.apache.cxf.message.MessageImpl) SOAPMessage(javax.xml.soap.SOAPMessage) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) RMProperties(org.apache.cxf.ws.rm.RMProperties) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 25 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcMessageMode.

@Test
public void testInvokeWithDOMSourcMessageMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.MESSAGE);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is);
    soapReq.saveChanges();
    DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
    DOMSource response = disp.invoke(domReqMessage);
    // XMLUtils.writeTo(response, System.out);
    assertNotNull(response);
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Aggregations

MessageFactory (javax.xml.soap.MessageFactory)70 SOAPMessage (javax.xml.soap.SOAPMessage)65 URL (java.net.URL)24 InputStream (java.io.InputStream)22 QName (javax.xml.namespace.QName)22 SOAPException (javax.xml.soap.SOAPException)22 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPPart (javax.xml.soap.SOAPPart)17 StreamSource (javax.xml.transform.stream.StreamSource)14 SOAPConnection (javax.xml.soap.SOAPConnection)13 IOException (java.io.IOException)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)10 JBossWSTest (org.jboss.wsf.test.JBossWSTest)10 NodeList (org.w3c.dom.NodeList)9 AttachmentPart (javax.xml.soap.AttachmentPart)8 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)8 Element (org.w3c.dom.Element)8