INT-197 Adding a Web Service Sample
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.ws;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.ws.adapter.AbstractWebServiceTargetAdapter;
|
||||
|
||||
/**
|
||||
* Demonstrating a web service invocation through a Web Service Target.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class WebServiceDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("temperatureConversion.xml",
|
||||
WebServiceDemo.class);
|
||||
context.start();
|
||||
|
||||
// Compose the XML message according to the server's schema
|
||||
String requestMessage = "<FahrenheitToCelsius xmlns=\"http://tempuri.org/\">" +
|
||||
" <Fahrenheit>90.0</Fahrenheit>" +
|
||||
" </FahrenheitToCelsius>";
|
||||
|
||||
// Prepare the Message object
|
||||
Message<String> message = new GenericMessage<String>(requestMessage);
|
||||
// In this case the service expects a SoapAction header
|
||||
message.getHeader().setProperty(AbstractWebServiceTargetAdapter.SOAP_ACTION_PROPERTY_KEY, "http://tempuri.org/FahrenheitToCelsius");
|
||||
// Set the return address for the message - the response message will be returned on this channel
|
||||
message.getHeader().setReturnAddress("celsiusChannel");
|
||||
|
||||
((MessageChannel)context.getBean("fahrenheitChannel")).send(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-ws-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<!-- A Web Service target reads messages from the configurd channel, invokes the service and sends
|
||||
the response on the replyAddress configured on the message header -->
|
||||
<si:channel id="fahrenheitChannel"/>
|
||||
|
||||
<si:ws-target id="temperatureConverter"
|
||||
uri="http://www.w3schools.com/webservices/tempconvert.asmx"
|
||||
channel="fahrenheitChannel" />
|
||||
|
||||
<si:channel id="celsiusChannel"/>
|
||||
|
||||
<!-- The response from the service is logged on the console -->
|
||||
<si:target-endpoint target="console" input-channel="celsiusChannel"/>
|
||||
|
||||
<si:console-target id="console"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user