Search in sources :

Example 11 with StringSource

use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.

the class UnmarshallingTransformerTests method testMessageReturnValueFromTopLevel.

@Test
public void testMessageReturnValueFromTopLevel() {
    Unmarshaller unmarshaller = new TestUnmarshaller(true);
    UnmarshallingTransformer transformer = new UnmarshallingTransformer(unmarshaller);
    Message<?> result = transformer.transform(MessageBuilder.withPayload(new StringSource("bar")).build());
    assertNotNull(result);
    assertEquals("message: bar", result.getPayload());
}
Also used : StringSource(org.springframework.xml.transform.StringSource) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.Test)

Example 12 with StringSource

use of org.springframework.xml.transform.StringSource in project spring-integration-samples by spring-projects.

the class InContainerTests method testWebServiceRequestAndResponse.

@Test
public void testWebServiceRequestAndResponse() {
    StringResult result = new StringResult();
    Source payload = new StringSource("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");
    template.sendSourceAndReceiveToResult(WS_URI, payload, result);
    logger.info("RESULT: " + result.toString());
    assertThat(result.toString(), equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));
}
Also used : StringResult(org.springframework.xml.transform.StringResult) StringSource(org.springframework.xml.transform.StringSource) StringSource(org.springframework.xml.transform.StringSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 13 with StringSource

use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.

the class SimpleWebServiceInboundGateway method doInvoke.

@Override
protected void doInvoke(MessageContext messageContext) throws Exception {
    WebServiceMessage request = messageContext.getRequest();
    Assert.notNull(request, "Invalid message context: request was null.");
    AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload((this.extractPayload) ? request.getPayloadSource() : request);
    this.fromSoapHeaders(messageContext, builder);
    Message<?> replyMessage = this.sendAndReceiveMessage(builder.build());
    if (replyMessage != null) {
        Object replyPayload = replyMessage.getPayload();
        Source responseSource = null;
        if (replyPayload instanceof WebServiceMessage) {
            messageContext.setResponse((WebServiceMessage) replyPayload);
        } else {
            if (replyPayload instanceof Source) {
                responseSource = (Source) replyPayload;
            } else if (replyPayload instanceof Document) {
                responseSource = new DOMSource((Document) replyPayload);
            } else if (replyPayload instanceof String) {
                responseSource = new StringSource((String) replyPayload);
            } else {
                throw new IllegalArgumentException("The reply Message payload must be a [" + Source.class.getName() + "], [" + Document.class.getName() + "], [java.lang.String] or [" + WebServiceMessage.class.getName() + "]. " + "The actual type was [" + replyPayload.getClass().getName() + "]");
            }
            WebServiceMessage response = messageContext.getResponse();
            this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
            toSoapHeaders(response, replyMessage);
        }
    }
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage) DOMSource(javax.xml.transform.dom.DOMSource) StringSource(org.springframework.xml.transform.StringSource) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StringSource(org.springframework.xml.transform.StringSource) Source(javax.xml.transform.Source)

Example 14 with StringSource

use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.

the class UnmarshallingTransformerParserTests method testPollingUnmarshall.

@Test
public void testPollingUnmarshall() throws Exception {
    MessageChannel input = (MessageChannel) appContext.getBean("pollableInput");
    PollableChannel output = (PollableChannel) appContext.getBean("output");
    GenericMessage<Object> message = new GenericMessage<Object>(new StringSource("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>"));
    input.send(message);
    Message<?> result = output.receive(5000);
    assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
    assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof StringSource);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Example 15 with StringSource

use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testFromHeadersToRequest.

@Test
public void testFromHeadersToRequest() throws SOAPException {
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    mapper.setReplyHeaderNames("foo", "auth", "myHeader");
    Map<String, Object> headers = new HashMap<>();
    headers.put("foo", "bar");
    String docString = "<auth xmlns='http://test.auth.org'>" + "<username>user</username>" + "<password>pass</password>" + "</auth>";
    Source source = new StringSource(docString);
    headers.put("auth", source);
    headers.put("myHeader", new StringSource("<test xmlns='http://test.org'>TEST</test>"));
    SaajSoapMessage message = new SaajSoapMessage(MessageFactory.newInstance().createMessage());
    mapper.fromHeadersToReply(new MessageHeaders(headers), message);
    SoapHeader soapHeader = message.getSoapHeader();
    assertEquals("bar", soapHeader.getAttributeValue(QNameUtils.parseQNameString("foo")));
    Iterator<SoapHeaderElement> authIterator = soapHeader.examineHeaderElements(QNameUtils.parseQNameString("{http://test.auth.org}auth"));
    assertTrue(authIterator.hasNext());
    SoapHeaderElement auth = authIterator.next();
    DOMSource authSource = (DOMSource) auth.getSource();
    NodeList nodeList = authSource.getNode().getChildNodes();
    assertEquals("username", nodeList.item(0).getNodeName());
    assertEquals("user", nodeList.item(0).getFirstChild().getNodeValue());
    assertEquals("password", nodeList.item(1).getNodeName());
    assertEquals("pass", nodeList.item(1).getFirstChild().getNodeValue());
    Iterator<SoapHeaderElement> testIterator = soapHeader.examineHeaderElements(QNameUtils.parseQNameString("{http://test.org}test"));
    assertTrue(testIterator.hasNext());
/*StringResult stringResult = new StringResult();
		Transformer transformer = TransformerFactory.newInstance().newTransformer();
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		transformer.transform(message.getEnvelope().getSource(), stringResult);
		System. out. println(stringResult.toString());*/
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StringSource(org.springframework.xml.transform.StringSource) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapHeader(org.springframework.ws.soap.SoapHeader) StringSource(org.springframework.xml.transform.StringSource) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Aggregations

StringSource (org.springframework.xml.transform.StringSource)22 Test (org.junit.Test)15 Source (javax.xml.transform.Source)7 Transformer (javax.xml.transform.Transformer)5 DOMSource (javax.xml.transform.dom.DOMSource)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 StringResult (org.springframework.xml.transform.StringResult)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 MessageChannel (org.springframework.messaging.MessageChannel)3 PollableChannel (org.springframework.messaging.PollableChannel)3 Unmarshaller (org.springframework.oxm.Unmarshaller)3 StringWriter (java.io.StringWriter)2 StreamResult (javax.xml.transform.stream.StreamResult)2 XmlMappingException (org.springframework.oxm.XmlMappingException)2 WebServiceMessage (org.springframework.ws.WebServiceMessage)2 MessageContext (org.springframework.ws.context.MessageContext)2 Document (org.w3c.dom.Document)2 ServiceException (com.consol.citrus.samples.incident.exception.ServiceException)1 HashMap (java.util.HashMap)1