Search in sources :

Example 1 with WebServiceConnection

use of org.springframework.ws.transport.WebServiceConnection in project spring-integration by spring-projects.

the class UriVariableTests method testInt2720EmailUriVariables.

@Test
public void testInt2720EmailUriVariables() {
    final String testEmailTo = "user@example.com";
    final String testEmailSubject = "Test subject";
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", testEmailTo).setHeader("subject", testEmailSubject).build();
    try {
        this.inputEmail.send(message);
    } catch (MessageHandlingException e) {
        // expected
        Class<?> causeType = e.getCause().getClass();
        // offline
        assertTrue(WebServiceIOException.class.equals(causeType));
    }
    WebServiceConnection webServiceConnection = this.emailInterceptor.getLastWebServiceConnection();
    assertEquals(testEmailTo, TestUtils.getPropertyValue(webServiceConnection, "to").toString());
    assertEquals(testEmailSubject, TestUtils.getPropertyValue(webServiceConnection, "subject"));
    assertEquals("mailto:user@example.com?subject=Test%20subject", this.emailInterceptor.getLastUri().toString());
}
Also used : WebServiceConnection(org.springframework.ws.transport.WebServiceConnection) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 2 with WebServiceConnection

use of org.springframework.ws.transport.WebServiceConnection 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 3 with WebServiceConnection

use of org.springframework.ws.transport.WebServiceConnection in project spring-integration by spring-projects.

the class SimpleWebServiceOutboundGatewayTests method createMockMessageSender.

public static WebServiceMessageSender createMockMessageSender(final String mockResponseMessage) throws Exception {
    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();
        WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
        return factory.createWebServiceMessage(new ByteArrayInputStream(mockResponseMessage.getBytes()));
    }).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
    return messageSender;
}
Also used : WebServiceMessageSender(org.springframework.ws.transport.WebServiceMessageSender) WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) WebServiceConnection(org.springframework.ws.transport.WebServiceConnection) URI(java.net.URI)

Aggregations

WebServiceConnection (org.springframework.ws.transport.WebServiceConnection)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)2 WebServiceMessageSender (org.springframework.ws.transport.WebServiceMessageSender)2 Test (org.junit.Test)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 AbstractWebServiceOutboundGateway (org.springframework.integration.ws.AbstractWebServiceOutboundGateway)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHandlingException (org.springframework.messaging.MessageHandlingException)1 WebServiceMessage (org.springframework.ws.WebServiceMessage)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1 DomPoxMessageFactory (org.springframework.ws.pox.dom.DomPoxMessageFactory)1 SoapHeader (org.springframework.ws.soap.SoapHeader)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1 SoapMessageFactory (org.springframework.ws.soap.SoapMessageFactory)1