tag:blogger.com,1999:blog-13077799495966398752024-03-21T03:14:33.745-07:00Tech Tips ExpressImalka Hemachandrahttp://www.blogger.com/profile/18053369641549194231noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-1307779949596639875.post-77464220917160039552011-07-08T10:39:00.000-07:002011-07-08T10:50:36.553-07:00Create a Client for a JAX-WS Web Service<div style="text-align: justify;">JAX-WS (Java API for XML Web Services) technology can be use to develop both web services & clients which communicates via XML. So all the calls and responses are transmitted as SOAP messages (XML files). Here I'm going to develop my servicewith netbeans IDE.</div><br />
<br />
<h2>Creating a Web Service</h2><ol><li style="text-align: justify;">Select file -> new project from the menu and choose the project category as java web -> web application.</li>
<li style="text-align: justify;">Name the project as "WSApplication" then select the server appropriately. Here i used GlassFish server. </li>
<li style="text-align: justify;">After creating the project we are going to create the web service. First right click on the project and select New -> Web Service. Then name the service and select a location or the package. According to the my sample, name the service as MultiplicationService and the package name as jaxws.</li>
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><li style="text-align: justify;">Now we are going to implement our service. The class <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;">MultiplicationService</span> </span></span>is annotated with <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">@WebService</span></span> annotation as the web service endpoint and it declares a simple method <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;">multiplication</span>, </span></span>with <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">@WebMethod</span></span> annotation (to exposed the the method to the client). Finally the method returns the multiplication of given two parameters. </li>
<pre class="java" name="code">package jaxws.multiplication;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public class MultiplicationService {
@WebMethod
public int multiplication(int i, int j) {
return i * j;
}
}
</pre><li style="text-align: justify;">Now you can deploy your service and run it. Right click on your project and select deploy, then you can run your application. <span style="font-family: "Courier New",Courier,monospace;"></span></li>
<li style="text-align: justify;"><span style="font-family: "Courier New",Courier,monospace;"></span>Using <span style="font-family: "Courier New",Courier,monospace;">wsimport</span> command we can generate all the JAX-WS artifacts by importing the, </li>
http://localhost:8080/WSApplication/MultiplicationServiceService?WSDL
<li> Open the command prompt and import artifacts in to a new package. First move to the java directory in the netbeans project. </li>
<span style="font-family: "Courier New",Courier,monospace;">> cd WSApplication\src\java </span>
<BR/>
<span style="font-family: "Courier New",Courier,monospace;">> wsimport -p soap -keep http://localhost:8080/WSApplication/MultiplicationServiceService?WSDL </span><ol>-p -> Specifying a target package </ol><ol>-keep -> Keep generated files </ol>So the above command generates the java artifacts and compile them by importing the http://localhost:8080/WSApplication/MultiplicationServiceService?WSDL
<li>So this is the new view of the project window<br />
</li>
</ol><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbhuI5hXcMHiOc1UalVhkHxURO0yIQNNXY6VLti4cWLRoOPiJgZAjC9zq8ZIk7syE5MTqsgofTqwI86-hKsPVH8afWaQX8bIg_d5YPe3Y9z_1orOd-NcdVv1COmYYY8Qi98R6gMNRB_y4/s1600/fileView.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbhuI5hXcMHiOc1UalVhkHxURO0yIQNNXY6VLti4cWLRoOPiJgZAjC9zq8ZIk7syE5MTqsgofTqwI86-hKsPVH8afWaQX8bIg_d5YPe3Y9z_1orOd-NcdVv1COmYYY8Qi98R6gMNRB_y4/s1600/fileView.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCx0v1PNWJdOCXlh14MdbWzGg0AwJ10IBqmh5ii6aYJdyfUu3PsNSJPiqvRlnyNuz04SLZQe3TXgb_tDFkOb1G321cHsAH5MEeqB8hf-7KRlZAGTlwWEN0njr_PvPopLMBDDy8nd3oQGA/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br />
</a></div><h2>Creating the Client</h2><div style="text-align: justify;">After importing JAX-WS artifacts, it's an easy task to create a client for the multiplication service by using MultiplicationService and MultiplicationServiceService classes (generated by the wsimport command). Code for the sample client is given below. It is giving the result of the multiplication method.<br />
</div><pre class="java" name="code">package jaxwsclient;
import soap.MultiplicationServiceService;
import soap.MultiplicationService;
public class Client {
public static void main(String[] args) {
MultiplicationServiceService service = new MultiplicationServiceService();
MultiplicationService port = service.getMultiplicationServicePort();
System.out.println(port.multiplication(5, 2));
}
}
</pre><br />
So it's all about creating a simple client for a jaxws web service. Hope this will be useful for u all....Imalka Hemachandrahttp://www.blogger.com/profile/18053369641549194231noreply@blogger.com0tag:blogger.com,1999:blog-1307779949596639875.post-4815236620201288122011-05-24T05:02:00.000-07:002011-05-24T21:19:00.974-07:00Reading Delimited Files Using FlatPack<div style="text-align: justify;"><div style="text-align: justify;">FlatPack is a java tool box which supports you to write & read delimited files. This is a sample java code that i have tried out using <a href="http://flatpack.sourceforge.net/">FlatPack</a> to delimited my .txt file which contains the columns names as the first record.<br />
<br />
This sample code will describe you how to insert the content of a delimited file into a database. I have tried out my code in netbeans. You should import all the dependency jar files in to your project (to lib folder) before you run this code. Download dependency files <a href="http://flatpack.sourceforge.net/downloads.html">flatpack.jar</a>, <a href="http://www.jdom.org/">jdom.jar</a> & <a href="http://www.slf4j.org/download.html">slf4j-api.jar</a>.<br />
<br />
</div><b>Sample .txt file (test.txt) </b></div><pre class="xml" name="code">"FIRST_NAME","LAST_NAME","ADDRESS","CITY","STATE","ZIP"
"JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035"
"JIMMY","ZNAME","180 SOME ST","AVON","OH","44011"
"JANE","ANAME","111 MILKY WY","AVON","OH","44001"
"FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345"
"FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345"</pre><br />
<b>FileReader.java file </b><br />
<pre class="java" name="code">import java.io.File;
import net.sf.flatpack.DataSet;
import net.sf.flatpack.DefaultParserFactory;
import net.sf.flatpack.Parser;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
public class FileReader {
static Connection con;
public static void main(String args[]) throws Exception {
con = DriverManager.getConnection("jdbc:derby:myDB;create=true;user=admin;password=admin");//enter details of your database
Statement stmt = con.createStatement();
//create a new table in "myDB" database
stmt.executeUpdate("CREATE TABLE USER_NAMES (first_name VARCHAR(32) NOT NULL, last_name VARCHAR(32) NOT NULL)");
//.txt file type used here, comma delimted with text qualified by "'s
Parser pzparser = DefaultParserFactory.getInstance().
newDelimitedParser(new File("test.txt"), ',', '"');
final DataSet ds = pzparser.parse();
while (ds.next()) {
//insert values into database by using the column names of the .txt file
PreparedStatement psInsert = con.prepareStatement("insert into USER_NAMES values (?,?)");
psInsert.setString(1, ds.getString("FIRSTNAME"));
psInsert.setString(2, ds.getString("LASTNAME"));
psInsert.executeUpdate();
}
}
}</pre><div style="text-align: justify;">If you need to print records inside the "USER_NAMES" table, you just need to copy following code snippet after the while loop.</div><pre class="java" name="code">Statement ss = con.createStatement();
ResultSet rs = ss.executeQuery("select * from USERS");
System.out.println("First Name | Last Name ");
while (rs.next()) {
System.out.println(rs.getString(1) + "\t" + rs.getString(2));
}
rs.close();
</pre><br />
Hope this post will be a useful one for you all. :)Imalka Hemachandrahttp://www.blogger.com/profile/18053369641549194231noreply@blogger.com0tag:blogger.com,1999:blog-1307779949596639875.post-82356746112053000132011-05-18T20:41:00.000-07:002011-05-22T21:41:11.319-07:00UltraESB File Handling Sample<div style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">It is a problem that someone have to continuously monitor a folder or group of folders for new files then trigger a custom action such as categorizing them, convert into desired format or response them etc</span></div><div style="color: black; text-align: justify;"><br />
</div><div style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";"> </span></div><div class="MsoNormal" face="georgia" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">So this article demonstrates the capability of the <a href="http://adroitlogic.org/" style="color: purple;">Free and Open Source UltraESB</a> to pick up a file from a directory, process it within the ESB and finally move the files to corresponding directories after processing, depending on the outcome.</span><br />
<span style="font-family: "Bodoni MT";"><br />
</span></div><div class="MsoNormal" face="georgia" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">If you installed the UltraESB v1.4.0 runtime version you’ll find all available examples inside the “ultraesb-1.4.x/samples/conf ” directory </span></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">( /home/imalka/java/ultraesb-1.4.0/samples/conf with respect to mine)</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="preformattedtext" face="georgia" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">Today I am going to work with the <a href="https://bitbucket.org/adroitlogic/ultraesb/src/60453a4dce05/resources/samples/conf/ultra-sample-401.xml" style="color: purple;">sample-401 (ultra-sample-401.xml</a> configuration file) . To try out this sample you should first create the directory structure to store the files that need to be processed and the files after processing</span></div><div class="preformattedtext" face="georgia" style="color: black; text-align: justify;"><br />
</div><div class="preformattedtext" face="georgia" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">According to the configuration, my directory hierarchy is created in the “/tmp” directory in linux operating system. The top level directory is named as “file”. One can create this folder structure in any location on the computer where you have permissions to update (instead of /tmp directory) </span></div><div class="preformattedtext" face="georgia" style="color: black; text-align: justify;"><br />
</div><div class="preformattedtext" face="georgia" style="text-align: justify;"><i style="color: black;"><span style="font-family: "Bodoni MT";">Inside “/tmp/file” directory</span></i><span style="font-family: "Bodoni MT";"></span></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPXx7FYn_WCDi1AddhFQw-Z5QtjBjxKrgS-Y3Xk4bA3K3gOAt-WiWII9JNWsAz4Ue0DsherUfV9nhTfT5aw6m9nncPTt36DogE6bZcvW0JKordjUve8UeqZdnPJ2f80gF0YcVONgsyDI/s1600/Screenshot-1.png"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5603661707440918594" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPXx7FYn_WCDi1AddhFQw-Z5QtjBjxKrgS-Y3Xk4bA3K3gOAt-WiWII9JNWsAz4Ue0DsherUfV9nhTfT5aw6m9nncPTt36DogE6bZcvW0JKordjUve8UeqZdnPJ2f80gF0YcVONgsyDI/s320/Screenshot-1.png" style="cursor: pointer; height: 174px; width: 296px;" /></a></div><br />
<div class="MsoNormal" style="color: black; text-align: justify;"><b><span style="font-family: "Bodoni MT";">incoming</span></b><span style="font-family: "Bodoni MT";"> - the directory which contains all the files which needs to be processed</span></div><div class="MsoNormal" face="georgia" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">To store processed files,</span></div><div class="MsoNormal" face="georgia" style="color: black; text-align: justify;"><b><span style="font-family: "Bodoni MT";">error</span></b><span style="font-family: "Bodoni MT";"> - contains failed files after processing</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><b><span style="font-family: "Bodoni MT";">done</span></b><span style="font-family: "Bodoni MT";"> - contains successfully processed files</span><br />
<div style="text-align: justify;"><span style="font-family: "Bodoni MT";"><b>sent</b> - we are not discuss about this directory in this article. But you can find an example related to this in sample-401(in file-proxy5) </span></div></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="MsoNormal" style="color: #990000; text-align: justify;"><span style="font-size: small;"><b><span style="font-family: "Bodoni MT";">Running the sample</span></b></span></div><div class="MsoNormal" style="color: black; text-align: justify;"></div><div style="color: black;"><i><b><span style="font-family: "Bodoni MT";">Executing configuration</span></b></i></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">Then start the UltraESB configuration, execute sample 401 as follows.</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";"> </span></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">In my case,</span><br />
<span style="font-family: "Bodoni MT";"><span style="background-color: #999999;">imalka@imalka:~/java/ultraesb-1.4.0/bin$ <span style="color: #990000;">./ultraesb.sh -sample 401 </span> </span></span></div><div class="PreformattedText" style="color: black; text-align: justify;"><br />
</div><div class="PreformattedText" style="color: black; text-align: justify;"><i><span style="font-size: small;"><b><span style="font-family: "Bodoni MT";">Insert files into “ /tmp/file/incoming ” diectory</span></b></span></i></div><div class="PreformattedText" style="color: black; text-align: justify;"><br />
</div><div class="PreformattedText" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT"; font-size: small;">Now you can create<b> </b>files according to the configurations define in sample 401.</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="ListContents" style="color: black; margin-left: 2.25pt; text-align: justify;"><b><span style="font-family: "Bodoni MT";">file-proxy1</span></b></div><br />
<div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"><u:proxy id="file-proxy1"></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:transport id="file"></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="url" value="file:///tmp/file/incoming"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="fileNamePattern" value=".*\.txt"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="startDelay" value="1000"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="repeatInterval" value="2000"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="moveAfterProcess" value="/tmp/file/done"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name="moveAfterFailure" value="/tmp/file/error"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:property name= "moveTimestampFormat" value="yyyy_MM_dd_'T'HH_mm_ss.SSSSZ"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> </u:transport></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:target></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:inSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> <u:java><![CDATA[</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> String fileName = msg.getFirstTransportHeader("FileName");</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> System.out.println("Got file : " + fileName);</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> if ("error.txt".equals(fileName)) {</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> throw new Exception("This file should fail");</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> }</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> ]]></u:java></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> </u:inSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"> </u:target></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 2.25pt;"><span style="font-family: "Bitstream Charter";"></u:proxy></span></div><div class="ListContents" style="color: black; margin-left: 2.25pt; text-align: justify;"><br />
</div><div class="ListContents" style="color: black; margin-left: 2.25pt; text-align: justify;"></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">The sample below shows the configuration used in the example, which can be easily modified and extended. The example configuration we use is as follows. it uses the method msg.getFirstTransportHeader() API by passing corresponding file name as a String.</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">This code snippet in the configuration (UltraESB sample # 401) defines a proxy service that start up after 1 second and polls for "*.txt" files at /tmp/file/incoming directory every 2 seconds. Processed and failed files are moved to /tmp/file/done or /tmp/file/error directories with a time stamp. This proxy throws an exception if the filename patches 'error.txt' so that the received files maybe tested.</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><i><br />
</i></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><i><b style="color: black;"><span style="font-family: "Bodoni MT";">Creating files for testing</span></b></i><br />
<b style="color: black;"><span style="font-family: "Bodoni MT";"> </span></b><span style="font-family: "Bodoni MT";"> </span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">Create two files, “test.txt” & “error.txt” inside “/tmp/file/incoming ” directory. After processing those two files “test.txt” file will be moved into “/tmp/file/done” directory and “error.txt” file be classified as failed file because of its name and move into “ /tmp/file/error ” directory. </span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><br />
</div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><b><span style="font-family: "Bodoni MT";">file-proxy3</span></b><br />
<br />
<span style="font-family: "Bodoni MT";">To try out this you should first</span> <span style="font-family: "Bodoni MT";">start a test server to simulate a web service</span><span style="font-family: "Bodoni MT";"> </span><br />
<div class="MsoNormal" style="color: black; text-align: justify;"></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">The UltraESB ships a sample Jetty server with web services one could use for testing. This could be started using the <a href="http://adroitlogic.org/samples-articles-and-tutorials/15-tutorials/18-getting-started-with-the-adroitlogic-toolbox-for-the-ultraesb.html">ToolBox</a> as follows, </span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="MsoNormal" style="background-color: #999999; color: black; text-align: justify;"><span style="font-family: "Bodoni MT"; font-size: small;">imalka@imalka:~$ <span style="color: #990000;">cd /home/imalka/java/ultraesb-1.4.0/bin/</span></span></div><div class="MsoNormal" style="background-color: #999999; color: black; text-align: justify;"><span style="font-family: "Bodoni MT";"><span style="background-color: #999999;"><span style="font-size: small;">imalka@imalka:~/java/ultraesb-1.4.0/bin$<span style="color: #990000;">./toolbox.sh</span></span><span style="color: #990000; font-size: small;"> </span><span style="font-size: small;"> </span> </span> </span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">Now AdroitLogic toolbox for Ultraesb window will be appear in your work place.</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">Go to file menu --></span><span style="font-family: "Bodoni MT";"> new </span><span style="font-family: Wingdings;">--> </span><span style="font-family: "Bodoni MT";"> </span><span style="font-family: "Bodoni MT";">Jetty Server (or Ctrl + j)</span></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";">Start Jetty (in port 9000) </span></div><div class="MsoNormal" style="color: black; text-align: justify;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJwgppiOtpTay-FmNnYiSUggnahzslh1d2T2MONkM4JHFiFYcfcE-MWqNLJYs-QEN4dYUneHafBEyQ1XUQ0n_pQsTJ5Fcqz8zwONODcl_KkSiNAW6Ivu0xFtVEEdvq4y5UAWwzhaLFbCQ/s1600/Screenshot-1.png" style="margin-left: 1em; margin-right: 1em;"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5603663750562777426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJwgppiOtpTay-FmNnYiSUggnahzslh1d2T2MONkM4JHFiFYcfcE-MWqNLJYs-QEN4dYUneHafBEyQ1XUQ0n_pQsTJ5Fcqz8zwONODcl_KkSiNAW6Ivu0xFtVEEdvq4y5UAWwzhaLFbCQ/s320/Screenshot-1.png" style="height: 150px; width: 320px;" /></a></div><div class="MsoNormal" style="color: black; text-align: justify;"><span style="font-family: "Bodoni MT";"> </span><b><span style="font-family: "Bodoni MT";"><br />
</span></b></div><b><span style="font-family: "Bodoni MT";"> </span></b></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-size: small;">To get a better idea of </span><span style="font-size: small;">AdroitLogic ToolBox for the UltraESB refer the following link </span><span style="font-size: small;"> </span><br />
<div style="color: #741b47;"><span style="font-size: small;"><a href="http://adroitlogic.org/samples-articles-and-tutorials/15-tutorials/18-getting-started-with-the-adroitlogic-toolbox-for-the-ultraesb.html"><span style="color: purple;">Getting started with the AdroitLogic ToolBox for the UltraESB</span></a></span><br />
<span style="font-size: small;"><span style="color: purple;"> </span> </span></div><span style="font-size: small;"></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"><u:proxy id="file-proxy3"></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:transport id="file"></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="url" value="file:///tmp/file/incoming/response.test"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="startDelay" value="1000"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="repeatInterval" value="2000"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="moveAfterProcess" value="/tmp/file/done"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="moveAfterFailure" value="/tmp/file/error"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:property name="moveTimestampFormat" value="yyyy_MM_dd_'T'HH_mm_ss.SSSSZ"/></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> </u:transport></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:target></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:inSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:java><![CDATA[</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> String fileName = msg.getFirstTransportHeader("FileName");</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> System.out.println("Got file : " + fileName);</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <a href="http://www.blogger.com/page-edit.g?blogID=1307779949596639875&pageID=4248839335887053976" name="__DdeLink__335_1674244566"> msg.holdCompletion()</a>;</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> ]]></u:java></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> </u:inSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:inDestination></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:address>http://localhost:9000/service/EchoService</u:address></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> </u:inDestination></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:outSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> <u:java><![CDATA[</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> if ("response".equals(mediation.readPayloadAsString(msg))) {</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> System.out.println("Expected response received");</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> } else {</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> throw new Exception("This file should fail");</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> }</span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> ]]></u:java></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"> </u:outSequence></span></div><div class="ListContents" style="background-color: #999999; color: black; margin-left: 0in; text-align: left;"><span style="font-family: "Bodoni MT"; font-size: small;"></u:target></span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><br />
<span style="font-family: "Bodoni MT";">The above code snippet defines a proxy that polls /tmp/file/incoming/response.test every 2 seconds and holds off message completion by using the method msg.holdCompletion() API until the file payload is sent to an HTTP endpoint at http://localhost:9000/service/EchoService and a response is received. Success or </span>failure in <span style="font-family: "Bodoni MT";">file processing is depend on the result of server response.</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><br />
</div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><i><b><span style="font-family: "Bodoni MT";">Creating files for testing</span></b></i></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">Create two files and name them as, “ response.test ” (inside “/tmp/file/incoming ” directory) and type “response” and “test”.</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">When processing two files poxy service searching for the expected results (the content “response”) inside the files. </span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";"> After processing only the file which contains the expected content will be moved into “/tmp/file/done” directory and the other file will be moved into “ /tmp/file/error ” directory. </span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><br />
</div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">Note :</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">Instead of throwing exception you can use <b>setMarkedAsFailed</b>() method in Message class.</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">Just replace,</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><b><i><span style="font-family: "Bodoni MT";">throw new Exception("This file should fail"); </span></i></b></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">line in “ ultra-sample-401.xml ” cofiguration file with,</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><b><span style="font-family: "Bodoni MT";">msg.setMarkedAsFailed(true)</span></b><span style="font-family: "Bodoni MT";">;</span></div><div class="ListContents" style="color: black; margin-left: 0in; text-align: justify;"><span style="font-family: "Bodoni MT";">This method mark the message as failed, by passing true. For more details on that method please refer the <a href="http://api.adroitlogic.org/index.html?overview-summary.html">Javadoc API</a> .</span></div><div class="ListContents" style="margin-left: 0in; text-align: justify;"><br />
</div><div class="MsoNormal" style="color: black; text-align: left;"><span style="font-family: "Bodoni MT";"></span></div>Imalka Hemachandrahttp://www.blogger.com/profile/18053369641549194231noreply@blogger.com0tag:blogger.com,1999:blog-1307779949596639875.post-36497363335087986772011-05-06T03:46:00.000-07:002011-05-18T09:29:14.918-07:00Quick Intro to UltraESB<div style="color: rgb(68, 68, 68); font-family: courier new; text-align: justify;"><p><style type="text/css">p { margin-bottom: 0.08in; }</style> </p></div> <style type="text/css">p { margin-bottom: 0.08in; }a:link { }</style> <p align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:130%;"><b>Why UltraESB</b></span></span></span></p> <p align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;">The UltraESB is very easy to use and light weight! Only 35MB to download including ready to run samples</span></span></span></p> <p align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:130%;"><b>Prerequisites</b></span></span></span></p> <p><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;"><i><b>Operating System</b></i></span></span></span></p> <p><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;">The UltraESB works best on a Linux operating system including best performance, and ease of configuration and tuning of the OS but it also work perfectly on windows system(Because UltraESB is a pure Java program)</span></span></span></p> <p><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;"><i><b>Java Development Kit</b></i></span></span></span></p> <p><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;">The UltraESB is currently certified against a JDK 1.6.x </span></span></span><a style="color: rgb(0, 0, 153);" href="http://mytechattempts.wordpress.com/2011/03/01/installing-java-manually-on-ubuntu/"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;">Installing Java on Ubuntu</span></span></a><br /><br /></p> <p align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:130%;"><b>Installation</b></span><br />You just have to follow simple steps to complete the installation</span></span></p> <p style="margin-bottom: 0in;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;"><b>Step 1 - Download UltraESB</b></span></span></span></p> <p style="margin-bottom: 0in; color: rgb(153, 0, 0);" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-weight: normal;">you can download latest UltraESB</span> <span style="font-weight: normal;">runtime version as a zip file from the following link to AdroitLogic website </span></span></span> <a style="color: rgb(0, 0, 153);" href="http://adroitlogic.org/download.html"><span style="font-family:Bitstream Charter,serif;"><span style="font-weight: normal;">Download now</span></span></a></p><br /><p style="margin-bottom: 0in;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="font-size:100%;"><b>Step 2 – Unzip the adroitlogic-ultraesb-commercial-1.4.x-bin.zip</b></span></span></span></p> <p style="margin-bottom: 0in; font-weight: normal;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;">Here I extract the zip file to “ /home/imalka/java “ directory</span></span></p> <p style="margin-bottom: 0in; font-weight: normal;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="background: none repeat scroll 0% 0% rgb(238, 238, 238);">imalka@imalka:~$ cd /home/imalka/java/</span></span></span></p> <p style="margin-bottom: 0in; font-weight: normal;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><span style="background: none repeat scroll 0% 0% rgb(238, 238, 238);">imalka@imalka:~/java$ unzip /home/imalka/Downloads/adroitlogic-ultraesb-commercial-1.4.0-bin.zip</span></span></span></p><br /><p style="margin-bottom: 0in; font-weight: normal;" align="JUSTIFY"><span style="color: rgb(0, 0, 0);"><span style="font-family:Bitstream Charter,serif;"><i>The directory structure inside “ home/imalka/java/ultraesb-1.4.x”</i></span></span></p><div style="color: rgb(68, 68, 68); text-align: justify;font-family:";"><div style="margin-bottom: 0in;" align="JUSTIFY"><p><span style="font-weight: normal;"> </span></p><p class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvDsTAR83kZZeHLH3cNghbn_PrOmac1scH5ldwio2O2BQXy2QkDQMS_kGwdKi4Av2KY-VDmaMiENBO6xWL7LW9esgtYjXu12j4tFdRDhMgMdYsyTEP0URSBI5Qtna3ogjJy9UU5dRcjeg/s1600/Screenshot.png" style="margin-left: 1em; margin-right: 1em;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvDsTAR83kZZeHLH3cNghbn_PrOmac1scH5ldwio2O2BQXy2QkDQMS_kGwdKi4Av2KY-VDmaMiENBO6xWL7LW9esgtYjXu12j4tFdRDhMgMdYsyTEP0URSBI5Qtna3ogjJy9UU5dRcjeg/s400/Screenshot.png" height="186" border="0" width="400" /></a></p><p><span style="font-weight: normal;"> </span></p></div></div>Imalka Hemachandrahttp://www.blogger.com/profile/18053369641549194231noreply@blogger.com0