Search in sources :

Example 16 with SoapMessage

use of org.springframework.ws.soap.SoapMessage in project webservices-axiom by apache.

the class TestCreateWebServiceMessageFromInputStream method runTest.

@Override
protected void runTest(SoapMessageFactory messageFactory) throws Throwable {
    SoapMessage message = messageFactory.createWebServiceMessage(new TransportInputStreamImpl(SOAPSampleSet.NO_HEADER.getMessage(spec)));
    SoapEnvelope env = message.getEnvelope();
    assertNull(env.getHeader());
    assertNotNull(env.getBody());
}
Also used : SoapEnvelope(org.springframework.ws.soap.SoapEnvelope) SoapMessage(org.springframework.ws.soap.SoapMessage)

Example 17 with SoapMessage

use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.

the class WebServiceOutboundGatewayWithHeaderMapperTests method process.

private Message<?> process(Object payload, String gatewayName, String channelName, final boolean soap) throws Exception {
    AbstractWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(this.context.getBean(gatewayName), "handler", AbstractWebServiceOutboundGateway.class);
    if (!soap) {
        WebServiceTemplate template = TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class);
        template.setMessageFactory(new DomPoxMessageFactory());
    }
    WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);
    WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class);
    Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
    Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true);
    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        WebServiceMessage wsMessage = (WebServiceMessage) args[0];
        // }
        if (soap) {
            SoapHeader soapHeader = ((SoapMessage) wsMessage).getSoapHeader();
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("foo")));
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("foobar")));
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("abaz")));
            assertNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("bar")));
        }
        return null;
    }).when(wsConnection).send(Mockito.any(WebServiceMessage.class));
    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
        String responseMessage = factory instanceof SoapMessageFactory ? responseSoapMessage : responseNonSoapMessage;
        WebServiceMessage wsMessage = factory.createWebServiceMessage(new ByteArrayInputStream(responseMessage.getBytes()));
        if (soap) {
            ((SoapMessage) wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("bar"), "bar");
            ((SoapMessage) wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("baz"), "baz");
        }
        // }
        return wsMessage;
    }).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
    gateway.setMessageSender(messageSender);
    MessageChannel inputChannel = context.getBean(channelName, MessageChannel.class);
    Message<?> message = MessageBuilder.withPayload(payload).setHeader("foo", "foo").setHeader("foobar", "foobar").setHeader("abaz", "abaz").setHeader("bar", "bar").setHeader(WebServiceHeaders.SOAP_ACTION, "someAction").build();
    inputChannel.send(message);
    QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
    return outputChannel.receive(0);
}
Also used : WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) DomPoxMessageFactory(org.springframework.ws.pox.dom.DomPoxMessageFactory) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) URI(java.net.URI) SoapMessage(org.springframework.ws.soap.SoapMessage) WebServiceMessage(org.springframework.ws.WebServiceMessage) SoapMessageFactory(org.springframework.ws.soap.SoapMessageFactory) WebServiceMessageSender(org.springframework.ws.transport.WebServiceMessageSender) MessageChannel(org.springframework.messaging.MessageChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) SoapHeader(org.springframework.ws.soap.SoapHeader) AbstractWebServiceOutboundGateway(org.springframework.integration.ws.AbstractWebServiceOutboundGateway) WebServiceConnection(org.springframework.ws.transport.WebServiceConnection)

Example 18 with SoapMessage

use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.

the class SimpleWebServiceOutboundGatewayTests method soapActionAndCustomCallback.

// INT-1051
@Test
public void soapActionAndCustomCallback() {
    String uri = "http://www.example.org";
    SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(new TestDestinationProvider(uri));
    final AtomicReference<String> soapActionFromCallback = new AtomicReference<String>();
    gateway.setRequestCallback(message -> {
        SoapMessage soapMessage = (SoapMessage) message;
        soapActionFromCallback.set(soapMessage.getSoapAction());
    });
    gateway.setBeanFactory(mock(BeanFactory.class));
    gateway.afterPropertiesSet();
    String soapActionHeaderValue = "testAction";
    String request = "<test>foo</test>";
    try {
        gateway.handleMessage(MessageBuilder.withPayload(request).setHeader(WebServiceHeaders.SOAP_ACTION, soapActionHeaderValue).build());
        fail("Expected MessageHandlingException");
    } catch (MessageHandlingException e) {
    // expected
    }
    assertNotNull(soapActionFromCallback.get());
    assertEquals("\"" + soapActionHeaderValue + "\"", soapActionFromCallback.get());
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageHandlingException(org.springframework.messaging.MessageHandlingException) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 19 with SoapMessage

use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testExtractStandardHeadersEmptySoapAction.

@Test
public void testExtractStandardHeadersEmptySoapAction() {
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    SoapMessage soapMessage = mock(SoapMessage.class);
    when(soapMessage.getSoapAction()).thenReturn("");
    assertTrue(mapper.extractStandardHeaders(soapMessage).isEmpty());
}
Also used : SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 20 with SoapMessage

use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testExtractStandardHeadersNonEmptySoapAction.

@Test
public void testExtractStandardHeadersNonEmptySoapAction() {
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    SoapMessage soapMessage = mock(SoapMessage.class);
    when(soapMessage.getSoapAction()).thenReturn("foo");
    Map<String, Object> standardHeaders = mapper.toHeadersFromRequest(soapMessage);
    assertEquals(1, standardHeaders.size());
    assertTrue(standardHeaders.containsKey(WebServiceHeaders.SOAP_ACTION));
    assertEquals("foo", standardHeaders.get(WebServiceHeaders.SOAP_ACTION));
}
Also used : SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Aggregations

SoapMessage (org.springframework.ws.soap.SoapMessage)22 Test (org.junit.Test)8 SaajSoapMessage (org.springframework.ws.soap.saaj.SaajSoapMessage)7 SoapHeader (org.springframework.ws.soap.SoapHeader)4 WebServiceMessage (org.springframework.ws.WebServiceMessage)3 SoapBody (org.springframework.ws.soap.SoapBody)3 SoapHeaderElement (org.springframework.ws.soap.SoapHeaderElement)3 MessageAddressingProperties (org.springframework.ws.soap.addressing.core.MessageAddressingProperties)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Locale (java.util.Locale)2 QName (javax.xml.namespace.QName)2 Source (javax.xml.transform.Source)2 SoapEnvelope (org.springframework.ws.soap.SoapEnvelope)2 Attachment (com.consol.citrus.samples.todolist.model.Attachment)1 TodoEntry (com.consol.citrus.samples.todolist.model.TodoEntry)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1