Search in sources :

Example 1 with DefaultMessageContext

use of org.springframework.ws.context.DefaultMessageContext 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 2 with DefaultMessageContext

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

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

the class InboundGatewayTests method testSendAndReceive.

/**
 * Emulate the Spring WS MessageDispatcherServlet by calling the gateway
 * with a DOMSource object representing the payload of the original SOAP
 * 'echoRequest' message.  Expect an 'echoResponse' DOMSource object
 * to be returned in synchronous fashion, which the MessageDispatcherServlet
 * would in turn wrap in a SOAP envelope and return to the client.
 */
@Test
public void testSendAndReceive() throws Exception {
    String xml = "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>";
    DomPoxMessageFactory messageFactory = new DomPoxMessageFactory();
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(new InputSource(new StringReader(xml)));
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DomPoxMessage request = new DomPoxMessage(document, transformer, "text/xml");
    MessageContext messageContext = new DefaultMessageContext(request, messageFactory);
    gateway.invoke(messageContext);
    Object reply = messageContext.getResponse().getPayloadSource();
    assertThat(reply, is(instanceOf(DOMSource.class)));
    DOMSource replySource = (DOMSource) reply;
    Element element = (Element) replySource.getNode().getFirstChild();
    assertThat(element.getTagName(), equalTo("echoResponse"));
}
Also used : InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) Element(org.w3c.dom.Element) DomPoxMessageFactory(org.springframework.ws.pox.dom.DomPoxMessageFactory) Document(org.w3c.dom.Document) DomPoxMessage(org.springframework.ws.pox.dom.DomPoxMessage) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) MessageContext(org.springframework.ws.context.MessageContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DefaultMessageContext (org.springframework.ws.context.DefaultMessageContext)3 MessageContext (org.springframework.ws.context.MessageContext)3 Properties (java.util.Properties)2 MessageHistory (org.springframework.integration.history.MessageHistory)2 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Transformer (javax.xml.transform.Transformer)1 DOMSource (javax.xml.transform.dom.DOMSource)1 Unmarshaller (org.springframework.oxm.Unmarshaller)1 DomPoxMessage (org.springframework.ws.pox.dom.DomPoxMessage)1 DomPoxMessageFactory (org.springframework.ws.pox.dom.DomPoxMessageFactory)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 InputSource (org.xml.sax.InputSource)1