Modified WebServiceDemo to show the 'chain' element and the 'header-enricher'.

This commit is contained in:
Mark Fisher
2008-11-22 16:17:16 +00:00
parent 4e72c719f9
commit 75903736e2
3 changed files with 16 additions and 16 deletions

View File

@@ -17,10 +17,11 @@
package org.springframework.integration.samples.ws;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.ws.WebServiceHeaders;
/**
* Demonstrating a web service invocation through a Web Service MessageHandler.
@@ -31,6 +32,7 @@ public class WebServiceDemo {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("temperatureConversion.xml", WebServiceDemo.class);
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
// Compose the XML message according to the server's schema
String requestXml =
@@ -39,13 +41,11 @@ public class WebServiceDemo {
"</FahrenheitToCelsius>";
// Create the Message object
// In this case the service expects a SoapAction header
Message<String> message = MessageBuilder.withPayload(requestXml)
.setHeader(WebServiceHeaders.SOAP_ACTION, "http://tempuri.org/FahrenheitToCelsius")
.build();
Message<String> message = MessageBuilder.withPayload(requestXml).build();
// Send the Message to the handler's input channel
((MessageChannel) context.getBean("fahrenheitChannel")).send(message);
MessageChannel channel = channelResolver.resolveChannelName("fahrenheitChannel");
channel.send(message);
}
}

View File

@@ -13,15 +13,15 @@
http://www.springframework.org/schema/integration/ws
http://www.springframework.org/schema/integration/ws/spring-integration-ws-1.0.xsd">
<channel id="fahrenheitChannel"/>
<!-- The Web Service outbound Messaging Gateway receives from the
'fahrenheitChannel', invokes the Web Service for the given URI,
and sends the reply Message to the 'celsiusChannel'. -->
<ws:outbound-gateway id="temperatureConverter"
request-channel="fahrenheitChannel"
reply-channel="celsiusChannel"
uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
<!-- This chain receives from the 'fahrenheitChannel' and enriches the request Message by adding
the "soap-action" header value. Then, the Web Service outbound Messaging Gateway invokes the
Web Service for the given URI, and the reply Message is sent to the 'celsiusChannel'. -->
<chain input-channel="fahrenheitChannel" output-channel="celsiusChannel">
<header-enricher>
<header name="spring.integration.ws.soap-action" value="http://tempuri.org/FahrenheitToCelsius"/>
</header-enricher>
<ws:outbound-gateway uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
</chain>
<!-- The response from the service is logged to the console. -->
<stream:stdout-channel-adapter id="celsiusChannel"/>