Skip to content

Instantly share code, notes, and snippets.

@garyrussell
Last active June 25, 2018 06:00
Show Gist options
  • Select an option

  • Save garyrussell/6394999 to your computer and use it in GitHub Desktop.

Select an option

Save garyrussell/6394999 to your computer and use it in GitHub Desktop.
Quick Start
<!-- Simple Service -->
<int:gateway id="gw1" service-interface="foo.TempConverter"
default-request-channel="simpleExpression" />
<int:service-activator input-channel="simpleExpression"
expression="(payload - 32) / 9 * 5"/>
<!-- Web Service -->
<int:gateway id="gw2" service-interface="foo.TempConverter"
default-request-channel="viaWebService" />
<int:chain input-channel="viaWebService">
<int:transformer
expression="'&lt;FahrenheitToCelsius xmlns=''http://tempuri.org/''&gt;&lt;Fahrenheit&gt;XXX&lt;/Fahrenheit&gt;&lt;/FahrenheitToCelsius&gt;'.replace('XXX', payload.toString())" />
<int-ws:header-enricher>
<int-ws:soap-action value="http://tempuri.org/FahrenheitToCelsius"/>
</int-ws:header-enricher>
<int-ws:outbound-gateway uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
<int-xml:xpath-transformer
xpath-expression="/*[local-name()='FahrenheitToCelsiusResponse']/*[local-name()='FahrenheitToCelsiusResult']"/>
</int:chain>
public class Main {
public static void main(String... args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
// simple service
TempConverter converter = ctx.getBean("gw1", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
// web service
converter = ctx.getBean("gw2", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
}
}
20.0
20.0
public interface TempConverter {
float fahrenheitToCelcius(float fahren);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment