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());
}
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>"));
}
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);
}
}
}
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);
}
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());*/
}
Aggregations