Search in sources :

Example 1 with MessageContext

use of org.springframework.ws.context.MessageContext in project camel by apache.

the class InMemoryWebServiceMessageSender2 method decorateResponseReceiver.

public void decorateResponseReceiver() {
    final WebServiceMessageReceiver original = getWebServiceMessageReceiver();
    setWebServiceMessageReceiver(new WebServiceMessageReceiver() {

        @Override
        public void receive(MessageContext messageContext) throws Exception {
            decorator.receive(messageContext);
            original.receive(messageContext);
        }
    });
}
Also used : MessageContext(org.springframework.ws.context.MessageContext) WebServiceMessageReceiver(org.springframework.ws.transport.WebServiceMessageReceiver)

Example 2 with MessageContext

use of org.springframework.ws.context.MessageContext in project spring-integration by spring-projects.

the class WebServiceInboundGatewayParserTests method testMessageHistoryWithMarshallingGateway.

@Test
public void testMessageHistoryWithMarshallingGateway() throws Exception {
    MessageContext context = new DefaultMessageContext(new StubMessageFactory());
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    when(unmarshaller.unmarshal((Source) Mockito.any())).thenReturn("hello");
    marshallingGateway.setUnmarshaller(unmarshaller);
    marshallingGateway.invoke(context);
    Message<?> message = requestsMarshalling.receive(100);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "marshalling", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("ws:inbound-gateway", componentHistoryRecord.get("type"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) MessageContext(org.springframework.ws.context.MessageContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with MessageContext

use of org.springframework.ws.context.MessageContext in project spring-integration by spring-projects.

the class WebServiceInboundGatewayParserTests method testMessageHistoryWithSimpleGateway.

@Test
public void testMessageHistoryWithSimpleGateway() throws Exception {
    MessageContext context = new DefaultMessageContext(new StubMessageFactory());
    payloadExtractingGateway.invoke(context);
    Message<?> message = requestsSimple.receive(100);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "extractsPayload", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("ws:inbound-gateway", componentHistoryRecord.get("type"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) MessageContext(org.springframework.ws.context.MessageContext) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with MessageContext

use of org.springframework.ws.context.MessageContext in project spring-integration by spring-projects.

the class SimpleWebServiceOutboundGatewayTests method testDomPoxMessageFactory.

@Test
public void testDomPoxMessageFactory() throws Exception {
    String uri = "http://www.example.org";
    SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
    gateway.setBeanFactory(mock(BeanFactory.class));
    final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
    ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {

        @Override
        public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
            requestFuture.set(messageContext.getRequest());
            return super.handleRequest(messageContext);
        }
    };
    gateway.setInterceptors(interceptorAdapter);
    gateway.setMessageFactory(new DomPoxMessageFactory());
    gateway.afterPropertiesSet();
    String request = "<test>foo</test>";
    try {
        gateway.handleMessage(new GenericMessage<>(request));
        fail("Expected MessageHandlingException");
    } catch (MessageHandlingException e) {
    // expected
    }
    WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(requestMessage);
    assertThat(requestMessage, instanceOf(PoxMessage.class));
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringResult stringResult = new StringResult();
    transformer.transform(requestMessage.getPayloadSource(), stringResult);
    assertEquals(request, stringResult.toString());
}
Also used : SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DomPoxMessageFactory(org.springframework.ws.pox.dom.DomPoxMessageFactory) ClientInterceptorAdapter(org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter) MessageHandlingException(org.springframework.messaging.MessageHandlingException) WebServiceMessage(org.springframework.ws.WebServiceMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) MessageContext(org.springframework.ws.context.MessageContext) StringResult(org.springframework.xml.transform.StringResult) PoxMessage(org.springframework.ws.pox.PoxMessage) Test(org.junit.Test)

Example 5 with MessageContext

use of org.springframework.ws.context.MessageContext in project spring-integration by spring-projects.

the class SimpleWebServiceOutboundGatewayTests method testAttachments.

@Test
public void testAttachments() throws Exception {
    String uri = "http://www.example.org";
    SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
    gateway.setBeanFactory(mock(BeanFactory.class));
    final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
    ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {

        @Override
        public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
            requestFuture.set(messageContext.getRequest());
            return super.handleRequest(messageContext);
        }
    };
    gateway.setInterceptors(interceptorAdapter);
    gateway.afterPropertiesSet();
    WebServiceMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
    MimeMessage webServiceMessage = (MimeMessage) messageFactory.createWebServiceMessage();
    String request = "<test>foo</test>";
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(new StringSource(request), webServiceMessage.getPayloadResult());
    webServiceMessage.addAttachment("myAttachment", new ByteArrayResource("my_data".getBytes()), "text/plain");
    try {
        gateway.handleMessage(new GenericMessage<>(webServiceMessage));
        fail("Expected MessageHandlingException");
    } catch (MessageHandlingException e) {
    // expected
    }
    WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(requestMessage);
    assertThat(requestMessage, instanceOf(MimeMessage.class));
    transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringResult stringResult = new StringResult();
    transformer.transform(requestMessage.getPayloadSource(), stringResult);
    assertEquals(request, stringResult.toString());
    Attachment myAttachment = ((MimeMessage) requestMessage).getAttachment("myAttachment");
    assertNotNull(myAttachment);
    assertEquals("text/plain", myAttachment.getContentType());
    assertEquals("my_data", StreamUtils.copyToString(myAttachment.getInputStream(), Charset.forName("UTF-8")));
}
Also used : WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) Attachment(org.springframework.ws.mime.Attachment) SaajSoapMessageFactory(org.springframework.ws.soap.saaj.SaajSoapMessageFactory) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClientInterceptorAdapter(org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter) MessageHandlingException(org.springframework.messaging.MessageHandlingException) WebServiceMessage(org.springframework.ws.WebServiceMessage) MimeMessage(org.springframework.ws.mime.MimeMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) MessageContext(org.springframework.ws.context.MessageContext) StringSource(org.springframework.xml.transform.StringSource) StringResult(org.springframework.xml.transform.StringResult) Test(org.junit.Test)

Aggregations

MessageContext (org.springframework.ws.context.MessageContext)7 Test (org.junit.Test)6 Transformer (javax.xml.transform.Transformer)3 DefaultMessageContext (org.springframework.ws.context.DefaultMessageContext)3 Properties (java.util.Properties)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 MessageHistory (org.springframework.integration.history.MessageHistory)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)2 WebServiceMessage (org.springframework.ws.WebServiceMessage)2 ClientInterceptorAdapter (org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter)2 DomPoxMessageFactory (org.springframework.ws.pox.dom.DomPoxMessageFactory)2 StringResult (org.springframework.xml.transform.StringResult)2 StringSource (org.springframework.xml.transform.StringSource)2 Element (org.w3c.dom.Element)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Locale (java.util.Locale)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1