This article describes the default configuration shipped with the AdroitLogic UltraESB, and shows how the sample could be tested and extended/modified using the IDE integration support of the UltraESB. This article also shows how a JUnit test case could be written for scenarios implemented with the UltraESB
The HelloESB Sample
References:
- [1] Getting started with the AdroitLogic ToolBox for the UltraESB
- [2] UltraESB Users Guide - Configuring and Using the IDE
Lets follow a simple end-to-end example with the UltraESB. We will use the default configuration, which holds the "echo-proxy" definition in the ultra-dynamic.xml as follows.
<u:proxy id="echo-proxy">
<u:transport id="http-8280"/>
<u:target>
<!--u:inSequence>
<u:class name="sample.SimpleJavaMediation1"/>
</u:inSequence-->
<u:inDestination>
<u:address>http://localhost:9000/service/EchoService</u:address>
</u:inDestination>
<u:outSequence>
<u:java><![CDATA[
System.out.println("Reply payload : " + mediation.readPayloadAsString(msg));
]]></u:java>
</u:outSequence>
<u:outDestination>
<u:address type="response"/>
</u:outDestination>
</u:target>
</u:proxy>
The above proxy service definition, exposes a service named "echo-proxy" over the HTTP transport (as defined by the "http-8280" bean in the ultra-root.xml). In this example, the incoming message is "mediated" by a sequence defined externally as a Java class named "sample.SimpleJavaMediation1" - which is commented out initially. This allows us to demonstrate the use of the IDE for writing mediation code as a Java class, and testing and debugging the mediation steps from within the IDE itself.
The request message is then forwarded to the EchoService endpoint specified in the inDestination. The response message received is then "mediated" by a sequence defined in-line within the configuration as a Java code fragment. The UltraESB allows the user to easily edit such Java code fragments from within the IDE itself, with auto-completion, syntax highlighting and all such features supported by the IDE. The response message is finally sent to the default response address - i.e to the original client of the ESB.
Testing the basic sample - using the AdroitLogic ToolBox
We will now use the AdroitLogic ToolBox to demonstrate interaction with the echo-proxy service. As this proxy service is defined in the default configuration, simply start the UltraESB using the ultraesb.sh/bat scripts. In the next section we will try this same example from within the IDE.
Now, start the AdroitLogic ToolBox using the toolbox.sh/bat scripts, and start the sample Jetty server on the default port 9000, which will then make the EchoService available at URL : http://localhost:9000/service/EchoService
Next start an HTTP/S client from within the ToolBox, and first test the above service using the request payload from Preset "1". You should see a response as follows.

Please refer to the guide on the AdroitLogic ToolBox [1] to learn more about its features and uses.
Now, send the same request from the ToolBox to the URL "http://localhost:8280/service/echo-proxy" - which is the address of the "echo-proxy" service hosted on the UltraESB. You would again see a similar response being received at the ToolBox - this time through the UltraESB. As the response "mediation" contained a System.out.println statement to print the textual representation of the response message, you will see it on the UltraESB console as follows.
Reply payload : <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.services.samples/">
<soapenv:Body>
<soap:getQuote>
<request>
<symbol>ADRT</symbol>
</request>
</soap:getQuote>
</soapenv:Body>
</soapenv:Envelope>
Testing the basic sample - using the IDE
Now, stop the UltraESB by pressing CTRL+C (Note: in a production deployment - you could instead use the ultraesb-daemon.sh or JMX to start and stop the instance - However, even when the JVM is terminated with a CRTL+C, the UltraESB will shutdown itself gracefully as long as the JVM allows the registered shutdown hooks to execute) and open the UltraRuntime.ipr project from the IntelliJ IDEA Community Edition IDE. We assume that you have properly configured the IDE already as per [2] for operation with the UltraESB.
If the default run configuration "UltraESB" is not available, define one to run the class "org.adroitlogic.ultraesb.UltraServer" from the UltraESB home directory, passing the parameter "conf" as a command line parameter - as shown below for IntelliJ IDEA

Now, uncomment the "<inSequence..../>" from the ultra-dynamic.xml and open the class "SimpleJavaMediation1" within the IDE, and place a breakpoint in the line first line of the "execute" method - the System.out.println as shown below.

Now run the default UltraESB configuration of the UltraRuntime project by pressing "Shift+F9" or the Debug button, and send the same request as before from the ToolBox HTTP/S client to the "echo-proxy" service. You will break at the breakpoint set above and can view all information available, and evaluate watches etc - as usual in standard Java debugging!

Testing the sample - Using a JUnit testcase
It is an easy task to write unit tests for any scenario when using the UltraESB. Infact AdroitLogic writes an end-to-end unit test case for each sample configuration of the UltraESB - and these are available with the distribution. To see how this same example will work in a JUnit test, refer to the HelloESB class shown below. You could directly run this testcase from within the IDE when the UltraRuntime project is selected.
public class HelloESB extends TestCase {
private static final Logger logger = LoggerFactory.getLogger(HelloESB.class);
private static final String proxyUrl = "http://localhost:8280/service/echo-proxy";
private static HttpClient client = new DefaultHttpClient();
private static Server server = null;
private static int port = 9000;
public static Test suite() {
TestSetup setup = new TestSetup(new TestSuite(HelloESB.class)) {
protected void setUp() throws Exception {
server = new Server(port);
WebAppContext webAppContext =
new WebAppContext("samples/webapp", "/");
webAppContext.setConfigurationClasses(new String[]{
"org.mortbay.jetty.webapp.WebInfConfiguration",
"org.mortbay.jetty.webapp.WebXmlConfiguration"});
server.addHandler(webAppContext);
server.start();
UltraServer.main(new String[]{"conf", "conf/ultra-root.xml"});
}
protected void tearDown() throws Exception {
if (server != null) {
server.stop();
}
}
};
return setup;
}
public void testHttpCall() throws Exception {
HttpPost httppost = new HttpPost(proxyUrl);
httppost.setEntity(new StringEntity(getQuoteRequest, "text/xml", "UTF-8"));
httppost.addHeader("SOAPAction", "\"urn:getQuote\"");
HttpResponse response = client.execute(httppost);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.getEntity().writeTo(baos);
System.out.println("Reply => " + baos.toString());
}
private static final String getQuoteRequest =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
" xmlns:soap=\"http://soap.services.samples/\">\n" +
" <soapenv:Body>\n" +
" <soap:getQuote>\n" +
" <request>\n" +
" <symbol>ADRT</symbol>\n" +
" </request>\n" +
" </soap:getQuote>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
}
| < Prev | Next > |
|---|