<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CUcBRX0-fSp7ImA9WhdaFk4.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881</id><updated>2011-10-26T05:44:14.355-07:00</updated><category term="interview" /><category term="eclipse" /><category term="j2ee" /><category term="itext" /><category term="http" /><category term="ejb" /><category term="java" /><category term="cache" /><category term="websevice" /><category term="spring" /><category term="pdf" /><category term="jax-ws" /><title>Enterprise Java In Action</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/EnterpriseJavaInAction" /><feedburner:info uri="enterprisejavainaction" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><entry gd:etag="W/&quot;A0EFQHY-cSp7ImA9WxRSEEs.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2793793535780445140</id><published>2008-09-10T11:00:00.001-07:00</published><updated>2008-09-10T11:00:11.859-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-10T11:00:11.859-07:00</app:edited><title>Multithreaded Testing</title><content type="html">&lt;p&gt;Every now and then you&amp;#8217;ll work on something that needs to handle requests from multiple concurrent threads in a special way. I say &amp;#8220;special way&amp;#8221; because in a web application, &lt;i&gt;everything&lt;/i&gt; needs to handle being executed concurrently and there are a slew of techniques used to handle this (prototypes, thread locals, stateless services, etc). Here&amp;#8217;s an example of what I mean by &amp;#8220;special&amp;#8221;&amp;#8230;&lt;/p&gt;  &lt;p&gt;On my current project, we have a queue of articles that need human-user attention (i.e. editorial moderation). Each article must be doled out to only one moderator and there are multiple instances of the web application servicing requests in the cluster. Imagine tens of thousands of articles per day and a team of moderators churning through them. We can&amp;#8217;t rely on Java synchronization because it only works within the JVM instance, not across server instances.&lt;/p&gt;  &lt;p&gt;The simplified version of the service interface we&amp;#8217;re working on looks like this:&lt;/p&gt;  &lt;h6&gt;ArticleService.java - Example service interface&lt;/h6&gt;  &lt;pre&gt;public interface ArticleService&lt;br /&gt;{&lt;br /&gt;    Article findNextArticleForModeration();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;What makes this interesting is that we must ensure that the service doesn&amp;#8217;t hand out the same Article to more than one user. This is impossible to assert using a single thread. We&amp;#8217;ve all been told that multiple threads and automated testing don&amp;#8217;t mix. It&amp;#8217;s generally true and should be avoided if at all possible, but in some cases it&amp;#8217;s the only way we can truly assert specific behavior. I&amp;#8217;ve found a pretty simple way to do this type of testing in a reliable, consistent, and non-disruptive manner. Despite the fact that the technique leverages Java 1.5 built-in concurrency utilities, most of the engineers who have seen it are surprised and weren&amp;#8217;t aware that such testing was so easy to implement.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Given the above service interface, here&amp;#8217;s a test that will assert that no single article is given out to more than one invoker of the method findNextArticleForModeration(). The scenario we&amp;#8217;re simulating is 10 users feverishly moderating a queue of 250 articles as quickly as possible.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;ArticleServiceImplTest.java - Test to invoke service concurrently&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;...&lt;br /&gt;public void findNextArticleForModerationStressTest() throws Exception&lt;br /&gt;{&lt;br /&gt;    final int ARTICLE_COUNT = 250;&lt;br /&gt;    final int THREAD_COUNT = 10;&amp;#160;&amp;#160; // Create test data and callable tasks&lt;br /&gt;    //&lt;br /&gt;    Set&amp;lt;Article&amp;gt; testArticles = new HashSet&amp;lt;Article&amp;gt;();&amp;#160;&amp;#160; Collection&amp;lt;Callable&amp;lt;Article&amp;gt;&amp;gt; tasks = new ArrayList&amp;lt;Callable&amp;lt;Article&amp;gt;&amp;gt;();&lt;br /&gt;    for (int i = 0; i &amp;lt; ARTICLE_COUNT; i++)&lt;br /&gt;    {&lt;br /&gt;        // Test data&lt;br /&gt;        testArticles.add(new Article());&amp;#160;&amp;#160; // Tasks - each task makes exactly one service invocation.&lt;br /&gt;        tasks.add(new Callable&amp;lt;Article&amp;gt;()&lt;br /&gt;        {&lt;br /&gt;            public Article call() throws Exception&lt;br /&gt;            {&lt;br /&gt;                return articleService.findNextArticleForModeration();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }&lt;br /&gt;    articleService.createArticles(testArticles);&amp;#160;&amp;#160; // Execute tasks&lt;br /&gt;    //&lt;br /&gt;    ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);&lt;br /&gt;    // invokeAll() blocks until all tasks have run...&lt;br /&gt;    List&amp;lt;Future&amp;lt;Article&amp;gt;&amp;gt; futures = executorService.invokeAll(tasks);&lt;br /&gt;    assertThat(futures.size(), is(ARTICLE_COUNT));&amp;#160;&amp;#160; // Assertions&lt;br /&gt;    //&lt;br /&gt;    Set&amp;lt;Long&amp;gt; articleIds = new HashSet&amp;lt;Long&amp;gt;(ARTICLE_COUNT);&lt;br /&gt;    for (Future&amp;lt;Article&amp;gt; future : futures)&lt;br /&gt;    {&lt;br /&gt;        // get() will throw an exception if an exception was thrown by the service.&lt;br /&gt;        Article article = future.get();&lt;br /&gt;        // Did we get an article?&lt;br /&gt;        assertThat(article, not(nullValue()));&lt;br /&gt;        // Did the service lock the article before returning?&lt;br /&gt;        assertThat(article.isLocked(), is(true));&lt;br /&gt;        // Is the article id unique (see Set.add() javadoc)?&lt;br /&gt;        assertThat(articleIds.add(article.getId()), is(true));&lt;br /&gt;    }&lt;br /&gt;    // Did we get the right number of article ids?&lt;br /&gt;    assertThat(articleIds.size(), is(ARTICLE_COUNT));&lt;br /&gt;}&lt;br /&gt;...&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The test starts off by creating 250 test articles to be moderated. It also creates 250 &amp;#8216;tasks&amp;#8217;, each designed to make a single service invocation of findNextArticleForModeration(). The real magic happens in &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool%28int%29"&gt;Executors.newFixedThreadPool()&lt;/a&gt; and &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutorService.html#invokeAll%28java.util.Collection%29"&gt;executorService.invokeAll()&lt;/a&gt;. The first creates a new &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutorService.html"&gt;ExecutorService&lt;/a&gt; backed by a thread pool of the specified size. This is a generic ExecutorService that is designed to churn through tasks using all of the threads in the pool. invokeAll blocks until every task has finished executing. In this test, 10 threads will rip through 250 tasks, each making a single call to our service and capturing the result of that call. Each task execution results in a &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html"&gt;Future&lt;/a&gt;, which is a handle to the results of the task (and more).&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Iterating over each resulting future, we make several assertions. The most important one is the last, where we assert that every task is given a unique Article. Thanks to the natural semantics of Set, this is easy to do in an elegant way. Another useful, though unexpected, feature is that if an exception occurs during the task execution, an &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutionException.html"&gt;ExecutionException&lt;/a&gt; will be thrown when &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html#get%28%29"&gt;get()&lt;/a&gt; is called on the corresponding Future. If our service fails for some reason, the test will fail because no exceptions are expected.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This technique makes simulating a multi-threaded environment in a test easy and readable. It&amp;#8217;s important to only use this technique when it&amp;#8217;s &lt;em&gt;really&lt;/em&gt; necessary. The resulting test is more of an integration test than a unit test, and its run time is orders of magnitude more than a unit test, so overuse of the technique will artificially inflate the time it takes to runs the tests. After I&amp;#8217;ve finished working on the component under test, I will reduce the test-data size and thread count to a level that the test still provides value, but is no longer a stress test (e.g. 10 articles and 2 threads). The next time the component is being worked on, the developer can crank up the values and run the tests to be confident that the behavior isn&amp;#8217;t broken.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The complete source for a working example of this technique is available &lt;a href="http://svn.carbonfive.com/public/christian/multi-threaded-testing/trunk"&gt;here&lt;/a&gt;. You&amp;#8217;ll need Maven (or IntelliJ IDEA 7.x) to build and run the test. By default, the tests run against an in-memory H2Database instance, but if you look at application.properties you&amp;#8217;ll see configurations for PostgreSQL and MySQL as well.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Happy testing!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;em&gt;by christian&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2793793535780445140?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2793793535780445140/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2793793535780445140" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2793793535780445140?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2793793535780445140?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/09/multithreaded-testing.html" title="Multithreaded Testing" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;AkcCQHk5fyp7ImA9WxRTGU0.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-8149255018540319251</id><published>2008-09-08T14:07:00.001-07:00</published><updated>2008-09-08T14:07:41.727-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-08T14:07:41.727-07:00</app:edited><title>Launching system processes from Java applications</title><content type="html">&lt;p&gt;Are you tired of issues with Runtime.getRuntime().exec()? I was!&lt;/p&gt;  &lt;p&gt;So I decided to create a small library to handle all the issues. Once and for all.&lt;/p&gt;  &lt;h4&gt;Main features&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;It's easy to redirect stdin, stderr and stdout to appropriate Java Input and Output streams, so you can now embed operating-system processes inside your applications. &lt;/li&gt;    &lt;li&gt;It's very easy to cancel a running process, by using the Future&amp;lt;Integer&amp;gt; interface. &lt;/li&gt;    &lt;li&gt;Automatically handles pipipng process streams into Java streams (and viceversa). &lt;/li&gt;    &lt;li&gt;Runs well in Linux and Windows. Probably runs well in Solaris and MacOSX too (haven't tried yet though) &lt;/li&gt;    &lt;li&gt;You can specify a working directory for the running process. &lt;/li&gt;    &lt;li&gt;Very small library (just one final class and two interfaces). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.antonioshome.net/attic/clexec/CLEXEC-SRC.zip"&gt;Sources&lt;/a&gt; and &lt;a href="http://www.antonioshome.net/attic/clexec/CLEXEC.jar"&gt;binaries&lt;/a&gt; are available in my attic, of course.&lt;/p&gt;  &lt;h4&gt;What for?&lt;/h4&gt;  &lt;p&gt;This small library will allow me to embed Scheme interpreters such as guile or scm or mzscheme inside the Scheme IDE I'm building on top of the NetBeans Platform.&lt;/p&gt;  &lt;h4&gt;How to use?&lt;/h4&gt;  &lt;p&gt;You can see the Javadoc. Basic usage is as follows:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;// Obtain a process executor&lt;br /&gt;ProcessExecutor executor =&lt;br /&gt;   ProcessExecutorFactory.getDefault();&lt;br /&gt;&lt;br /&gt;// Launch the process&lt;br /&gt;Future&amp;lt;Integer&amp;gt; process = executor.execute(&lt;br /&gt;   ProcessInputOutput.DEFAULT, null, &amp;quot;/bin/ls -ali&amp;quot;);&lt;br /&gt;&lt;br /&gt;// If you want to kill the process write:&lt;br /&gt;process.cancel( true );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// To get the exit status of the process use:&lt;br /&gt;System.out.println( process.get() );&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now, that's easy, isn't it?&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;What next?&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As usual I'll do some more extra testing and, who knows, maybe this could be integrated in NetBeans in the future!&lt;br /&gt;  &lt;br /&gt;All bugs and enhancements are, of course, welcome. Please send me an email or add a comment to this entry.&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Happy processing,&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Antonio&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-8149255018540319251?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/8149255018540319251/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=8149255018540319251" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8149255018540319251?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8149255018540319251?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/09/launching-system-processes-from-java.html" title="Launching system processes from Java applications" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C08BQ3w5cCp7ImA9WxRTF08.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-4629457650760809727</id><published>2008-09-06T10:24:00.001-07:00</published><updated>2008-09-06T10:24:12.228-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-06T10:24:12.228-07:00</app:edited><title>GridGain - simple, effective, and made of pure happy juice</title><content type="html">&lt;p&gt;Let's talk about real, tangible, hype-less, &lt;q&gt;grid&lt;/q&gt; computing. I swear, it's real. &lt;/p&gt;  &lt;p&gt;I've heard endless sales pitches about &lt;q&gt;moving your apps to the grid.&lt;/q&gt; It's almost quaint how easy they make it sound. Let's pretend, for a moment, you have an application that benefits from parallelization, you have no issues with data availability, and you control your source code (because you're not going to make every application you use magically run in parallel regardless of the sales pitch). &lt;/p&gt;  &lt;p&gt;To this end, I've been using &lt;a href="http://www.gridgain.com"&gt;GridGain&lt;/a&gt;, recently. In a few weeks I might even be able to talk about why, but that's far less important. For those living under a rock, GridGain is a Java implementation of a Google-ish &lt;a href="http://labs.google.com/papers/mapreduce.html"&gt;map / reduce&lt;/a&gt; system. The effect is that, with very little code and even less configuration, one can cause suitable code to run in parallel, on a grid of JVM nodes. I won't discuss the map / reduce concept in detail, other than to say the idea is to: &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;take a job, break it up into smaller units of work &lt;/li&gt;    &lt;li&gt;assign these units to processing nodes &lt;/li&gt;    &lt;li&gt;collect the results from the processing nodes &lt;/li&gt;    &lt;li&gt;aggregate the results, as appropriate &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Items #1 and #2 refer to the &lt;q&gt;map&lt;/q&gt; part of the process, while #3 and #4 refer to the &lt;q&gt;reduce&lt;/q&gt; component. &lt;/p&gt;  &lt;p&gt;There are two ways to use GridGain. The first method is to annotate methods (either static or otherwise) that should be run on the grid. This is fast to write, and coarse-grained in that the unit of work is (usually, but need not be) the entire method. The second method of running tasks on the grid is by directly accessing the &lt;a href="http://www.gridgain.com/javadoc/overview-summary.html"&gt;GridGain APIs&lt;/a&gt;. This, of course, tends to mean a bit more code, but to some, may be easier to understand and debug. Which method you choose, will probably depend mostly on preference, but could also be influenced by dependencies. I opted for direct invocation via the APIs because I prefer not to futz around with AspectJ - which is how the annotations actually work - and friends unless I'm also using it for other things. GridGain is happy to work with AspectJ, Spring AOP, or JBoss AOP, according to the docs, although they seem to recommend against Spring AOP due to a lack of &lt;q&gt;full functionality&lt;/q&gt; or some such. I didn't get too much into the details. &lt;/p&gt;  &lt;p&gt;The APIs are surprisingly direct and simple to understand for something that is so seemingly nebulous. This, coupled with some of the best documentation I've seen in some time, makes for a pleasant experience. The only thing that makes my vision a little blurry is the generic-soup that begins to occur, but for the type safety, it's probably worth it; anything that needs to run on a grid is arguably important enough that you can groan through the angle brackets. &lt;/p&gt;  &lt;p&gt;Running a GridGain node requires zero configuration, in many cases, although being a Spring application, itself, and being well written with a number of service provider interfaces, one could easily sculpt what amounts to a custom product out of it. What is nice is that one can easily run GridGain within an IDE like Eclipse during testing and development, which significantly speeds the process of rolling out your apps. While on the topic of time saving features, GridGain using peer-based class loading meaning, for simple, self contained, tasks, one need not do any kind of special deployment to execute tasks. The task classes are transmitted and loaded by GridGain itself, without any need for restarts or copying. It's like a magic fairy sprinkled happy-time sparkles in my brain. &lt;/p&gt;  &lt;p&gt;Of course, GridGain provides all manners of fancy pants things that I haven't yet explored such as node affinity for processing &lt;q&gt;close to&lt;/q&gt; your data, integration with caching products from Oracle and JBoss, different scheduling and communication methods, and similar goodies. I also haven't fully explored implementing custom service providers, but it's mostly because I couldn't find one that I might need that wasn't already implemented. &lt;/p&gt;  &lt;p&gt;Here's a bottom of the barrel, super-contrived, example to whet your noggin knobs. &lt;/p&gt;  &lt;pre&gt;public class TestApp {&lt;br /&gt;&lt;br /&gt;  static public void main(String[] args) throws GridException {&lt;br /&gt;    try {&lt;br /&gt;      Grid grid;&lt;br /&gt;      GridTaskFuture future;&lt;br /&gt;&lt;br /&gt;      grid = GridFactory.start();&lt;br /&gt;&lt;br /&gt;      future = grid.execute(MyTask.class, &amp;quot;Print me...&amp;quot;);&lt;br /&gt;&lt;br /&gt;      // This causes GridGain to block until all jobs are complete. It&lt;br /&gt;      // also returns the result, if there is one.&lt;br /&gt;      future.get();&lt;br /&gt;&lt;br /&gt;    } finally {&lt;br /&gt;      GridFactory.stop(false);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * The task class is going to be the unit of word that gets split&lt;br /&gt; * into smaller jobs (GridJob) that get distributed and executed.&lt;br /&gt; * I'm using adapters for both the task as well as the jobs to avoid&lt;br /&gt; * extra work, so yes, I'm cheating.&lt;br /&gt; */&lt;br /&gt;public class MyTask extends GridTaskAdapter&amp;lt;String, String&amp;gt; {&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  protected Collection&amp;lt;? extends GridJob&amp;gt; split(int gridSize, String arg)&lt;br /&gt;    throws GridException {&lt;br /&gt;&lt;br /&gt;    List&amp;lt;GridJobAdapter&amp;lt;String&amp;gt;&amp;gt; jobs;&lt;br /&gt;&lt;br /&gt;    jobs = new ArrayList&amp;lt;GridJobAdapter&amp;lt;String&amp;gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;    // Build a collection of jobs to run on the grid.&lt;br /&gt;&lt;br /&gt;    for (int i = 0; i &amp;lt; 10; i++) {&lt;br /&gt;      jobs.add(new GridJobAdapter&amp;lt;String&amp;gt;(arg) {&lt;br /&gt;        @Override&lt;br /&gt;        public Serializable execute() throw GridException {&lt;br /&gt;          System.out.println(&amp;quot;arg:&amp;quot; + getArgument());&lt;br /&gt;        }&lt;br /&gt;      });&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return jobs;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public String reduce(List&amp;lt;GridJobResult&amp;gt; results) throws GridException {&lt;br /&gt;    System.out.println(&amp;quot;Not much to reduce when we're printing stuff...&amp;quot;);&lt;br /&gt;&lt;br /&gt;    return null;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I know it's probably considered verbose, still, to the scripting community at large, but when you consider what's happening here, it's pretty bad ass. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It's worth noting that there are other frameworks similar to GridGain, in this space, that deserve a look as well. &lt;a href="http://hadoop.apache.org/core/"&gt;Hadoop&lt;/a&gt; comes to mind. I have no direct experience with them, so I don't want to say either way, but I have heard nice things. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is all very contrived and still thin on details. My goal wasn't to reproduce a howto, but more so to, well, to glow about GridGain, to some small degree. I encourage everyone to check out GridGain for themselves and find the things relevant to them. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;em&gt;by E. Sammer&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-4629457650760809727?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/4629457650760809727/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=4629457650760809727" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4629457650760809727?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4629457650760809727?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/09/gridgain-simple-effective-and-made-of.html" title="GridGain - simple, effective, and made of pure happy juice" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0IMQX89cSp7ImA9WxRTF08.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-9025902608654560758</id><published>2008-09-06T10:19:00.001-07:00</published><updated>2008-09-06T10:19:40.169-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-06T10:19:40.169-07:00</app:edited><title>Improve your unit-tests with jMock2</title><content type="html">&lt;p&gt;Writing unit-tests should be part of your development process whether you write them before or after the actual coding I leave that up to you. On of the pitfalls of writing unit tests is that the units become to big.&lt;/p&gt;  &lt;p&gt;The unit your are testing, a method in most cases probably uses some other beans or services to do its job. In your unit test you don&amp;#8217;t want to test those other beans but just your method. Because you use decoupling &lt;img alt="Smiley" src="http://technology.amis.nl/blog/wp-content/plugins/xinha4wp/xinha_core/plugins/InsertSmiley/smileys/0002.gif" /&gt; you can easily override the interfaces of the services in your test case and inject those services in your instance you are testing. This is an example of a mock object.&lt;/p&gt;  &lt;p&gt;This is maybe good for one or two mock objects but it gets tricky. Who test the mock objects? You will soon get a lot of logic in the mock objects. To reuse them they need to be extracted from the unit test. You don&amp;#8217;t have checks if the mock objects are really called. There are several frameworks that will do this mocking for you. You supply them the interface and they will give you an implementation which can be injected into the bean thats being tested.&lt;img alt="...." src="http://technology.amis.nl/blog/wp-content/plugins/xinha4wp/xinha_core/plugins/InsertMore/img/ed_more.png" /&gt;&lt;/p&gt;  &lt;p&gt;Recently (14 jul 2008) jMock has released their 2.5.0 version of the lightweight mock framework. In the next example I shortly demonstrate how jMock2 can be used to improve your unit test.&lt;/p&gt;  &lt;p&gt;In the example I want to test the registerUser method on the RegistrationBean. The bean will only create a new user if the username and password are not blank (they must contain a non white space character). The method will return true if the user is created otherwise false. The method uses to other references. The references need to be mocked out in the unit test.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;code&gt;@Stateless     &lt;br /&gt;&lt;strong&gt;public class &lt;/strong&gt;RegistrationBean &lt;strong&gt;implements &lt;/strong&gt;RegistrationLocal {      &lt;br /&gt;@EJB      &lt;br /&gt;&lt;strong&gt;private &lt;/strong&gt;NotificationMailerLocal notificationMailerBean;      &lt;br /&gt;@PersistenceContext      &lt;br /&gt;&lt;strong&gt;private &lt;/strong&gt;EntityManager em;      &lt;br /&gt;&lt;strong&gt;public &lt;/strong&gt;&lt;strong&gt;boolean &lt;/strong&gt;registerUser(String username, String passwd) {      &lt;br /&gt;&lt;strong&gt;if &lt;/strong&gt;(StringUtils.isNotBlank(username) &amp;amp;&amp;amp; StringUtils.isNotBlank(passwd)) {      &lt;br /&gt;User user = &lt;strong&gt;new &lt;/strong&gt;User(username, passwd);      &lt;br /&gt;em.persist(user);      &lt;br /&gt;notificationMailerBean.mailNewRegistration(user);      &lt;br /&gt;&lt;strong&gt;return true&lt;/strong&gt;;      &lt;br /&gt;}      &lt;br /&gt;&lt;strong&gt;return false&lt;/strong&gt;;      &lt;br /&gt;}      &lt;br /&gt;&amp;#8230;      &lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I use the Junit4 framework to write the tests.   &lt;br /&gt;To tell Junit4 I use jMock the @RunWith is added on top of the test class. The test checks if a user is created when a non blank username and password is supplied. jMock uses expectations. If you don&amp;#8217;t add them and the mocked object is called the test will fail. With expectations we can tell jMock that we expect that a mocked method is called exactly once or we don&amp;#8217;t care. There are many more expectations you can add.    &lt;br /&gt;But in this example we expect that the notification mail is send exactly once with a non null user object. We also tell Jmock that we are not interested in the calls to the em mock object.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;@RunWith(JMock.&lt;strong&gt;class&lt;/strong&gt;)      &lt;br /&gt;&lt;strong&gt;public class &lt;/strong&gt;RegistrationBeanTest {      &lt;br /&gt;Mockery mockContext = &lt;strong&gt;new &lt;/strong&gt;JUnit4Mockery();      &lt;br /&gt;@Test      &lt;br /&gt;&lt;strong&gt;public &lt;/strong&gt;&lt;strong&gt;void &lt;/strong&gt;registerUser() {      &lt;br /&gt;&lt;strong&gt;final &lt;/strong&gt;NotificationMailerLocal mailer = mockContext      &lt;br /&gt;.mock(NotificationMailerLocal.&lt;strong&gt;class&lt;/strong&gt;);      &lt;br /&gt;&lt;strong&gt;final &lt;/strong&gt;EntityManager em = mockContext.mock(EntityManager.&lt;strong&gt;class&lt;/strong&gt;);      &lt;br /&gt;mockContext.checking(&lt;strong&gt;new &lt;/strong&gt;Expectations() {      &lt;br /&gt;{      &lt;br /&gt;ignoring(em);      &lt;br /&gt;one(mailer).mailNewRegistration(with(aNonNull(User.&lt;strong&gt;class&lt;/strong&gt;)));      &lt;br /&gt;}      &lt;br /&gt;});      &lt;br /&gt;RegistrationBean regBean = &lt;strong&gt;new &lt;/strong&gt;RegistrationBean();      &lt;br /&gt;regBean.setNotificationmailer(mailer);      &lt;br /&gt;regBean.setEntityManager(em);      &lt;br /&gt;assertTrue(regBean.registerUser(&amp;quot;TestUser&amp;quot;, &amp;quot;qwerty&amp;quot;));      &lt;br /&gt;}      &lt;br /&gt;&amp;#8230;      &lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;In the second test I want to test that the user is not created when we supply an empty string as password. The registerUser method should return false. But I also want to make sure that the registration mail is not sent. &lt;/p&gt;  &lt;p&gt;&lt;code&gt;@Test     &lt;br /&gt;&lt;strong&gt;public &lt;/strong&gt;&lt;strong&gt;void &lt;/strong&gt;registerInvalidUser() {      &lt;br /&gt;&lt;strong&gt;final &lt;/strong&gt;NotificationMailerLocal mailer = mockContext      &lt;br /&gt;.mock(NotificationMailerLocal.&lt;strong&gt;class&lt;/strong&gt;);      &lt;br /&gt;&lt;strong&gt;final &lt;/strong&gt;EntityManager em = mockContext.mock(EntityManager.&lt;strong&gt;class&lt;/strong&gt;);      &lt;br /&gt;mockContext.checking(&lt;strong&gt;new &lt;/strong&gt;Expectations() {      &lt;br /&gt;{      &lt;br /&gt;never(em);      &lt;br /&gt;never(mailer);      &lt;br /&gt;}      &lt;br /&gt;});      &lt;br /&gt;RegistrationBean regBean = &lt;strong&gt;new &lt;/strong&gt;RegistrationBean();      &lt;br /&gt;regBean.setNotificationmailer(mailer);      &lt;br /&gt;regBean.setEntityManager(em);      &lt;br /&gt;assertFalse(regBean.registerUser(&amp;quot;TestUser&amp;quot;, &amp;quot;&amp;quot;));      &lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Another problem I often have with mock objects is how to tell the mocked object what it should return. For this I changed the check in the registrationBean a little. It now uses a other bean that checks if the password is strong enough.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&lt;strong&gt;if &lt;/strong&gt;(StringUtils.isNotBlank(username) &amp;amp;&amp;amp; passwordCheckerBean.checkPass(passwd)) {      &lt;br /&gt;&amp;#8230;      &lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;In the test we now also need a mock object for the passwordCheckerBean. But this time the mocked object should return a value. With Jmock you can also express this in a Expectation. The expectations part says that the checkPass method on the passChecker mock object is called only once with any String object. If it is called it will return true.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;#8230;     &lt;br /&gt;&lt;strong&gt;final &lt;/strong&gt;PasswordCheckerLocal passChecker = mockContext.mock(PasswordCheckerLocal.&lt;strong&gt;class&lt;/strong&gt;);      &lt;br /&gt;mockContext.checking(&lt;strong&gt;new &lt;/strong&gt;Expectations() {      &lt;br /&gt;{      &lt;br /&gt;&amp;#8230;      &lt;br /&gt;one(passChecker).checkPass(with(any(String.&lt;strong&gt;class&lt;/strong&gt;)));      &lt;br /&gt;will(returnValue(&lt;strong&gt;true&lt;/strong&gt;));      &lt;br /&gt;}      &lt;br /&gt;});      &lt;br /&gt;&amp;#8230;      &lt;br /&gt;regBean.setPasswordChecker(passChecker);      &lt;br /&gt;&amp;#8230;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;For more about adding expectations to your mock objects go to the &lt;a href="http://www.jmock.org"&gt;http://www.jmock.org&lt;/a&gt; site.    &lt;br /&gt;They have a quick getting started but also an useful cheat sheet&lt;a href="http://www.jmock.org/cheat-sheet.html"&gt; http://www.jmock.org/cheat-sheet.html&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;by Alan van Dam&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-9025902608654560758?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/9025902608654560758/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=9025902608654560758" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/9025902608654560758?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/9025902608654560758?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/09/improve-your-unit-tests-with-jmock2.html" title="Improve your unit-tests with jMock2" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkEASX4zeyp7ImA9WxdREEQ.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-7416558730271694349</id><published>2008-05-29T12:50:00.001-07:00</published><updated>2008-05-29T12:50:48.083-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-29T12:50:48.083-07:00</app:edited><title>Optimize your java applications synchronization-instantiation-casting-exceptions-and-threads</title><content type="html">&lt;p&gt;&lt;strong&gt;Method Call Optimization:&lt;/strong&gt; There are two basic categories of methods: those that can be statically resolved by the compiler and the rest, which must be dynamically resolved at run time. To statically resolve a method, the compiler must be able to determine absolutely which method should be invoked. Methods declared as static, private, and final, as well as all constructors, may be resolved at compile time because the class to which the method belongs to is known. A statically resolved method executes more quickly than a dynamically resolved method because, statically resolved method, the binding is done by the compiler and for other methods the binding should happen at runtime depending on the object instance that is being refered.&lt;/p&gt;  &lt;p&gt;Even for a statically resolved methods, there will be considerable execution overhead &amp;#8211; the local variables should be saved, the method arguments should be pushed to the stack. So it is better to eliminate small methods if there is only one caller. You may not be able to eliminate method calls in your code, but you can at least minimize the method calls at the bytecode level by inline the methods. You can instruct the compiler to inline small methods by using the &amp;#8211;O flag.&lt;/p&gt;  &lt;p&gt;Inlining a method call inserts the code for the method directly into the code making the method call. This eliminates the overhead of the method call. For a small method this overhead can represent a significant percentage of its execution time. Note that only methods declared as either private, static, or final can be considered for inlining, because only these methods are statically resolved by the compiler. Also, synchronized methods won't be inlined. The compiler will only inline small methods typically consisting of only one or two lines of code.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;&lt;em&gt;Warning:&lt;/em&gt;&lt;/strong&gt;&lt;/u&gt; Please do not use the inlining option if you are using the 1.0 version of javac compiler because it has a bug that may generate byte code that can't pass the bytecode verifier when the -O option is use. This bug has been fixed in JDK 1.1 onwards.&lt;/p&gt;  &lt;p&gt;The next best option is to convert method and especially interface invocations to static, private, or final calls. If you have methods in your class that don't make use of instance variables or call other instance methods, they can be declared static. If a method doesn't need to be overridden, it can be declared final. And methods that shouldn't be called from outside the class should always be declared private anyway.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Minimize Synchronization:&lt;/strong&gt; Call to a synchronized method is very expensive, in fast it is the most expensive method call. Not only does it involve getting the lock on an object&amp;#8217;s monitor but, but there is always the potential that the call will be delayed waiting for the monitor for the object. And when the method returns, the monitor must be released, which takes more time. &lt;/p&gt;  &lt;p&gt;So, it is always better to reduce usage of synchronized methods and blocks as far as possible, so make sure that the operations actually require synchronization. Be careful though; this is not an area of your program to be overly ambitious in optimizing as the problems you can cause can be difficult to track down.&lt;/p&gt;  &lt;p&gt;Also, you must try to use synchronized methods in place of synchronized blocks as far as possible because synchronized method invocation is slightly faster than entering a synchronized block as synchronized method invocation is handled differently in the byte code. &lt;/p&gt;  &lt;p&gt;Also, a call to a synchronized method when the monitor is already owned by the thread executes somewhat faster than the synchronized method when the monitor isn't owned. So, If you have a heavily synchronized class that is calling lots of synchronized methods from other synchronized methods, you may want to consider having a few synchronized methods delegate the work to private non-synchronized methods to avoid the overhead of reacquiring the monitor.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Save Casting:&lt;/strong&gt; Casting object references to refer to different object types in Java (object casts) can get pretty dense -- especially if you work with a lot of lists or other collection classes. It turns out that any object cast that can't be resolved at compile time is so expensive that that it is better to save the cast object in a local variable than to repeat the cast. &lt;/p&gt;  &lt;p&gt;So instead of writing:&lt;/p&gt;  &lt;p&gt;boolean equals (Object obj) {    &lt;br /&gt;if (obj instanceof Rectangle)     &lt;br /&gt;return (((Rectangle)obj).x == this.x &amp;amp;&amp;amp; ((Rectangle)obj).y == this.y &amp;amp;&amp;amp; ((Rectangle)obj).width == this.width &amp;amp;&amp;amp; ((Rectangle)obj).height == this.height);     &lt;br /&gt;return false;     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Do the casting only once:&lt;/p&gt;  &lt;p&gt;boolean equals (Object obj) {    &lt;br /&gt;if (obj instanceof Rectangle) {     &lt;br /&gt;Rectangle rect = (Rectangle)obj;     &lt;br /&gt;return (rect.x == this.x &amp;amp;&amp;amp; rect.y == this.y &amp;amp;&amp;amp; rect.width == this.width &amp;amp;&amp;amp; rect.height == this.height);     &lt;br /&gt;}     &lt;br /&gt;return false;     &lt;br /&gt;}     &lt;br /&gt;If the cast is to an interface, it's probably twice slower than casting to a class.     &lt;br /&gt;In fact, there is one type of cast that can take much longer to execute. If you have an object hierarchy like     &lt;br /&gt;interface I {}     &lt;br /&gt;class Super {}     &lt;br /&gt;class Sub extends Super implements I {}     &lt;br /&gt;then the following cast, to an interface implemented by a subclass, takes anywhere from two to three times as long as casting to the subclass.     &lt;br /&gt;Super su = new Sub();     &lt;br /&gt;I i = (I) su;     &lt;br /&gt;The further the separation between the interface and the subclass (that is, the further back in the interface inheritance chain the cast interface is from the implemented interface), the longer the cast takes to resolve.     &lt;br /&gt;Also beware of unnecessary uses of instanceof. The following cast is resolved by the compiler and produces no runtime code to implement the unnecessary cast.&lt;/p&gt;  &lt;p&gt;Rectangle q = new Rectangle ();    &lt;br /&gt;Rectangle p = (Rectangle) q;     &lt;br /&gt;However,     &lt;br /&gt;Rectangle p = new Rectangle ();     &lt;br /&gt;boolean b = (p instanceof Rectangle);     &lt;br /&gt;cannot be resolved by the compiler because instanceof must return false if p == null.&lt;/p&gt;  &lt;p&gt;Casting data types is simpler and cheaper than casting objects because the type of the data value being cast is known (for example, an int never is actually a subclass of an int.) However, again since int is the natural size used by the JVM (ints are the common data type that all other data types can be directly converted to and from), beware of using the other data types. Casting from a long to a short requires first casting from a long to an int and then from an int to a short.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Reuse Object Instances:&lt;/strong&gt; Creating an object is fairly expensive in terms of CPU cycles. On top of that, discarded objects will need to be garbage collected at some point. It takes about as long to garbage collect an object as it takes to create one.     &lt;br /&gt;Also, the longer the hierarchy chain for the object, the more constructors that must be called. This adds to the instantiation overhead. If you add extra layers to your class hierarchy for increased abstraction, you'll also increase the instantiation time.     &lt;br /&gt;The best option is to avoid instantiating objects in tight loops. Where possible, reuse an existing object.     &lt;br /&gt;The loop     &lt;br /&gt;for (int i = 0; i &amp;lt; limit; i++) {     &lt;br /&gt;ArrayList list = new ArrayList();     &lt;br /&gt;// do something with list...     &lt;br /&gt;}     &lt;br /&gt;would be faster if written as     &lt;br /&gt;ArrayList list = new ArrayList();     &lt;br /&gt;for (int i = 0; i &amp;lt; limit; i++) {     &lt;br /&gt;list.clear();     &lt;br /&gt;// do something with list...     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Also, it is better not to explicitly initialize instance variables to their default values because when an objects is created all instance variables will by virtue get initialized to the default values. If you are explicitly doing the same, it will duplicate the default initialization, generate additional bytecodes, and make the instantiation take longer. (There are rare cases when the explicit initialization is needed to reinitialize a variable that was altered from the default value during the super class's constructor.)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;     &lt;br /&gt;Optimizing Exception Handling:&lt;/strong&gt; The try/catch/finally mechanism is implemented efficiently in the JVM. When an exception is thrown, only a quick check is done against the exception table for each method in the call chain to determine whether or not the exception is handled by the method.     &lt;br /&gt;Also, a try {} statement is cheap, no much bytecodes are generated, all that try {} statement adds to your code as far as overhead is the goto bytecode to skip the catch () {} statement and one or more entries in the method's exception table. A finally statement adds a little more overhead as it is implemented as an inline subroutine.&lt;/p&gt;  &lt;p&gt;However, instantiating a new exception can be expensive. An exception generates and stores a snapshot of the stack at the time the exception was instantiated. This is where most of the time for instantiating an exception goes. If you're throwing exceptions regularly as part of the normal operation of your code, you may want to rethink your design.&lt;/p&gt;  &lt;p&gt;But, if you do have a need to do this (such as returning a result from several calls deep), and if you're simply going to catch and handle the exception, then repeatedly instantiating an exception can be a waste of time. Instead, it is possible to reuse an exception. That is when you are not concerned with logging the exception, but you are only interested in returning a result from several calls deep, then you can have the exception as a class variable and always change the required values in the exception and throw the reused exception.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Reduce Threads:&lt;/strong&gt; Using threads can cause problems memory wise and also CPU cycle wise. Each running thread has both a native/&amp;quot;C&amp;quot; stack and a Java stack which will take some memory. There is also an overhead for switching between threads (a context switch), which varies significantly between platforms. Moreover, if the threads are in some synchronized method or block, then a context switch also involves releasing / acquiring the monitor for an object, so context switch will be much slower when threads are in synchronized methods or blocks.     &lt;br /&gt;There are many places in your code where threads can be minimized or avoided. For Example, a java game can be easily implemented by using separate threads for painting, keys handling and AI, In fact, Painting, key handling and AI together can be handled by a single thread make will make the code slightly complex but will avoid the over associated to context switching between threads..&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-7416558730271694349?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/7416558730271694349/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=7416558730271694349" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7416558730271694349?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7416558730271694349?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/05/optimize-your-java-applications.html" title="Optimize your java applications synchronization-instantiation-casting-exceptions-and-threads" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DE8DRXk_eSp7ImA9WxdSF08.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2667021484906906806</id><published>2008-05-25T07:47:00.001-07:00</published><updated>2008-05-25T07:47:54.741-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-25T07:47:54.741-07:00</app:edited><title>Java Architectural Knowledge for Job Interviews. Are we prepared?</title><content type="html">&lt;p&gt;I already interviewed lots of Java developers during hiring activities. As part of the interview, besides other things, I like to understand if the person being interviewed has understanding of the applications he/she develops as a whole, I mean, not only understands business requirements but also understands the entire architecture of the application and, most important, why that specific architecture is in place for that application and its specific needs.&lt;/p&gt;  &lt;p&gt;So below a typical dialog between a candidate (C) and I regarding architecture of a Java EE application.&lt;/p&gt;  &lt;p&gt;- So, could you please describe, from your perspective, what should be a typical Java EE architecture for, let's say, a medium-size web-based application?   &lt;br /&gt;C - Of course. Well, typically I will have in place a lightweight container like Spring and persistence mechanism like Hibernate. Spring will do everything for me.    &lt;br /&gt;- Alright, let me be more specific, I believe my question was not well-built. Imagine if the end user is about to submit a form data. What will be the flow that data would take to be persisted in database? Describe to me the building blocks, all the path of the data, which objects will apply business rules, which objects will handle web requests, etc. Feel free to draw this architecture if you think it is better for you.    &lt;br /&gt;C - Not necessary. Well, I would put Spring MVC in place to handle all the requests. For persistence, Spring DAO with Hibernate support.    &lt;br /&gt;- hum, I think you haven't got the point. Forget about Spring. forget about EJBs. Forget about lightweight or heavyweight containers. Forget about Hibernate. Imagine you don't have these technologies to assist you. You have to propose the architecture without using any specific product. What would you do? Remember, no products. Just give me building blocks.    &lt;br /&gt;C - .....    &lt;br /&gt;C - .....    &lt;br /&gt;C - In the presentation layer an object will take all data submitted and...    &lt;br /&gt;- Which object?    &lt;br /&gt;C - hum...... maybe a Servlet object or .....    &lt;br /&gt;- Or a managed bean, something like this? Ok, go on. Once data is retrieved from the UI, what will happen?    &lt;br /&gt;C - ... ok, data will be sent to an object and this object will perform business rules and after that data will be persisted.    &lt;br /&gt;- Could you please be more specific? Do you have in mind any design pattern that could assist you for this architecture? What would be the structure for the domain layer? And Persistence layer?    &lt;br /&gt;C - ...    &lt;br /&gt;C - Man, I would work with Spring, it does all those things for me.    &lt;br /&gt;- Alright, that's good for me. Thank you.&lt;/p&gt;  &lt;p&gt;Let me say somethings about this dialog.   &lt;br /&gt;&lt;strong&gt;First&lt;/strong&gt;: I don't have any problems with Spring. In &lt;a href="http://weblogs.java.net/blog/giovanisalvador/archive/2008/03/java_and_the_ne.html"&gt;one of my posts&lt;/a&gt; I said that I never used it because I never had to. We need to find solutions for our problems and not create problems for given solutions. By the way, comments in that post were great.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;: The candidate never asked how many transactions per minute, hour, etc, how many concurrent users, if it is a critical application. That dictates the architecture. We can't have silver bullet and it seems today most of the &amp;quot;architects&amp;quot; have silver bullets. And, even worst, relying on specific products. Also, based on the non-functional requirements of the application we could see if clustering would be needed. But no, no question about those kinds of things at all.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Third&lt;/strong&gt;: The lack of knowledge on some typical design patterns is also something to take into account. Fa&amp;#231;ade? DAO? Value Objects? Application Controller? Even if we don't need all of them, candidates should be prepared to use them when necessary.&lt;/p&gt;  &lt;p&gt;I know it is hard in an job interview to remember all those things. And I really don't have answers for all problems, most of the times we just can't propose an architecture whitout digging deeper in the details, in the business requirements and having lots of discussions with peers and even business team.   &lt;br /&gt;But as developers and architects we can't be relying on specific products, we need to be able to understand architecture as a whole and what are the options we have to better propose a scalable architecture and build a solid system.&lt;/p&gt;  &lt;p&gt;Here a few basic references about all this stuff.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://java.sun.com/reference/blueprints/"&gt;Java BluePrints&lt;/a&gt; - Here some good stuff for JAva Enterprise Applications.    &lt;br /&gt;&lt;a href="http://java.sun.com/blueprints/patterns/"&gt;Java EE Design Patterns&lt;/a&gt;: Core J2EE patterns are here also    &lt;br /&gt;&lt;a href="http://books.google.com.br/books?id=FyWZt5DdvFkC&amp;amp;dq=patterns+of+enterprise+application+architecture&amp;amp;pg=PP1&amp;amp;ots=eExq0zXq9w&amp;amp;sig=6Uea3vkl8wUS2FhivHiMk-XST6I&amp;amp;hl=pt-BR&amp;amp;prev=http://www.google.com.br/search%3Fhl%3Dpt-BR%26q%3Dpatterns%2Bof%2Benterprise%2Bapplication%2Barchitecture%26btnG%3DPesquisar&amp;amp;sa=X&amp;amp;oi=print&amp;amp;ct=title&amp;amp;cad=one-book-with-thumbnail"&gt;Patterns of Enterprise Application Architecture&lt;/a&gt;, from Martin Fowler.    &lt;br /&gt;&lt;a href="http://www.oreilly.com/catalog/9780596007126/"&gt;Head First Design Patterns&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There are lots of other good books and articles. Please, feel free to comment here adding more references.   &lt;br /&gt;Also, what do you think would be the basic understanding developers should have nowadays? Any other specific skill?&lt;/p&gt;  &lt;p&gt;&lt;em&gt;By Giovani Salvador&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2667021484906906806?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2667021484906906806/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2667021484906906806" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2667021484906906806?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2667021484906906806?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/05/java-architectural-knowledge-for-job.html" title="Java Architectural Knowledge for Job Interviews. Are we prepared?" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DE8ER3w8fyp7ImA9WxdSF08.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-7821513169911135045</id><published>2008-05-25T07:46:00.001-07:00</published><updated>2008-05-25T07:46:46.277-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-25T07:46:46.277-07:00</app:edited><title>Layout management, how simple can it be?</title><content type="html">&lt;p&gt;Trying to teach Java to a 14 year old, and after working on some problems such as: Solving a quadratric equation, checking if a number is prime, we have so far changed the data inside the program, recompiled it and ran again....   &lt;br /&gt;We are reaching the point where we want to be able to enter the data in a fashionable way! Meaning time to address the &amp;quot;GUI&amp;quot; problem. While it is straightforward to create a frame and add components to it, it is tricky to layout the components inside the frame.    &lt;br /&gt;Here are some examples using the layout manager as little as possible (I am keeping this subject for way later...).    &lt;br /&gt;In the first example, we simply add some components to the panel used by the frame (FlowLayout is used by default)    &lt;br /&gt;In the second example, we use the GridLayout class to order the components.     &lt;br /&gt;In the third example, the components in a row are first added to a panel which is then added to the overall panel.&lt;/p&gt;  &lt;pre&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class Test {&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    JFrame frame = new JFrame();&lt;br /&gt;&lt;br /&gt;    JPanel panel = new JPanel();&lt;br /&gt;&lt;br /&gt;    JLabel l = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f = new JTextField(10);&lt;br /&gt;    JButton b = new JButton(&amp;quot;Calc&amp;quot;);&lt;br /&gt;&lt;br /&gt;    panel.add(l);&lt;br /&gt;    panel.add(f);&lt;br /&gt;    panel.add(b);&lt;br /&gt;&lt;br /&gt;    frame.getContentPane().add(panel);&lt;br /&gt;&lt;br /&gt;    frame.setSize(300, 300);&lt;br /&gt;    frame.setVisible(true);&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class Test2 {&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    JFrame frame = new JFrame();&lt;br /&gt;&lt;br /&gt;    JPanel panel = new JPanel();&lt;br /&gt;    panel.setLayout(new GridLayout(4,2));&lt;br /&gt;&lt;br /&gt;    JLabel l1 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f1 = new JTextField(10);&lt;br /&gt;    panel.add(l1);&lt;br /&gt;    panel.add(f1);&lt;br /&gt;&lt;br /&gt;    JLabel l2 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f2 = new JTextField(10);&lt;br /&gt;    panel.add(l2);&lt;br /&gt;    panel.add(f2);&lt;br /&gt;&lt;br /&gt;    JLabel l3 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f3 = new JTextField(10);&lt;br /&gt;    panel.add(l3);&lt;br /&gt;    panel.add(f3);&lt;br /&gt;&lt;br /&gt;    JButton b = new JButton(&amp;quot;Calc&amp;quot;);&lt;br /&gt;    panel.add(b);&lt;br /&gt;&lt;br /&gt;    frame.getContentPane().add(panel);&lt;br /&gt;&lt;br /&gt;    frame.setSize(300, 300);&lt;br /&gt;    frame.setVisible(true);&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class Test3 {&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    JFrame frame = new JFrame();&lt;br /&gt;&lt;br /&gt;    JPanel panel = new JPanel();&lt;br /&gt;    panel.setLayout(new GridLayout(4,1));&lt;br /&gt;&lt;br /&gt;    JLabel l1 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f1 = new JTextField(10);&lt;br /&gt;    JPanel panel1 = new JPanel();&lt;br /&gt;    panel1.add(l1);&lt;br /&gt;    panel1.add(f1);&lt;br /&gt;    panel.add(panel1);&lt;br /&gt;&lt;br /&gt;    JLabel l2 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f2 = new JTextField(10);&lt;br /&gt;    JPanel panel2 = new JPanel();&lt;br /&gt;    panel2.add(l2);&lt;br /&gt;    panel2.add(f2);&lt;br /&gt;    panel.add(panel2);&lt;br /&gt;&lt;br /&gt;    JLabel l3 = new JLabel(&amp;quot;label:&amp;quot;);&lt;br /&gt;    JTextField f3 = new JTextField(10);&lt;br /&gt;    JPanel panel3 = new JPanel();&lt;br /&gt;    panel3.add(l3);&lt;br /&gt;    panel3.add(f3);&lt;br /&gt;    panel.add(panel3);&lt;br /&gt;&lt;br /&gt;    JButton b = new JButton(&amp;quot;Calc&amp;quot;);&lt;br /&gt;    JPanel panel4 = new JPanel();&lt;br /&gt;    panel4.add(b);&lt;br /&gt;    panel.add(panel4);&lt;br /&gt;&lt;br /&gt;    frame.getContentPane().add(panel);&lt;br /&gt;&lt;br /&gt;    frame.setSize(300, 300);&lt;br /&gt;    frame.setVisible(true);&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;em&gt;by Pascal Ledru&lt;/em&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-7821513169911135045?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/7821513169911135045/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=7821513169911135045" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7821513169911135045?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7821513169911135045?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/05/layout-management-how-simple-can-it-be.html" title="Layout management, how simple can it be?" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEIGQnc6fip7ImA9WxdSF08.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-5907532563937105263</id><published>2008-05-25T07:42:00.001-07:00</published><updated>2008-05-25T07:42:03.916-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-25T07:42:03.916-07:00</app:edited><title>Lessons Learned From Spring’s @Autowired</title><content type="html">&lt;p&gt;Last &lt;a href="http://blog.rainer.eschen.name/2007/11/27/spring-25-its-time-for-annotation-driven-injection/"&gt;November&lt;/a&gt; we got &lt;a href="http://blog.rainer.eschen.name/tag/spring/"&gt;Spring&lt;/a&gt; 2.5 and with it the possibility to use annotations for &lt;a href="http://blog.rainer.eschen.name/tag/dependency-injection/"&gt;dependency injection&lt;/a&gt; (DI). Annotations can be used instead or mixed with the classic &lt;a href="http://blog.rainer.eschen.name/tag/application-context/"&gt;application context&lt;/a&gt; file(s) based on XML.&lt;/p&gt;  &lt;p&gt;If you compare the former more complex XML configurations with what you still have to keep, after using annotations, it&amp;#8217;s quite amazing how straightforward the XML becomes. For projects with complex DI configurations it is possible to transfer the configuration in steps. &lt;/p&gt;  &lt;p&gt;For our ICEfaces Web application e.g. we started with something like this:&lt;/p&gt;  &lt;pre&gt;&amp;lt;bean id=&amp;quot;businessObject&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BusinessObject&amp;quot;&lt;br /&gt;    scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;    &amp;lt;property name=&amp;quot;simpleProperty&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;value&amp;gt;Hello World&amp;lt;/value&amp;gt;&lt;br /&gt;    &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id=&amp;quot;businessObjectAdministration&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BusinessObjectAdministration&amp;quot;&lt;br /&gt;    scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;    &amp;lt;property name=&amp;quot;simpleProperty&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;value&amp;gt;Hello Administrators&amp;lt;/value&amp;gt;&lt;br /&gt;    &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id=&amp;quot;backingBean&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BackingBean&amp;quot; scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;        &amp;lt;property name=&amp;quot;businessObject&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ref bean=&amp;quot;businessObject&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id=&amp;quot;backingBeanAdministration&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BackingBeanAdministration&amp;quot;&lt;br /&gt;    scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;        &amp;lt;property name=&amp;quot;businessObjectAdministration&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;ref bean=&amp;quot;businessObjectAdministration&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is pretty verbose. The references can also be written in compact syntax, like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;property name=&amp;quot;businessObject&amp;quot; ref=&amp;quot;businessObject&amp;quot; /&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here are the corresponding classes:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;package com.test;&lt;br /&gt;public class BusinessObject {&lt;br /&gt;&lt;br /&gt;    String simpleProperty;&lt;br /&gt;&lt;br /&gt;    public void setSimpleProperty(String simpleProperty) {&lt;br /&gt;        this.simpleProperty = simpleProperty;&lt;br /&gt;    }&lt;br /&gt;    public String getSimpleProperty() {&lt;br /&gt;        return this.simpleProperty;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;package com.test;&lt;br /&gt;public class BusinessObjectAdministration extends&lt;br /&gt;    BusinessObject {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;package com.test;&lt;br /&gt;public class BackingBean {&lt;br /&gt;&lt;br /&gt;    BusinessObject businessObject;&lt;br /&gt;&lt;br /&gt;    public void setBusinessObject(BusinessObject businessObject) {&lt;br /&gt;        this.businessObject = businessObject;&lt;br /&gt;    }&lt;br /&gt;    public String getBusinessObject() {&lt;br /&gt;        return this.businessObject;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;package com.test;&lt;br /&gt;public class BackingBeanAdministration {&lt;br /&gt;&lt;br /&gt;    BusinessObjectAdministration businessObjectAdministration;&lt;br /&gt;&lt;br /&gt;    public void setBusinessObjectAdministration(&lt;br /&gt;        BusinessObjectAdministration businessObjectAdministration) {&lt;br /&gt;        this.businessObjectAdministration = businessObjectAdministration;&lt;br /&gt;    }&lt;br /&gt;    public String getBusinessObjectAdministration() {&lt;br /&gt;        return this.businessObjectAdministration;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Each backing bean in this example uses a corresponding business object, whereas &lt;code&gt;BusinessObjectAdministration&lt;/code&gt; is a child of &lt;code&gt;BusinessObject&lt;/code&gt;.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;Adding Annotations&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So, what do we have to change to get this &lt;a href="http://blog.rainer.eschen.name/tag/annotation/"&gt;annotation&lt;/a&gt; stuff working? The reference attributes in the backing beans get an &lt;code&gt;@Autowired&lt;/code&gt;. With this a corresponding &lt;a href="http://blog.rainer.eschen.name/tag/spring/"&gt;Spring&lt;/a&gt; bean with the same type is searched during the &lt;a href="http://blog.rainer.eschen.name/tag/dependency-injection/"&gt;dependency injection&lt;/a&gt;. Additionally, we can skip getter and setter for the reference attributes.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class BackingBean {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    BusinessObject businessObject;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class BackingBeanAdministration {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    BusinessObjectAdministration businessObjectAdministration;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;With this we can also skip the corresponding properties in the &lt;a href="http://blog.rainer.eschen.name/tag/application-context/"&gt;application context&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;bean id=&amp;quot;backingBean&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BackingBean&amp;quot; scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id=&amp;quot;backingBeanAdministration&amp;quot;&lt;br /&gt;    class=&amp;quot;com.test.BackingBeanAdministration&amp;quot;&lt;br /&gt;    scope=&amp;quot;session&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;aop :scoped-proxy/&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Pretty simple. But, when you deploy this you get an exception. &lt;a href="http://blog.rainer.eschen.name/tag/spring/"&gt;Spring&lt;/a&gt; will tell you that it has problems to inject the &lt;code&gt;businessObject&lt;/code&gt; reference into &lt;code&gt;backingBean.BusinessObject&lt;/code&gt;, because there are &lt;em&gt;two&lt;/em&gt; matches. We&amp;#8217;ve an &lt;a href="http://blog.rainer.eschen.name/tag/inheritance/"&gt;inheritance&lt;/a&gt; between &lt;code&gt;BusinessObject&lt;/code&gt; and &lt;code&gt;BusinessObjectAdministration&lt;/code&gt;. So, both are matched in this case.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Matching via type is not the best solution here. But, there&amp;#8217;s another &lt;a href="http://blog.rainer.eschen.name/tag/annotation/"&gt;annotation&lt;/a&gt; that allows to name the &lt;a href="http://blog.rainer.eschen.name/tag/spring/"&gt;Spring&lt;/a&gt; bean we wanna be used during the &lt;a href="http://blog.rainer.eschen.name/tag/dependency-injection/"&gt;dependency injection&lt;/a&gt;, called &lt;code&gt;@Qualifier&lt;/code&gt;. It has a parameter, that allows to set the bean&amp;#8217;s name.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When we add this to the backing beans everything works fine.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class BackingBean {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    @Qualifier(&amp;quot;businessObject&amp;quot;)&lt;br /&gt;    BusinessObject businessObject;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class BackingBeanAdministration {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    @Qualifier(&amp;quot;businessObjectAdministration&amp;quot;)&lt;br /&gt;    BusinessObjectAdministration businessObjectAdministration;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-5907532563937105263?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/5907532563937105263/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=5907532563937105263" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5907532563937105263?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5907532563937105263?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/05/lessons-learned-from-springs-autowired.html" title="Lessons Learned From Spring’s @Autowired" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMFSHs_fip7ImA9WxZWEUU.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-5842547837421798683</id><published>2008-03-10T15:00:00.001-07:00</published><updated>2008-03-10T15:00:19.546-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-10T15:00:19.546-07:00</app:edited><title>Hibernate annotation for a Map of some enum type to some primitive type</title><content type="html">&lt;p&gt;&lt;a href="http://annotations.hibernate.org/"&gt;Hibernate Annotations&lt;/a&gt; are so great, especially together with the &lt;a href="http://tools.hibernate.org/"&gt;Hibernate Tools&lt;/a&gt; that allows to generate the whole database (sql table definitions) from your annotated beans.&lt;/p&gt;  &lt;p&gt;Right now I mapped the first time a &lt;code&gt;java.util.Map&lt;/code&gt; with some &lt;code&gt;enum&lt;/code&gt; type as key and a primitive type as value (&lt;code&gt;java.lang.String&lt;/code&gt;).&lt;/p&gt;  &lt;p&gt;The mapping looks like the following:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;&lt;br /&gt;    @CollectionOfElements&lt;br /&gt;    @JoinTable( name=&amp;quot;my_table&amp;quot; )&lt;br /&gt;    @Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)&lt;br /&gt;    @Enumerated(value=EnumType.STRING)&lt;br /&gt;    @org.hibernate.annotations.MapKey( columns = { @Column( name=&amp;quot;my_enum&amp;quot; ) } )&lt;br /&gt;    @Column( name=&amp;quot;my_value&amp;quot;, length=4000 )&lt;br /&gt;    public Map&amp;lt;MyEnumType, String&amp;gt; getMappedValues() {&lt;br /&gt;        return _mappedValues;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;What I was not able to do was to define the type of the value (String) as hibernate type &lt;code&gt;text&lt;/code&gt;. This gave the correct table/column definition at build time (hibernate tools), but a &lt;code&gt;ClassCastException&lt;/code&gt; at runtime, saying that &lt;code&gt;MyEnumType&lt;/code&gt; is not compatible to hibernate&amp;#8217;s type &lt;code&gt;text&lt;/code&gt;. So I used the &lt;code&gt;length&lt;/code&gt; of the &lt;code&gt;@Column&lt;/code&gt; annotation as a temporary workaround - I&amp;#8217;ll dig into this now or later - or has anybody a clue how to do this? &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-5842547837421798683?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/5842547837421798683/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=5842547837421798683" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5842547837421798683?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5842547837421798683?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/03/hibernate-annotation-for-map-of-some.html" title="Hibernate annotation for a Map of some enum type to some primitive type" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DEQFQn45fyp7ImA9WxZWEUU.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-1238652307262389089</id><published>2008-03-09T13:43:00.001-07:00</published><updated>2008-03-10T14:58:33.027-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-10T14:58:33.027-07:00</app:edited><title>Using Dynamic Method Invocation to "Script" Java</title><content type="html">&lt;p&gt;Although Java isn't thought of as a dynamic language now a days, what with Ruby and Groovy being all the rage, Java does have support for dynamic features. (See my &lt;a href="http://www.vitarara.org/cms/whats_wrong_with_javas_dynamic_dispatch_and_how_to_fix_it"&gt;previous blog post&lt;/a&gt; on the subject and the solution I came up with.)&lt;/p&gt;  &lt;h4&gt;A Use Case for Dynamic Java&lt;/h4&gt;  &lt;p&gt;Currently I'm wrapping about a hundred EJB 2.1 LocalHome classes in DAO's, and having them transform local EJB entities into POJO's. Much of the code is largely boiler plate. Actually it's mind numbingly boiler plate. Here's a sample of wrapping a finder:&lt;/p&gt;  &lt;pre&gt;public Endowment findById ( String id ) {&lt;br /&gt;	try {&lt;br /&gt;		// get the local home&lt;br /&gt;		EndowmentLocalHome endowmentLH = EndowmentUtil.getLocalHome ();&lt;br /&gt;		// lookup the entity&lt;br /&gt;		EndowmentLocal endowmentL = endowmentLH.findByPrimaryKey ( id );&lt;br /&gt;		// return the entity&lt;br /&gt;		return createEndowment ( endowmentL );&lt;br /&gt;	} catch ( Exception e ) { throw new VRRemoteException ( e ); }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So, five lines of code just to call a finder, then there's the createEndowment() method that actually does the transformation into a POJO. Additionally every method is cluttered with try {} catch {} constructs, further blurring the intent of the code.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;By using reflection and dynamic method calls I've been able to reduce the boilerplate to: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public Member findById ( String id ) {&lt;br /&gt;    return (Member) mixin.find (&amp;quot;findById&amp;quot;, new Object[] { id } );&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If by chance my finder returns a Collection, all I need to do is cast the result to Collection.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Each DAO is specific to a &amp;quot;type.&amp;quot; Not type as in a Class, but type as in a &amp;quot;business type,&amp;quot; ie the snipped deals with the &amp;quot;Endowment&amp;quot; type. For each type there are a number of EJB 2.1 and POJO classes collaborating to make the whole thing work. For the Endowment type the critical classes are:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;EndowmentUtil: A utility class for looking up local and remote home interfaces using JNDI. This utility class shields us complete from JNDI. :) This class is generated by XDoclet. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;EndowmentLocalHome: The local home for the Endowment EJB. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;EndomentLocal: A local EJB entity of an endowment. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;EndowmentValue: A value bean representing an endowment. This is generated by XDoclet. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;EndowmentDAO: An interface for a persistence agnostic data access object. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;EndowmementDAOEjbImpl: An implementation of EndowmentDAO that wraps the EJB 2.1 LocalHome. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Endowment: A POJO in a new clean package that has no connection to our old EJB 2.1/XDoclet code. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The other thing we're doing is making our POJO's transparently navigable, just like JPA entities are when they are managed by an EntityManager. (ie: We can do contactMechanism.getParty().getMember().)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The major issue is that I had repeating patterns like the findById() example above that are the same except that the &amp;quot;type&amp;quot; differed. The convention is the same, over and over. Reflection and my dynamic method calling to the rescue. (NB: This app needs to run on a Java 1.4 server, otherwise I'd have taken a look at generics to solve some of these issues.)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;The Solution&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Using the findById sample the pattern is easily identifyable:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public Endowment findById ( String id ) {&lt;br /&gt;	try {&lt;br /&gt;		// get the local home&lt;br /&gt;		EndowmentLocalHome endowmentLH = EndowmentUtil.getLocalHome ();&lt;br /&gt;		// lookup the entity&lt;br /&gt;		EndowmentLocal endowmentL = endowmentLH.findByPrimaryKey ( id );&lt;br /&gt;		// return the entity&lt;br /&gt;		return createEndowment ( endowmentL );&lt;br /&gt;	} catch ( Exception e ) { throw new VRRemoteException ( e ); }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Simplifying this to pseudo code can help in seeing the pattern:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public #TYPE# findById ( String id ) {&lt;br /&gt;	try {&lt;br /&gt;		// get the local home&lt;br /&gt;		#TYPE#LocalHome localHome = #TYPE#Util.getLocalHome ();&lt;br /&gt;		// lookup the entity&lt;br /&gt;		#TYPE#Local localEjb = localhome.findByPrimaryKey ( id );&lt;br /&gt;		// return the entity&lt;br /&gt;		return create#TYPE# ( localEjb );&lt;br /&gt;	} catch ( Exception e ) { throw new VRRemoteException ( e ); }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We can even simplify this further, because the pattern is really the same with any finder. Look up a #TYPE#Util, call getLocalHome() on it, getting a #TYPE#LocalHome, call the finder method and transform the result into a POJO.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public #TYPE# find (Object[] args ) {&lt;br /&gt;	try {&lt;br /&gt;		// get the local home&lt;br /&gt;		#TYPE#LocalHome localHome = #TYPE#Util.getLocalHome ();&lt;br /&gt;		// lookup the entity&lt;br /&gt;		#TYPE#Local localEjb = localhome.find ( args );&lt;br /&gt;		// return the entity&lt;br /&gt;		return create#TYPE# ( localEjb );&lt;br /&gt;	} catch ( Exception e ) { throw new VRRemoteException ( e ); }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We call some find method with some collection of arguments, represented by the Object[], which could also be absent for an no-argument finder.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;With the pattern identified let's &amp;quot;script&amp;quot; it using the dynamic method calling and the fact that the related class names all follow a convention.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here's the code that will call any finder using the pattern above:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public Object find (String finder, Object[] args) {&lt;br /&gt;	Object result = sendMessage (finder, getLocalHome(), args);&lt;br /&gt;	if (result instanceof Collection) {&lt;br /&gt;		try {&lt;br /&gt;			Collection originalResultList = (Collection) result;&lt;br /&gt;&lt;br /&gt;			// If the result is empty there is nothing to convert. Return the empty collection.&lt;br /&gt;			if (originalResultList.size() == 0) {&lt;br /&gt;				return result;&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;			Collection resultList = new ArrayList ( originalResultList.size () );&lt;br /&gt;			for (Iterator itr = originalResultList.iterator (); itr.hasNext (); ) {&lt;br /&gt;				Object ejb = itr.next ();&lt;br /&gt;				resultList.add (createPojo (ejb) );&lt;br /&gt;			}&lt;br /&gt;			result = resultList;&lt;br /&gt;		} catch (Exception e) {&lt;br /&gt;			throw new VRUtilityException (&amp;quot;ERROR: Post-processing a collection into POJO's for type = '&amp;quot; + getType() + &amp;quot;'.&amp;quot;, e);&lt;br /&gt;		}	&lt;br /&gt;	} else {&lt;br /&gt;		// Build a POJO from the EJB entity returned by the finder.&lt;br /&gt;		return createPojo (result);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	return result;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Most of the code in the method is involved with transforming Collection results into POJO's.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To access the findById method I'd do: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;return (TYPE) find (&amp;quot;findById&amp;quot;, new Object[] { id } )&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Getting the LocalHome interface is done by convention:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;/** Get the local home appropriate to this mixin. */&lt;br /&gt;protected Object getLocalHome () {&lt;br /&gt;	// Determine utility class name.&lt;br /&gt;	Class utilClass = findClass (getType() + &amp;quot;Util&amp;quot;);&lt;br /&gt;	if (utilClass == null) {&lt;br /&gt;		throw new VRUtilityException (&amp;quot;ERROR: Could not look up utility class for type = '&amp;quot; + getType () + &amp;quot;' by convention.&amp;quot;);&lt;br /&gt;	}&lt;br /&gt;	try {&lt;br /&gt;	       return utilClass.getMethod (&amp;quot;getLocalHome&amp;quot;, null).invoke (null, null);&lt;br /&gt;	} catch (Exception e) {&lt;br /&gt;		throw new VRUtilityException (&amp;quot;ERROR: Could isntantiate local home for class of type = '&amp;quot; + getType () + &amp;quot;' by convention using Method object.&amp;quot;);&lt;br /&gt;	}&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Because I know my Util class is #TYPE#Util I can rely on that by convention to get my utility class and instantiate a LocalHome to be used. (In my case the findClass() method looks for the #TYPE#Util class in one of three packages by convention. I could have search the classpath, but that seemed like overkill under the circumstances, when I know it's in one of those three packages.)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Using the same recognition of patterns and convention allowed the replacement of boilerplate code in our persist method to.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Before: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public void persist ( Endowment endowment ) {&lt;br /&gt;	try {&lt;br /&gt;		// get the local home&lt;br /&gt;		EndowmentLocalHome endowmentLH = EndowmentUtil.getLocalHome ();&lt;br /&gt;		// create the entity&lt;br /&gt;		EndowmentLocal endowmentL = endowmentLH.create ();&lt;br /&gt;		// ensure that the foreign keys are set&lt;br /&gt;		setForeignKeys ( endowment );&lt;br /&gt;		// populate the entity&lt;br /&gt;		endowmentL.setEndowmentValue ( endowment );&lt;br /&gt;		// update the ID&lt;br /&gt;		endowment.setId( endowmentL.getId() );&lt;br /&gt;	} catch ( Exception e ) { throw new VRRemoteException ( e ); }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public void persist ( Endowment endowment ) {&lt;br /&gt;	mixin.persist (endowment);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The reflection code that does it:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public void persist (Object bean) {&lt;br /&gt;&lt;br /&gt;	// Create an entity EJB bean using the localHome.&lt;br /&gt;	Object ejb = sendMessage (&amp;quot;create&amp;quot;, getLocalHome (), null);&lt;br /&gt;		&lt;br /&gt;	// Populate foreign ID's from associated POJO's.&lt;br /&gt;	setForeignKeys (bean);&lt;br /&gt;		&lt;br /&gt;	// Populate the entity.&lt;br /&gt;	setValueOnEjb (bean, ejb);&lt;br /&gt;		&lt;br /&gt;	// Get the id from the ejb.&lt;br /&gt;	String id = (String) sendMessage (&amp;quot;getId&amp;quot;, ejb, null);&lt;br /&gt;		&lt;br /&gt;	// Set the id on the bean (POJO).&lt;br /&gt;	sendMessage (&amp;quot;setId&amp;quot;, bean, new Object[] { id });&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The nice thing is I wrote the reflection version of the persist once and I can reuse it with one line of code. Bye bye boiler plate.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Conclusion&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you find yourself writing repetitive code, such as in my case when wrapping some API you want to abstract out, find the patterns and factor out that repetitive boilerplate code using reflection. You don't need to waste your life writing repetitive code.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-1238652307262389089?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/1238652307262389089/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=1238652307262389089" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/1238652307262389089?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/1238652307262389089?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/03/using-dynamic-method-invocation-to-java.html" title="Using Dynamic Method Invocation to &amp;quot;Script&amp;quot; Java" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUEFQ388eCp7ImA9WxZXFEQ.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-4858445598474343011</id><published>2008-03-02T13:32:00.001-08:00</published><updated>2008-03-02T13:33:32.170-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-02T13:33:32.170-08:00</app:edited><title>Groovy : Currying closures</title><content type="html">&lt;p&gt;This is just a quick Groovy feature that I think is cool.   &lt;br /&gt;For my reporting page, I want to produce a whole bunch of stats based on the duration of my trades. What is my average net, %age, and R gains for my winners and losers? Am I making more money per day with my winners than with my losers (ie: am I cutting the crap short and holding my winners)? Each calculation is essentially the same, just with some minor permutations. The basic structure will be:&lt;/p&gt;  &lt;pre&gt;for each trade in a list&lt;br /&gt; num days += trade.num days&lt;br /&gt; currVal += trade.currVal&lt;br /&gt;return currVal / num days&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The problem is that I need to do this calculation for all of my winners, losers and breakeven trades, and for each list, I need to do several different calculations. This is hardly intractable, it just makes a messy loop with lots of temp variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Groovy lets you do a couple cool things. First, you can define a closure which is sort of like an anonymous inner class in Java, except without the class. It's really just a method pointer. So we can start by defining a closure to calculate the average dollar value:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def avgDollar = {ts -&amp;gt; ts?.sum{it.net()} / (ts ? ts.sum{it.duration()} : 1) }&lt;/pre&gt;&lt;br /&gt;The notation ts?.sum is groovy's way of checking for nulls so instead of writing:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;double val = 0;&lt;br /&gt;if( ts != null ) {&lt;br /&gt;   val = ts.sum();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;you just say:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def val = ts?.sum()&lt;/pre&gt;&lt;br /&gt;Cool, no? Makes it easy to do the &amp;quot;right&amp;quot; thing and check for nulls without messing up your code. Anyway...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So now that we have our closure, we can say:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def avgDlrWins = avgDollar(winners)&lt;br /&gt;def avgDlrBE = avgDollar(breakEvens)&lt;br /&gt;def avgDlrLoss = avgDollar(losers)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's a step in the right direction, but now we have to do the same mess when we try to average R's and %ages. So now we step up our game and do some meta-programming, defining a closure to pass to our closure!&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def holdAvg = {clos, ts -&amp;gt; ts?.sum{clos.call(it)} / (ts ? ts?.sum{it.duration()} : 1) }&lt;/pre&gt;&lt;br /&gt;This closure takes two arguments, closure and a list of trades and sums the result of calling the closure and dividing that by the sum of the duration. That lets us create our sub closures as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;def avgDollar = holdAvg.curry({it.net()})&lt;br /&gt;def avgR = holdAvg.curry({it.r()})&lt;br /&gt;def avgPerc = holdAvg.curry({it.percent()})&lt;/pre&gt;&lt;br /&gt;The method &amp;quot;curry&amp;quot; binds the first argument of the holdAvg closure to the argument we pass in (in this case another closure). That means that the avgDollar() closure we just define is fully equivalent to the first one, only now we can quickly rattle off the avgR and avgPercent closure. Now that's code re-use!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you haven't used closures before, this is probably a bit weird-looking and when I first &lt;a href="http://www-128.ibm.com/developerworks/library/j-pg08235/"&gt;read about curried closures&lt;/a&gt;, I couldn't see how they'd be used, but it's surprising how often they pop up when you know that the feature exists.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Good coding!  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-4858445598474343011?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/4858445598474343011/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=4858445598474343011" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4858445598474343011?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4858445598474343011?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2008/03/groovy-currying-closures.html" title="Groovy : Currying closures" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DU4NQX4_fSp7ImA9WB9WGE8.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-4050682499605902000</id><published>2007-11-12T13:56:00.000-08:00</published><updated>2007-11-23T06:26:30.045-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-23T06:26:30.045-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><title>A new approach to the equals() method!</title><content type="html">Custom equals() methods are handy but involve writing a lot of ugly boilerplate code — and there are booby-traps for the unwary. In this post, I present a way of over-riding equals() and hashCode() methods — based on annotations — which makes them a doddle to implement and maintain. The resulting code is available for download in a shrink-wrapped jar.&lt;br /&gt;&lt;br /&gt;To recap, a == b tests whether a and b are the same object. a.equals(b) tests whether they are equivalent objects. equals() is a very useful method, and you will no doubt have found yourself over-riding the default version in several of your classes.&lt;br /&gt;&lt;br /&gt;Over-riding equals() is not quite as straightforward as it seems. You must also override hashcode() in an equivalent manner. Otherwise HashSet, HashMap and HashTable will exhibit strange bugs. I’ve made this mistake and it’s confusing as hell to debug. Josh Bloch’s Effective Java provides more examples of how equals can go wrong.&lt;br /&gt;&lt;br /&gt;Also equals() and hashCode() methods contain a lot of boilerplate. Here’s an example of equals() for a class — and this is for a simple class with only 2 fields:&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;public boolean equals(Object obj) {&lt;br /&gt;       if (this == obj)&lt;br /&gt;           return true;&lt;br /&gt;       if (obj == null)&lt;br /&gt;           return false;&lt;br /&gt;       if (getClass() != obj.getClass())&lt;br /&gt;           return false;&lt;br /&gt;       final ToyStoryState other = (ToyStoryState) obj;&lt;br /&gt;       if (leftBank == null) {&lt;br /&gt;           if (other.leftBank != null)&lt;br /&gt;               return false;&lt;br /&gt;       } else if (!leftBank.equals(other.leftBank))&lt;br /&gt;           return false;&lt;br /&gt;       if (torch == null) {&lt;br /&gt;           if (other.torch != null)&lt;br /&gt;               return false;&lt;br /&gt;       } else if (!torch.equals(other.torch))&lt;br /&gt;           return false;&lt;br /&gt;       return true;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Yuck!&lt;br /&gt;Annotations to the rescue!&lt;br /&gt;&lt;br /&gt;There is a nice solution to this issue using annotations. We’ll start with an example, then look behind the scenes at how it works.&lt;br /&gt;&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;class MyObject {&lt;br /&gt;&lt;br /&gt;   @Equals&lt;br /&gt;   public String name;&lt;br /&gt;&lt;br /&gt;   private int id;&lt;br /&gt;&lt;br /&gt;   @Equals&lt;br /&gt;   public int getId() {&lt;br /&gt;       return id;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public boolean equals(Object obj) {&lt;br /&gt;       return Equality.equalsByAnnotation(MyObject.class, this, obj);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public int hashCode() {&lt;br /&gt;       return Equality.hashCodeByAnnotation(MyObject.class, this);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;With the example above, two MyObjects are considered equal if they have the same name and id — as returned by getId(). Equals is our custom annotation, and Equality is a support class with static methods…&lt;br /&gt;&lt;h4&gt;Making it work&lt;/h4&gt;&lt;br /&gt;We need to know which properties are important for equality. Properties can be fields or zero-argument methods, such as getters. This can be specified in a natural way by annotating fields and methods. First we define an annotation for properties that should be tested: @Equals indicates a property that should be compared using equals(). Defining an annotation is similar to defining an interface, except you use the keyword @interface, and you’ll usually want to add some meta-annotations.&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;@Retention(RetentionPolicy.RUNTIME) // Meta-annotation for "Don't throw this away during compilation"&lt;br /&gt;@Target( { ElementType.FIELD, ElementType.METHOD }) // Meta-annotation for "Only allowed on fields and methods"&lt;br /&gt;public @interface Equals {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we can annotate properties like in the example — how do we test them? We need to make use of the reflection api. Given a Class object, we can get it’s Field and Method objects via Class.getDeclaredFields/Methods(). Given those, we test for the presence of annotations using Field/Method.isAnnotationPresent(). We use a little known Java feature to get access to non-public fields — see this post for details. I put the code for all this is in a class Equality under the static methods equalsByAnnotation() and hashCodeByAnnotation() — you can download it below.&lt;br /&gt;&lt;h4&gt;Checking the superclass&lt;/h4&gt;&lt;br /&gt;Note that the equalsByAnnotation() method does not look at properties belonging to ancestor classes. Similarly, hashcodeByAnnotation() does not incorporate properties belonging to ancestor classes. If this is necessary, the user must call super.equals() and super.hashcode(). E.g. like this:&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;if ( ! super.equals(obj)) return false;&lt;br /&gt;return equalsByAnnotation(MyObject.class, this, obj);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;return 17*super.hashcode() + hashcodeByAnnotation(this);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is a deliberate design decision. If the parent class has over-ridden equals(), then it’s method (which may or may not use annotations) must be checked. I’ve left this as the user’s responsibility - partly so they keep control, partly because the code to check for an ancestor equals method would have been ugly. If you think it should be handled automatically, feel free to send me your code suggestions…&lt;br /&gt;&lt;h4&gt;Advantages&lt;/h4&gt;&lt;br /&gt;Shorter code, cleaner code, God kills less kittens, etc. Having @Equals attached to fields and methods makes it clear what is and isn’t being tested. This helps in maintaining correct behaviour when the class is edited. And it isn’t restrictive — you can still write your own custom code if you need to.&lt;br /&gt;&lt;h4&gt;The Disadvantage: Speed&lt;/h4&gt;&lt;br /&gt;So the code is a lot nicer — but naturally you lose a bit of speed. I did some time trials, and the annotations based method came out as 3x slower. That’s fine during development and if equals() / hashCode() are not bottlenecks. Note that equals() and hashCode() can be bottlenecks — e.g. when making intensive use of Maps. So you may not want to use this in some production systems.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-4050682499605902000?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/4050682499605902000/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=4050682499605902000" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4050682499605902000?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4050682499605902000?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/new-approach-to-equals-method.html" title="A new approach to the equals() method!" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A08GQnk8fip7ImA9WB9XF0Q.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-9054872113054896573</id><published>2007-11-09T13:23:00.001-08:00</published><updated>2007-11-11T08:50:23.776-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-11T08:50:23.776-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="itext" /><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="pdf" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><title>Creating PDF Documents Dynamically in J2EE, Java Applications</title><content type="html">&lt;span style="font-weight: bold;"&gt;Background:&lt;/span&gt;&lt;br&gt;In today's enterprise applications their is a big requirement for dynamic generation of PDF documents. These applications range from telecom companies generating phone bills, airlines producing e-tickets, banks generating customer statements for e-mail delivery to readers, book sellers selling books in pdf format.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;What is PDF:&lt;/span&gt;&lt;br&gt;The Portable Document Format (PDF) is the file format created by Adobe Systems in 1993 for document exchange. PDF is used for representing two-dimensional documents in a device-independent and display resolution-independent fixed-layout document format. Each PDF file encapsulates a complete description of a 2-D document (and, with Acrobat 3-D, embedded 3-D documents) that includes the text, fonts, images, and 2-D vector graphics that compose the document.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Why PDF: &lt;/span&gt;&lt;br&gt;PDF is an open standard, unlike Microsoft Word, supported by all operating systems, ie; as long as you have an adobe reader you can read a pdf file on any system like Linux, Mac, Solaris, Windows. On virus front, it’s very hard that a PDF file will have some virus. It is is now being prepared for submission as an ISO standard.&lt;br&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_b6Hez4oFqv0/RywaUXX_GiI/AAAAAAAAAm0/H9sVCrn53J0/s1600-h/pdfImage.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_b6Hez4oFqv0/RywaUXX_GiI/AAAAAAAAAm0/H9sVCrn53J0/s200/pdfImage.jpg" alt="" id="Pdf, Documents, Java, Create, Dynamic, J2EE, Development, Microsoft Word, Convert" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Dynamic PDF Generation in Enterprise Application Development :&lt;/span&gt;&lt;br&gt;As mentioned above, in digital age everything is digitized so that end user can access it from anywhere, anytime.  As a result new enterprise applications are generating lot of data in pdf formant which can be used by end user.&lt;br&gt;In Enterprise (Java or J2EE, JEE) application development generating pdf documents on the fly (dynamically)  has become a trivial thing, courtesy of lot of third party tools, APIs available. The list of these tools/API's is endless. In this article, we will use the iText Java library to generate PDF documents by merging GIF files. I'll go through an example to show how this is done.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;iText&lt;/span&gt; :&lt;br&gt;&lt;a href="http://www.lowagie.com/"&gt;iText&lt;/a&gt; is an open-source Java library that provides API to generate PDF files on the fly. It also  supports the generation of HTML, RTF, and XML documents, in addition to generating PDFs. It's available for free under a multiple license: MPL and LGPL.&lt;br&gt;&lt;/p&gt;&lt;p style="font-weight: bold;"&gt;&lt;a name="api"&gt;&lt;span class="atitle"&gt;iText API :&lt;br&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;The com.lowagie.text.Document is the main class for PDF document generation. This is the first class to be instantiated. Once the document is created, we would require a writer to write into it. The com.lowagie.text.pdf.PdfWriter is a PDF writer.  Other classes which are often used:&lt;/p&gt;    &lt;ul&gt;&lt;li&gt;&lt;b&gt;com.lowagie.text.Paragraph&lt;/b&gt; - represents an indented paragraph.&lt;/li&gt;&lt;li&gt;&lt;b&gt;com.lowagie.text.Chapter&lt;/b&gt; - represents a chapter in the PDF document. It is created using a &lt;code&gt;Paragraph&lt;/code&gt; as title and an &lt;code&gt;int&lt;/code&gt; as chapter number.&lt;/li&gt;&lt;li&gt;&lt;b&gt;com.lowagie.text.Font&lt;/b&gt; - contains all specifications of a font, such as family of font, size, style, and color. Various fonts are declared as static constants in this class.&lt;/li&gt;&lt;li&gt;&lt;b&gt;com.lowagie.text.List&lt;/b&gt; - represents a list, which, in turn, contains a number of &lt;code&gt;ListItems&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;&lt;b&gt;com.lowagie.text.Table&lt;/b&gt; - represents a table that contains cells, ordered in a matrix.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;&lt;br&gt;Example of converting multiple GIF files into PDF :&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Pre-requisites :&lt;/span&gt;&lt;br&gt;Download iText and include &lt;span style="font-weight: bold;"&gt;itext-version.jar&lt;/span&gt; into your application or yr classpath.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Code Snippet :&lt;/span&gt;&lt;br&gt;The following code snippet demonstrates how to convert an array (collection) of  gif files into a single pdf,&lt;br&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;br /&gt;FileOutputStream fos = null;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;&lt;br /&gt; fos = new FileOutputStream (new File(pDestinationFolder + File.separator + pTargetFileNamePrefix + ".pdf"));&lt;br /&gt;&lt;br /&gt; /* Create a document which is the container for all the elements of a PDF document.*/&lt;br /&gt; Document doc = new Document();&lt;br /&gt;&lt;br /&gt; /* Line -1 */&lt;br /&gt; PdfWriter writer = PdfWriter.getInstance(doc, fos);&lt;br /&gt; &lt;br /&gt; doc.open();&lt;br /&gt; &lt;br /&gt; for (File aFile : gifFiles)  {&lt;br /&gt; &lt;br /&gt;  Image image = Image.getInstance(aFile.getAbsolutePath());&lt;br /&gt;  &lt;br /&gt;  /* Line -2 */&lt;br /&gt;  image.scaleToFit(doc.getPageSize().getWidth(), doc.getPageSize().getHeight());&lt;br /&gt;  &lt;br /&gt;  /* Line -3 */&lt;br /&gt;  image.setAlignment(Image.ALIGN_CENTER);&lt;br /&gt;  doc.add(image);&lt;br /&gt;  doc.newPage();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; doc.close();&lt;br /&gt;}&lt;br /&gt;catch (Exception ex) {&lt;br /&gt; ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;finally {&lt;br /&gt; &lt;br /&gt;  if (fos != null)  {&lt;br /&gt;  try  {&lt;br /&gt;   fos.close();&lt;br /&gt;  }&lt;br /&gt;  catch (Exception ex)  {&lt;br /&gt;   ex.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Code Demystified :&lt;/span&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Line - 1 is important to create an instance of &lt;span style="font-weight: bold;"&gt;PdfWriter&lt;/span&gt; that associates a document object with the output stream. For our code snippet, we choose com.lowagie.text.pdf.PdfWriter. Other writers are HtmlWriter, RtfWriter, XmlWriter, and several others for obvious reasons.&lt;/li&gt;&lt;li&gt;Line - 2 is very useful methods that will scale the current image to fit the width and height specified. Gif images can vary in sizes and this allows the method to scale down to the default size of the PDF page.&lt;/li&gt;&lt;li&gt;Line-3 is to align the image so that it is located at the center of the page.&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;Other opensource libraries for generating pdf documents are :&lt;br&gt;&lt;ul&gt;&lt;li&gt;FOP&lt;/li&gt;&lt;li&gt;Gnujpdf&lt;/li&gt;&lt;li&gt;JFreeReport&lt;/li&gt;&lt;li&gt;JPedal&lt;/li&gt;&lt;li&gt;jPod&lt;/li&gt;&lt;li&gt;PDF Box&lt;/li&gt;&lt;li&gt;PDFjet&lt;/li&gt;&lt;li&gt;PJX&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-9054872113054896573?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/9054872113054896573/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=9054872113054896573" title="19 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/9054872113054896573?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/9054872113054896573?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/creating-pdf-documents-dynamically-in.html" title="Creating PDF Documents Dynamically in J2EE, Java Applications" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_b6Hez4oFqv0/RywaUXX_GiI/AAAAAAAAAm0/H9sVCrn53J0/s72-c/pdfImage.jpg" height="72" width="72" /><thr:total>19</thr:total></entry><entry gd:etag="W/&quot;CEcMQ347cCp7ImA9WB9WFU0.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-8665503032880995185</id><published>2007-11-08T12:40:00.000-08:00</published><updated>2007-11-19T11:54:42.008-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-19T11:54:42.008-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><title>Serialization in Java/J2EE - Demystified</title><content type="html">&lt;span style="font-weight: bold;"&gt;Serialization:&lt;/span&gt;&lt;br&gt;&lt;br&gt;Serialization is the process of persisting the state of an object.&lt;br&gt;In Java serializing an object involves encoding its state in a structured way within a byte array. Once an object is serialized, the byte array can be manipulated in various ways; it can be written to a file, sent over a network or RMI, or persisted within a database as a BLOB.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_b6Hez4oFqv0/RwocfsO9zjI/AAAAAAAAAkA/EmNyQNT0VqI/s1600-h/Serialization.htm"&gt;&lt;br /&gt;&lt;img src="http://4.bp.blogspot.com/_b6Hez4oFqv0/RwocfsO9zjI/AAAAAAAAAkA/EmNyQNT0VqI/s400/Serialization.htm" alt="Java, Programming, J2EE, Framework, Development, Serialization" id="BLOGGER_PHOTO_ID_5118935257235443250" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;The serialization process encodes enough information about the object type within the byte stream, allowing the original object to be easily recreated upon deserialization, at a later point in time.&lt;br&gt;&lt;span style="font-style: italic;"&gt;Serialization and Deserialization is same as marshaling and unmarshaling in C/C++.&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Where to keep serialized object&lt;/span&gt;:&lt;br&gt;&lt;br&gt;Serialization is a highly versatile mechanism it should be addressed by storing the state in relational or object databases. It does not have transaction management and concurrency control. Nor does it provide any typical database features like indexed access, caching and a query language.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Serializing static variables:  &lt;/span&gt;&lt;br&gt;&lt;br&gt;Variables declared as static members are not considered part of the state of an object because they are shared by all instances of that class. &lt;span style="font-weight: bold;"&gt;Classes which need to preserve the value of static members during serialization should save and restore these values explicitly using private void readObject(ObjectInputStream) and private void writeObject(ObjectOutputStream).&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Advantages and Disadvantages:&lt;br&gt;&lt;br&gt;&lt;/span&gt;The advantages of serialization are:&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It is easy to use and can be customized. &lt;/li&gt;&lt;li&gt;The serialized stream can be encrypted, authenticated and compressed, supporting the needs of secure Java computing. &lt;/li&gt;&lt;li&gt;Serialized classes can support coherent versioning and are flexible enough to allow gradual evolution of your application's object schema. &lt;/li&gt;&lt;li&gt;Serialization can also be used as a mechanism for exchanging objects between Java and C++ libraries, using third party vendor libraries within C++. &lt;/li&gt;&lt;li&gt;Many vital technologies that rely upon serialization, including RMI, JavaBeans and EJB. &lt;/li&gt;&lt;/ul&gt;&lt;br&gt;Disadvantages:&lt;br&gt;&lt;ul&gt;&lt;li&gt;It should ideally not be used with large-sized objects, as it offers significant overhead. Large objects also significantly increase the memory requirements of your application since the object input/output streams cache live references to all objects written to or read from the stream until the stream is closed or reset. Consequently, the garbage collection of these objects can be inordinately delayed. &lt;/li&gt;&lt;li&gt;Serializable interface does not offer fine-grained control over object access - although you can somewhat circumvent this issue by implementing the complex Externalizable interface, instead. &lt;/li&gt;&lt;li&gt;Since serialization does not offer any transaction control mechanisms, it is not suitable for use within applications needing concurrent access without making use of additional APIs. &lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Criteria for a class to be Serializable:&lt;/span&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Have access to a no-argument constructor in its first non-serializable superclass &lt;/li&gt;&lt;li&gt;Identify non-serializable data members using the &lt;span style="font-weight: bold;"&gt;transient keyword&lt;/span&gt; or explicitly mark data members as serializable using the &lt;span style="font-weight: bold;"&gt;serialPersistentFields&lt;/span&gt; member. &lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;My subclass implements Serializable but my superclass doesn't. Both subclass and superclass contain instance variables that need to be saved as part of the state of the subclass. Will serialization save the superclass fields for me?&lt;/span&gt;&lt;br&gt;&lt;br&gt;When you serialize an object, the serialization mechanism works by chaining up the inheritance hierarchy, saving the sate of each Serializable superclass in turn. When serialization reaches the first non-serializable superclass, the serialization stops.&lt;br&gt;&lt;br&gt;When deserializing, the state of this first non-serializable superclass is restored not from the stream, but by invoking that class' no-argument constructor. If the no-argument constructor is not adequate for your purposes, you must customize the serialization of your subclass with writeObject() and readObject() in order to write out and restore any information from the non-serializable superclass that you find necessary.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Externalizable instead of Serializable:&lt;/span&gt;&lt;br&gt;&lt;br&gt;By implementing Externalizable yourself you can win performance at the cost of flexibility and extra code to maintain. If you implement Externalizable yourself you stream the data directly without the need for reflection which is used in the case of Serializable&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Read and write serialized objects to and from a database:&lt;/span&gt;&lt;br&gt;&lt;br&gt;If your RDBMS supports them, you can store serialized objects as BLOBs.&lt;br&gt;These are JDBC 2.0 features, but take a look at java.sql.Blob, ResultSet and PreparedStatement for more information.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Collections like Vector or a Hashtable:&lt;/span&gt;&lt;br&gt;&lt;br&gt;Collections like Vector and Hashtable both implements Serializable and have been designed for serialization.&lt;br&gt;One thing to keep in mind is to watch out for is, that in order to serialize a collection like Vector or Hashtable, you must also be able to serialize all of the objects contained in these collections. Otherwise, the collection would not be able to be completely restored. Your program will throw a NotSerializableException unless all objects stored in the Vector or Hashtable are also serializable.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Other way to save the state of an object of a class which   does not implement Serializable or Extenalizable&lt;/span&gt;&lt;br&gt;&lt;br&gt;Write the value of each and every instance variable into the persistent storage. If there are 50 variables, you will have to store each of them individually. If some of the variables are object references, you will have to follow each reference and save the state of that object as well. You can do that, but it would be a proprietary solution and each class that wanted to read your object would also have to know all about your proprietary format.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Role of serialization in RMI:&lt;/span&gt;&lt;br&gt;&lt;br&gt;RMI uses serialization as its basic and only mechanism for sending objects across a network.&lt;br&gt;If an object implements java.rmi.Remote, then the object's stub is serialized and sent to the client. If the object implements java.io.Serializable, then the object itself is serialized and sent.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Role of serialization in EJB:&lt;/span&gt;&lt;br&gt;&lt;br&gt;A big part of EJB is that it is a framework for underlying RMI: remote method invocation. You're invoking methods remotely from one JVM space 'A' on objects which are in JVM space 'B' -- possibly running on another machine on the network.&lt;br&gt;To make this happen, all arguments of each method call must have their current state plucked out of JVM 'A' memory, flattened into a byte stream which can be sent over a network connection, and then deserialized for reincarnation on the other end in JVM 'B' where the actual method call takes place.&lt;br&gt;If the method has a return value, it is serialized up for streaming back to JVM 'A.' Thus the requirement that all EJB methods arguments and return values must be serializable. The easiest way to do this is to make sure all your classes implement java.io.Serializable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-8665503032880995185?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/8665503032880995185/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=8665503032880995185" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8665503032880995185?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8665503032880995185?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/serialization-in-javaj2ee-demystified.html" title="Serialization in Java/J2EE - Demystified" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_b6Hez4oFqv0/RwocfsO9zjI/AAAAAAAAAkA/EmNyQNT0VqI/s72-c/Serialization.htm" height="72" width="72" /><thr:total>5</thr:total></entry><entry gd:etag="W/&quot;D0ADRX4ycSp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2131845203065407517</id><published>2007-10-09T13:14:00.000-07:00</published><updated>2007-11-09T14:02:54.099-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T14:02:54.099-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jax-ws" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><category scheme="http://www.blogger.com/atom/ns#" term="websevice" /><title>J2EE Tutorial on JAX WS Style Webservices using JBoss</title><content type="html">Continuing from part &lt;a target="_blank" href="http://java-polis.blogspot.com/2007/11/j2ee-tutorial-on-webservices-using.html"&gt;1&lt;/a&gt;, this part will cover the following porting steps in&lt;br&gt;&lt;br&gt;1.3 Porting Steps&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;1.3.1 Naming conventions&lt;/li&gt;&lt;li&gt;1.3.2 Generate stubs&lt;/li&gt;&lt;li&gt;1.3.3 Ant target to generate stubs&lt;/li&gt;&lt;li&gt;1.3.4 Test Webservices client&lt;/li&gt;&lt;li&gt;1.3.5 Configure Logging SOAP packet  (incoming and outgoing)&lt;br&gt;&lt;/li&gt;&lt;li&gt;1.3.6  Instructions for setting up SOAP packet logging on client side&lt;/li&gt;&lt;li&gt;1.3.7 Test client code snippet&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;1.3.1 Porting Steps&lt;br&gt;&lt;br&gt;To port JBoss Webservices stack from JBoss 4.0.4 to 4.2 &amp;gt;= without breaking interoperability from JAX-RPC style webservices to JAX-WS style web services few steps are required.&lt;br&gt;&lt;ul&gt;&lt;li&gt;WSDL (which act as a contract) generated previously has to be modified to work with JAX-WS compliant JbossWS.&lt;/li&gt;&lt;li&gt;Some naming conventions has to be followed while generating new WSDL so that stubs are generated with ease.&lt;/li&gt;&lt;li&gt;Generate Stubs&lt;/li&gt;&lt;li&gt;Logging SOAP Packet Logging &lt;/li&gt;&lt;/ul&gt;1.3.1.1 Diffrences between WSDL's&lt;br&gt;&lt;br&gt;Here is an old generated WSDL using JAX-RPC Stack on JBoss&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;?xml&lt;/span&gt; &lt;span class="re0"&gt;version&lt;/span&gt;=&lt;span class="st0"&gt;"1.0"&lt;/span&gt; &lt;span class="re0"&gt;encoding&lt;/span&gt;=&lt;span class="st0"&gt;"UTF-8"&lt;/span&gt;&lt;span class="re2"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:definitions&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3"&lt;/span&gt; &lt;span class="re0"&gt;targetNamespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:wsdl&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:xsd&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:http&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/http/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:mime&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/mime/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:soap&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/soap/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:tns&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:types&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:schema&lt;/span&gt; &lt;span class="re0"&gt;xmlns:xsd&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt; &lt;span class="re0"&gt;targetNamespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://localhost/matt/HelloWorld3/HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;xmlns:tns&lt;/span&gt;=&lt;span class="st0"&gt;"http://localhost/matt/HelloWorld3/HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;xmlns:edm&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:import&lt;/span&gt; &lt;span class="re0"&gt;namespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:complexType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRequest"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"id"&lt;/span&gt; &lt;span class="re0"&gt;nillable&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"xsd:string"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:complexType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:complexType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"result"&lt;/span&gt; &lt;span class="re0"&gt;nillable&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"xsd:string"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:complexType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:schema&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:schema&lt;/span&gt; &lt;span class="re0"&gt;xmlns:xsd&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;  &lt;span class="re0"&gt;targetNamespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:edm&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:tns&lt;/span&gt;=&lt;span class="st0"&gt;"http://localhost/matt/HelloWorld3/HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:import&lt;/span&gt; &lt;span class="re0"&gt;namespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://localhost/matt/HelloWorld3/HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldRequest"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:schema&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:types&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldOutput"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:portType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:input&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:output&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldOutput"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:portType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:binding&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Binding"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"tns:matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;soap:binding&lt;/span&gt; &lt;span class="re0"&gt;style&lt;/span&gt;=&lt;span class="st0"&gt;"document"&lt;/span&gt; &lt;span class="re0"&gt;transport&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/soap/http"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:operation&lt;/span&gt; &lt;span class="re0"&gt;soapAction&lt;/span&gt;=&lt;span class="st0"&gt;""&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:binding&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:service&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Service"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:port&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Port0"&lt;/span&gt; &lt;span class="re0"&gt;binding&lt;/span&gt;=&lt;span class="st0"&gt;"tns:matt_HelloWorld3Binding"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:address&lt;/span&gt; &lt;span class="re0"&gt;location&lt;/span&gt;=&lt;span class="st0"&gt;"http://spthd01:5565/soap/DocLiteral"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:port&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:service&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:definitions&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;Modified WSDL for JAX-WS stack in JBoss&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;?xml&lt;/span&gt; &lt;span class="re0"&gt;version&lt;/span&gt;=&lt;span class="st0"&gt;"1.0"&lt;/span&gt; &lt;span class="re0"&gt;encoding&lt;/span&gt;=&lt;span class="st0"&gt;"UTF-8"&lt;/span&gt;&lt;span class="re2"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:definitions&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;targetNamespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:wsdl&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:xsd&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:http&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/http/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:mime&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/mime/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:soap&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/wsdl/soap/"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:tns&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:types&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:schema&lt;/span&gt; &lt;span class="re0"&gt;xmlns:xsd&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;targetNamespace&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:edm&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"edm:HelloWorldRequest"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"edm:HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:complexType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRequest"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"id"&lt;/span&gt; &lt;span class="re0"&gt;nillable&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"xsd:string"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:complexType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;xsd:complexType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;xsd:element&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"result"&lt;/span&gt; &lt;span class="re0"&gt;nillable&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"xsd:string"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:sequence&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:complexType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/xsd:schema&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:types&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldOutput"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldRespons"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:portType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:input&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:output&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldOutput"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:portType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:binding&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Binding"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"tns:matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:binding&lt;/span&gt; &lt;span class="re0"&gt;style&lt;/span&gt;=&lt;span class="st0"&gt;"document"&lt;/span&gt; &lt;span class="re0"&gt;transport&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/soap/http"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:operation&lt;/span&gt; &lt;span class="re0"&gt;soapAction&lt;/span&gt;=&lt;span class="st0"&gt;""&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:binding&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:service&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Service"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:port&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Port0"&lt;/span&gt; &lt;span class="re0"&gt;binding&lt;/span&gt;=&lt;span class="st0"&gt;"tns:matt_HelloWorld3Binding"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:address&lt;/span&gt; &lt;span class="re0"&gt;location&lt;/span&gt;=&lt;span class="st0"&gt;"http://spthd01:5565/soap/DocLiteral"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:port&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:service&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:definitions&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;Difference between original WSDL and  modified WSDL&lt;br&gt;&lt;ul&gt;&lt;li&gt;No import statement required here&lt;/li&gt;&lt;li&gt;HelloWorld is not a complex type but just an element, if it is complex type it adds another layer in SOAP Packet&lt;/li&gt;&lt;li&gt;Similarly HelloWorldRespons is not a complex type but just an element&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;1.3.1 Naming conventions&lt;br&gt;&lt;br&gt;For naming conventions lets look at code snippet from original wsdl&lt;br&gt;&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;JAX-WS specification is pedantic about method name and&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;input argument name.&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;It says method name has to same as arguement name, otherwise&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;it will not work_. Here elemnet="tns:HelloWorld" is the&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;input argument and name="HelloWorld" is just a local name.&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;JAX-WS specification also _recommends_ to name return type,&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;suffix with word _Response_.&lt;/span&gt;&lt;br&gt;&lt;br&gt;In this case its not used, it is using word _Respons_ with missing _e_.&lt;br&gt;Here elemnet="tns:HelloWorldRespons" is the output arguement&lt;br&gt;and name="HelloWorldRepons" is just a local name.&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:message&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldOutput"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorldRespons"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldRespons"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:message&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Here method/function/behavior prototype is declared.&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Method name is _HelloWorld_ (operation name="HelloWorld")&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;same as input arguement (element="tns:HelloWorld" defined&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;under message name="HelloWorld".&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;This has to be same, otherwise it will not work/generate&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;right stubs.&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:portType&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:input&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;wsdl:output&lt;/span&gt; &lt;span class="re0"&gt;message&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorldOutput"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:portType&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:binding&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"matt_HelloWorld3Binding"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"tns:matt_HelloWorld3PortType"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Web services Style is document/literal and Wrapped. Wrapped&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;word is not mentioned, but it is the type of&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;arguements/paratmeters used in method/operation which&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;identfies it whether it is a Wrapped or non Wrappped service.&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;If an operation parameter uses element in declartion then&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;it is wrapped. In our case it is this &lt;/span&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&lt;br&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;element&lt;/span&gt;=&lt;span class="st0"&gt;"tns:HelloWorld"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;which makes it warpped.&lt;br&gt;&lt;br&gt;For non warpped it will be&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:part&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt; &lt;span class="re0"&gt;type&lt;/span&gt;=&lt;span class="st0"&gt;"xsd:string"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;soap:binding&lt;/span&gt; &lt;span class="re0"&gt;style&lt;/span&gt;=&lt;span class="st0"&gt;"document"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;transport&lt;/span&gt;=&lt;span class="st0"&gt;"http://schemas.xmlsoap.org/soap/http"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;Document type &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&lt;br&gt;&amp;lt;wsdl:operation&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"HelloWorld"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;soap:operation&lt;/span&gt; &lt;span class="re0"&gt;soapAction&lt;/span&gt;=&lt;span class="st0"&gt;""&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;Literal Type&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:input&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;soap:body&lt;/span&gt; &lt;span class="re0"&gt;use&lt;/span&gt;=&lt;span class="st0"&gt;"literal"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:output&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/wsdl:operation&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/wsdl:binding&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="foot"&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;1.3.2 Generate Stubs&lt;br&gt;&lt;br&gt;To generate stubs new tools sets are usd in JBoss 4.2 &amp;gt;= series.&lt;br&gt;Previuously it used to use wstools bundled with JBoss 4.0.4, now it uses&lt;br&gt;wsconsume and wsprovide.&lt;br&gt;&lt;br&gt;Wsconsume is used for top down approach - i:e; to generate stubs from  WSDL&lt;br&gt;&lt;br&gt;Wsprovide is used  for bottom up approach&lt;br&gt;For  both of them their are ant targets as well.&lt;br&gt;&lt;br&gt;For this exercise I have used command line tools.&lt;br&gt;&lt;br&gt;Command to generate stubs from WSDL.&lt;br&gt;&lt;br&gt;&lt;code&gt;&lt;br&gt;vsm@jm000606:client11$ ~/javadev/jboss/bin/wsconsume.sh  -k -p au.com.hello.client11.test.orig HelloWorldOrig.wsdl&lt;br&gt;JBossWS-Native stack deployed&lt;br&gt;parsing WSDL...&lt;br&gt;&lt;br&gt;generating code...&lt;br&gt;au.com.hello.client11.test.orig.HelloWorldRequest.java&lt;br&gt;au.com.hello.client11.test.orig.HelloWorldRespons.java&lt;br&gt;au.com.hello.client11.test.orig.MattHelloWorld3PortType.java&lt;br&gt;au.com.hello.client11.test.orig.MattHelloWorld3Service.java&lt;br&gt;au.com.hello.client11.test.orig.ObjectFactory.java&lt;br&gt;au.com.hello\client11.test.orig.package-info.java&lt;br&gt;vsm@jm000606:client11$&lt;br&gt;&lt;br&gt;I'm using unix based tools but you can use wsconsume.bat on windows.~~&lt;br&gt;&lt;br&gt;&lt;/code&gt;&lt;br&gt;1.3.3  Ant target to generate stubs&lt;br&gt;&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="re0"&gt;id&lt;/span&gt;=&lt;span class="st0"&gt;"web.services.classpath"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;fileset&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;dir&lt;/span&gt;=&lt;span class="st0"&gt;"C:/Program Files/Java/jdk1.5.0_06/lib/"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;includes&lt;/span&gt;=&lt;span class="st0"&gt;"*.jar"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;fileset&lt;/span&gt; &lt;span class="re0"&gt;dir&lt;/span&gt;=&lt;span class="st0"&gt;"D:/javadev/jboss-4.2.1.GA/lib/endorsed/"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;includes&lt;/span&gt;=&lt;span class="st0"&gt;"*.jar"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;fileset&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;dir&lt;/span&gt;=&lt;span class="st0"&gt;"D:/javadev/jboss-4.2.1.GA/lib/"&lt;/span&gt; &lt;span class="re0"&gt;includes&lt;/span&gt;=&lt;span class="st0"&gt;"*.jar"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;&lt;br&gt;&lt;br&gt;&amp;lt;!-- Please dont put jaxws-tools.jar and jaxws-rt.jar on&lt;br&gt;Eclipse's classpath at all, its fine within ant. Its&lt;br&gt;to do with JAXB API bundled in Eclispe and Jboss --&amp;gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;fileset&lt;/span&gt; &lt;span class="re0"&gt;dir&lt;/span&gt;=&lt;span class="st0"&gt;"D:/javadev/jboss-4.2.1.GA/client/"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"activation.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"getopt.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"wstx.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jbossall-client.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"log4j.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"mail.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jbossws-spi.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"stax-api.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jaxb-api.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jaxb-impl.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jaxb-xjc.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"streambuffer.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"stax-ex.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"javassist.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jboss-xml-binding.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jbossws-client.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jboss-jaxws.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jboss-jaxrpc.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jboss-saaj.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jboss-srp-client.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jbossws-common.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;&amp;lt;!-- Be careful with these two jars in Eclipse,&lt;br&gt;dont put it on classpath --&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"jaxws-tools.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;include&lt;/span&gt; name =&lt;span class="st0"&gt;"jaxws-rt.jar"&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/fileset&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/path&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;pre&gt;&amp;lt;!&lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;-- Ant task for wsconsume --&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;target&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"gen_stubs"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;taskdef&lt;/span&gt; &lt;span class="re0"&gt;name&lt;/span&gt;=&lt;span class="st0"&gt;"wsconsume"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;classname&lt;/span&gt;=&lt;span class="st0"&gt;"org.jboss.wsf.spi.tools.ant.WSConsumeTask"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;classpath&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="re0"&gt;refid&lt;/span&gt;=&lt;span class="st0"&gt;"web.services.classpath"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/classpath&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;br&gt;&amp;lt;/taskdef&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;wsconsume&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;fork&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;verbose&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;sourcedestdir&lt;/span&gt;=&lt;span class="st0"&gt;"${basedir}"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;package&lt;/span&gt;=&lt;span class="st0"&gt;"au.com.hello.integrate.anttask.stubs"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;keep&lt;/span&gt;=&lt;span class="st0"&gt;"true"&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;wsdl&lt;/span&gt;=&lt;span class="st0"&gt;"GetMemberTest.wsdl"&lt;/span&gt; &lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;&lt;br&gt;&amp;lt;!--destdir="${basedir}"--&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/target&lt;span class="re2"&gt;&amp;gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&amp;lt;!&lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;-- Ant task for wsprovide --&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&amp;lt;target name="test-wsproivde" &amp;gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;&amp;lt;taskdef name="WSProvideTask"&lt;br&gt;classname="org.jboss.wsf.spi.tools.ant.WSProvideTask"&amp;gt;&lt;br&gt;&amp;lt;classpath refid="&lt;span class="sc3"&gt;&lt;span class="st0"&gt;web.services.classpath&lt;/span&gt;&lt;/span&gt;"/&amp;gt;&lt;br&gt;&amp;lt;/taskdef&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;WSProvideTask&lt;br&gt;     fork="false"&lt;br&gt;     keep="true"&lt;br&gt;     destdir="out"&lt;br&gt;     resourcedestdir="out-resource"&lt;br&gt;     sourcedestdir="out-source"&lt;br&gt;     genwsdl="true"&lt;br&gt;     verbose="true"&amp;gt;&lt;br&gt;   &lt;br&gt;&amp;lt;/WSProvideTask&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;/target&amp;gt;&lt;br&gt;&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&lt;span class="re2"&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;1.3.3.1 More on wsconsume options:&lt;br&gt;If -keep option is set, the generated java files will be removed. -keep option is automatically set by WSConsume tool if you'll specify sourcedestdir attribute in your apache ant task.&lt;br&gt;&lt;br&gt;Thus if you will specify &lt;span style="font-style: italic;"&gt;sourcedestdir&lt;/span&gt;, the generated java files will not be deleted after the compilation phase.&lt;br&gt;&lt;br&gt;So &lt;span style="font-style: italic;"&gt;sourcedestdir&lt;/span&gt; points to the directory, where WsimportTool will generate java files&lt;br&gt;While &lt;span style="font-style: italic;"&gt;destdir&lt;/span&gt;points to a directory where these java files will be compiled to class files.&lt;br&gt;&lt;br&gt;1.3.4 Test Webservices Client&lt;br&gt;&lt;br&gt;Now only remaining bit is to write a Test Client and invoke the service.&lt;br&gt;Code snippet from test client.&lt;br&gt;&lt;br&gt;&lt;code&gt;public class TestWSClient {&lt;br&gt;&lt;br&gt;static Logger log = Logger.getLogger(TestWSClient.class);&lt;br&gt;&lt;br&gt;public static void main(String[] args)&lt;br&gt;{&lt;br&gt;// TODO Auto-generated method stub&lt;br&gt;&lt;br&gt;PropertyConfigurator.configure(&lt;br&gt;"D:/javadev/eclipse_workspace/TestWs/src/au/com/hello/client2/log4j.properties");&lt;br&gt;&lt;br&gt;Logger log = Logger.getLogger(TestWSClient.class);&lt;br&gt;log.info("Got My logger going -1 ");&lt;br&gt;&lt;br&gt;MattHelloWorld3Service service = new MattHelloWorld3Service();&lt;br&gt;MattHelloWorld3PortType port =  service.getPort(MattHelloWorld3PortType.class) ;&lt;br&gt;&lt;br&gt;BindingProvider bp = (BindingProvider) port;&lt;br&gt;bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "test");&lt;br&gt;bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "test");&lt;br&gt;&lt;br&gt;log.info ("Got My logger going -2");&lt;br&gt;&lt;br&gt;HelloWorldReq memreq = new HelloWorldReq();&lt;br&gt;&lt;br&gt;String response =   port.helloWorld("Hi Vishal");&lt;br&gt;System.out.println (" Returned messages is " + response);&lt;br&gt;}&lt;br&gt;}&lt;br&gt;&lt;/code&gt;&lt;br&gt;1.3.5 Logging SOAP Packet&lt;br&gt;&lt;br&gt;First configure your JBoss  Server side.&lt;br&gt;Go to jboss-log4j.xml under conf directory.&lt;br&gt;Uncomment this section&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;div class="de2"&gt;&lt;span class="sc3"&gt;&lt;span class="coMULTI"&gt;&amp;lt;!-- Enable JBossWS message tracing&lt;br&gt;&lt;/span&gt;&amp;lt;category name="jbossws.SOAPMessage"&amp;gt;&lt;br&gt;&lt;span class="re1"&gt;&amp;lt;priority&lt;/span&gt; &lt;span class="re0"&gt;value&lt;/span&gt;=&lt;span class="st0"&gt;"TRACE"&lt;/span&gt;&lt;span class="re1"&gt;/&amp;gt;&lt;br&gt;&amp;lt;/category&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="de1"&gt;--&amp;gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;1.3.6  Instructions for setting up SOAP packet logging on client side&lt;br&gt;Create a log4j.properties file with these options&lt;br&gt;&lt;br&gt;&lt;code&gt;&lt;br&gt;# Set root logger level to ALL and its only appender to A1.&lt;br&gt;log4j.rootLogger=ALL, A1&lt;br&gt;&lt;br&gt;# A1 is set to be a ConsoleAppender.&lt;br&gt;log4j.appender.A1=org.apache.log4j.ConsoleAppender&lt;br&gt;# Other appenders can be used here and can bee added to root&lt;br&gt;&lt;br&gt;# A1 uses PatternLayout.&lt;br&gt;log4j.appender.A1.layout=org.apache.log4j.PatternLayout&lt;br&gt;log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n&lt;br&gt;&lt;/code&gt;&lt;br&gt;Now inside your test client add this line which configures this logging.&lt;br&gt;&lt;code&gt;&lt;br&gt;PropertyConfigurator.configure("D:/javadev/eclipse_workspace/TestWs/src/au/com/hello/client2/log4j.properties");&lt;br&gt;&lt;/code&gt;&lt;br&gt;Now when you will run your server it will  log outgoing and incoming soap packets&lt;br&gt;&lt;br&gt;Outgoing SOAP packet is&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;env:Envelope&lt;/span&gt; &lt;span class="re0"&gt;&lt;br&gt;xmlns:env&lt;/span&gt;=&lt;span class="st0"&gt;'http://schemas.xmlsoap.org/soap/envelope/'&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;env:Header&lt;/span&gt;&lt;span class="re2"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;env:Body&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;ns1:HelloWorld&lt;/span&gt; xmlns:ns1=&lt;span class="st0"&gt;'http://www.vishal.com.au/matt.HelloWorld3'&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;id&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Hi Vishal&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/id&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/ns1:HelloWorld&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/env:Body&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/env:Envelope&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;Incoming SOAP packet is&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class="xml" style="border: 1px dotted rgb(160, 160, 160); margin: 0pt; padding: 0pt; white-space: nowrap; background-color: rgb(240, 240, 240); line-height: 110%; color: rgb(0, 0, 187); font-family: 'Courier New',Courier,monospace; font-size: 110%;"&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;edm:HelloWorldRespons&lt;/span&gt;&lt;br&gt;&lt;span class="re0"&gt;xmlns:edm&lt;/span&gt;=&lt;span class="st0"&gt;"http://www.vishal.com.au/matt.HelloWorld3"&lt;/span&gt;&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;result&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Hello Hi Vishal&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/result&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/edm:HelloWorldRespons&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/SOAP-ENV:Body&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class="sc3"&gt;&lt;span class="re1"&gt;&amp;lt;/SOAP-ENV:Envelope&lt;span class="re2"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;1.3.7 Test client code snippet&lt;br&gt;&lt;code&gt;&lt;br&gt;&lt;br&gt;public static void main(String[] args) {&lt;br&gt;&lt;br&gt;PropertyConfigurator.configure("D:/javadev/eclipse_workspace/TestWs/src/au/com/hello/client2/log4j.properties");&lt;br&gt;&lt;br&gt;log.info("Got My logger going -1 ");&lt;br&gt;&lt;br&gt;MattHelloWorld2Service service = new MattHelloWorld2Service();&lt;br&gt;MattHelloWorld2PortType port =  service.getPort(MattHelloWorld2PortType.class) ;&lt;br&gt;&lt;br&gt;BindingProvider bp = (BindingProvider) port;&lt;br&gt;bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "test");&lt;br&gt;bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "test");&lt;br&gt;&lt;br&gt;log.info ("Got My logger going -2");&lt;br&gt;&lt;br&gt;HelloWorld2 memReq = new HelloWorld2();&lt;br&gt;memReq.setId("Hellow Mathew");&lt;br&gt;&lt;br&gt;HelloWorld2Respons resp = port.getMessage(memReq);&lt;br&gt;&lt;br&gt;System.out.println (" Returned messages is " );&lt;br&gt;&lt;br&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2131845203065407517?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2131845203065407517/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2131845203065407517" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2131845203065407517?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2131845203065407517?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/j2ee-tutorial-on-jax-ws-style.html" title="J2EE Tutorial on JAX WS Style Webservices using JBoss" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;D0UHRnY8cSp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2327348932481501607</id><published>2007-10-09T13:03:00.000-07:00</published><updated>2007-11-09T13:53:57.879-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:53:57.879-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="cache" /><title>Opensource Cache/Caching Solutions in Java</title><content type="html">&lt;span style="font-weight: bold;"&gt;Background:&lt;/span&gt;&lt;br /&gt;In computer science, a &lt;b&gt;cache&lt;/b&gt; is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (due to slow access time) or to compute, relative to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, future use can be made by accessing the cached copy rather than re-fetching or recomputing the original data, so that the average access time is lower. Cache, therefore, helps expedites data access otherwise the CPU would need to fetch from main memory. Cache have proven to be extremely effective in many areas of computing because access patterns in typical computer applications have locality of reference. &lt;span class="link-external"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Purpose :&lt;/span&gt;&lt;br /&gt;The main purpose of the caching service is to improve server performance by managing static and non static data members. The performance gain is from reducing the number of trips to the database or other external sources of information, avoiding the cost of repeatedly recreating data (objects in java), sharing data between threads in a process and, when possible between processes, and efficient use of process resources.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Advantages: &lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;In a multi-tiered (n-tier) application, data access is an expensive operation, compared to any other task. By keeping the frequently accessed data around and not releasing it after the first use, we can avoid the cost and time required for the reacquisition and release of the data. This results in greatly improved performance, since we won't be hitting the database every time we need the data.&lt;/li&gt;&lt;li&gt;Scalability is another reason of using. Since cached data is accessed across multiple tiers, sessions, components, caching can become a big part of a scalable application design.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Disadvantages:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Synchronization complexity: Depending on the kind of data, complexity increases, because consistency between the state of the cached data and the original data in the data source needs to be ensured. Otherwise, the cached data can get out of sync with the actual data, which will lead to data inaccuracies.&lt;/li&gt;&lt;li&gt;Durability: Changes to the cached data can be lost when the server crashes. This problem can be avoided if a synchronized cache is used. &lt;/li&gt;&lt;li&gt;Memory size: JVM memory size can get unacceptably huge if there is lot of unused data in the cache and the data is not released from memory at regular intervals.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Opensource Caching solutions in Java:&lt;/span&gt;&lt;br /&gt;There are lots of caching solution in Java, free and non free. This is a list of opensource caching solutions available in Java/J2EE/JEE domain for software development or developing enterprise applications.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_b6Hez4oFqv0/Rwsn9sO9zkI/AAAAAAAAAkI/zefo39vir80/s1600-h/caching.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://1.bp.blogspot.com/_b6Hez4oFqv0/Rwsn9sO9zkI/AAAAAAAAAkI/zefo39vir80/s400/caching.jpg" alt="Java, Cache, Hibernate, Jboss, J2EE, Software, Caching, opensource" id="BLOGGER_PHOTO_ID_5119229342236134978" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span class="link-external"&gt;Bamboo DHT&lt;/span&gt; - is a distributed hash table, or DHT, is a building block for peer-to-peer applications. At the most basic level, it allows a group of distributed hosts to collectively manage a mapping from keys to data values, without any fixed hierarchy, and with very little human assistance. This building block can then be used to ease the implementation of a diverse variety of peer-to-peer applications such as file sharing services, DNS replacements, web caches, etc.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/cache4j"&gt;cache4j&lt;/a&gt; - is a cache for Java objects with a simple API and fast implementation. It features in-memory caching, a design for a multi-threaded environment, both synchronized and blocking implementations, a choice of eviction algorithms (LFU, LRU, FIFO), and the choice of either hard or soft references for object storage.&lt;br /&gt;&lt;br /&gt;&lt;span class="link-external"&gt;&lt;a href="http://freepastry.rice.edu/"&gt;FreePastry&lt;/a&gt;&lt;/span&gt; - is a modular, open source implementation of the Pastry p2p routing and location substrate. Pastry is a generic, scalable and efficient substrate for peer-to-peer applications. Pastry nodes form a decentralized, self-organizing and fault-tolerant overlay network within the Internet. Pastry provides efficient request routing, deterministic object location, and load balancing in an application-independent manner. Furthermore, Pastry provides mechanisms that support and facilitate application-specific object replication, caching, and fault recovery. The proponents of Pastry work for Microsoft, however they've made an excellent choice sticking with Java.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/ehcache"&gt;EHCache&lt;/a&gt; - is a pure Java, in-process cache. It started as a replacement for JCS. EHCache is faster than JCS. It has following features: Fast,Simple, pluggable cache for Hibernate, small foot print, minimal dependencies, fully documented and production tested.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/java-caching-system"&gt;Java Caching System (JCS)&lt;/a&gt; - is a distributed caching system written in java for server-side java applications. It is intended to speed up dynamic web applications by providing a means to manage cached data of various dynamic natures. Like any caching system, the JCS is most useful for high read, low put applications. Dynamic content and reporting systems can benefit most. However, any site that repeatedly constructs pages, drop downs, or common search results form a database that is updated at intervals (rather than across categories continuously) can improve performance and scalability by implementing caching. Latency times drop sharply and bottlenecks move away from the database in an effectively cached system.&lt;br /&gt;It provides several important features, necessary for any Enterprise level caching system, features include Memory management, disk overflow, element grouping, quick nested categorical removal, data expiration, extensible framework, fully configurable run time parameters, remote synchronization, remote store recovery, non-blocking "zombie" pattern, optional lateral distribution of elements, remote server clustering and failover. These features provide a framework with no point of failure, allowing for full session failover including session data across up to 256 servers.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/jbosscache"&gt;JBoss Cache&lt;/a&gt; - is a product designed to cache frequently accessed Java objects in order to dramatically improve the performance of e-business applications. By eliminating unnecessary database access, JBoss Cache decreases network traffic and increases the scalability of applications. But JBoss Cache is much more than a simple cache. JBoss Cache provides fully transactional features as well as a highly configurable set of options to deal with concurrent data access in the most efficient manner possible for your application. In addition, it is a clustered cache that replicates contents to other cache instances running on separate JVMs, servers or even entire networks, making JBoss Cache a highly efficient library used by application server developers to implement clustering features.&lt;br /&gt;JBossCache consists of two modules&lt;br /&gt;TreeCache - a replicated transactional tree-structured cache .&lt;br /&gt;TreeCacheAop a subclass of TreeCache using AOP to dynamically replicate Plain Old Java Objects - POJO.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java-source.net/open-source/cache-solutions/jcache"&gt;JCache&lt;/a&gt; - is an effort to make an Open Source version of JSR-107 JCache. Since the JSR-107 hasn't released any specs for years, This version still builds on the original functional specification. It is implemented by some  geeks at ThoughtWorks.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/jofti"&gt;Jofti&lt;/a&gt; - is a simple to use, high-performance object indexing and searching solution for Objects in a Caching layer or storage structure that supports the Map interface. The framework supports EHCache, JBossCache and OSCache and provides for transparent addition, removal and updating of objects in its index as well as simple to use query capabilities for searching. Features include type aware searching, configurable object property indexing, indexing/searching by interfaces as well as support for Dynamic Proxies, primitive attributes, Collections and Arrays&lt;br /&gt;&lt;br /&gt;&lt;span class="link-external"&gt;&lt;a href="http://www.oceanstore.org/"&gt;OceanStore&lt;/a&gt;&lt;/span&gt; - is a global persistent data store designed to scale to billions of users. It provides a consistent, highly-available, and durable storage utility atop an infrastructure comprised of untrusted servers. OceanStore caches data promiscuously; any server may create a local replica of any data object. These local replicas provide faster access and robustness to network partitions. They also reduce network congestion by localizing access traffic. Pond, the OceanStore prototype, is currently available for download.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/open-terracotta"&gt;Open Terracotta&lt;/a&gt; - is Open Source Clustering for Java. Features: HTTP Session Replication, Distributed Cache, POJO Clustering, Application Coordination across cluster's JVM's (made using code injection, so you don't need to modify your code)&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/oscache"&gt;OSCache&lt;/a&gt; - is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects. It provides both in memory and persistent on disk caches, and can allow your site to have graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people can still surf the site almost without knowing). Take a look at the great &lt;a href="http://www.opensymphony.com/oscache/wiki/Feature%20List.html"&gt;features&lt;/a&gt; of OSCache.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/shiftone"&gt;ShiftOne&lt;/a&gt; - is a Java Object Cache library that implements several strict object caching policies, as well as a light framework for configuring cache behavior. It's strict in the sense that each cache enforces two limits in a very strict and predictable way.&lt;a name="What does it mean that the caches are strict?"&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/swarmcache"&gt;SwarmCache&lt;/a&gt; - is a simple but effective distributed cache. It uses IP multicast to efficiently communicate with any number of hosts on a LAN. It is specifically designed for use by clustered, database-driven web applications. Such applications typically have many more read operations than write operations, which allows SwarmCache to deliver the greatest performance gains. SwarmCache uses JavaGroups internally to manage the membership and communications of its distributed cache. Wrappers have been written that allow SwarmCache to be used with the &lt;a href="http://hibernate.org/"&gt;Hibernate&lt;/a&gt; and &lt;a href="http://www.jpox.org/"&gt;JPOX&lt;/a&gt; persistence engines.&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://java-source.net/open-source/cache-solutions/whirlycache"&gt;WhirlyCache&lt;/a&gt; -  is a fast, configurable in-memory object cache for Java. It can be used, for example, to speed up a website or an application by caching objects that would otherwise have to be created by querying a database or by another expensive procedure&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2327348932481501607?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2327348932481501607/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2327348932481501607" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2327348932481501607?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2327348932481501607?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/opensource-cachecaching-solutions-in.html" title="Opensource Cache/Caching Solutions in Java" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_b6Hez4oFqv0/Rwsn9sO9zkI/AAAAAAAAAkI/zefo39vir80/s72-c/caching.jpg" height="72" width="72" /><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;Dk8BSXszfCp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2138129695272076186</id><published>2007-10-09T13:00:00.000-07:00</published><updated>2007-11-09T13:47:38.584-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:47:38.584-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="ejb" /><category scheme="http://www.blogger.com/atom/ns#" term="spring" /><title>Spring Framework - J2EE Development without EJB</title><content type="html">&lt;span style="font-weight: bold;"&gt;Background :&lt;/span&gt;&lt;br&gt;Spring is an open-source application framework, introduced and developed in 2004. The main ideas were suggested by an experienced J2EE architect, Rod Johnson. He had earlier, written a book titled J2EE Development without using EJB and had introduced the concept of Light-weight container. Primarily, his argument is that while EJB has its merits, it is not always necessary and suitable in all applications.&lt;br&gt;Just as Hibernate attacked CMP as primitive ORM technology, Spring attacked EJB as unduly complicated and not susceptible to unit-testing. Instead of EJB, Spring suggests that we make use of ordinary Java beans, with some slight modifications, to  get all the supposed advantages of EJB environment. Thus, Spring is posed as an alternative to EJB essentially. However, as a concession to the existing EJB investments, Spring is designed to operate with EJB if required.&lt;br&gt;&lt;br&gt;Much of the philosophy and approach of Spring framework, however, predates, the latest EJB-3. As we know now that EJB-3 has absorbed a number of new ideas suggested by Spring and some more, to answer the criticisms. Their is a debate going on in the Java community about Spring and EJB-3. Spring is not a Persistence technology but a framework which allows plug in of other such technologies. But EJB-3 is primarily focused on Persistence Technology and  has now incorporated Hibernate, the best ORM to date.Talks are going on to incorporate another equally nice ORM Technology known as JDO, which provides for Object Database also. Moreover, EJB-3 's Attribute-Oriented Meta tags, help in vastly reducing the size of XML lines. Some have complained that Spring is still too dependent on XML files.&lt;br&gt;The main aim of Spring is to simplify the J2EE development and testing.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Spring Under The Hood :&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_b6Hez4oFqv0/RwefP8O9zhI/AAAAAAAAAjY/asA1OGTpJLg/s1600-h/spring-overview.gif"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://2.bp.blogspot.com/_b6Hez4oFqv0/RwefP8O9zhI/AAAAAAAAAjY/asA1OGTpJLg/s400/spring-overview.gif" alt="Enterprise, Technlogy, Spring Framework, J2EE Development, Hibernate,without EJB" id="BLOGGER_PHOTO_ID_5118234597745610258" border="0"&gt;&lt;/a&gt;&lt;br&gt;Spring is a great framework for development of Enterprise applications. It is a light-weight framework for the development of enterprise-ready applications. Spring can be used to configure declarative transaction management, remote access to your logic using RMI or web services, mailing facilities and various options in persisting your data to a database. It can be used in modular fashion, allows to use in parts and leave the other components which is not required by the application.&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Main Features of Spring Framework:&lt;/span&gt;&lt;br&gt;&lt;br&gt;Transaction Management: Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring's transaction support is not tied to J2EE environments and it can be also used in container less environments.&lt;br&gt;&lt;br&gt;JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy&lt;br&gt;&lt;br&gt;Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS.&lt;br&gt;&lt;br&gt;AOP Framework: Spring is one of the best AOP framework&lt;br&gt;&lt;br&gt;MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText and POI.&lt;br&gt;But other frameworks can be easily used instead of Spring MVC Framework..&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Spring Architecture :&lt;br&gt;&lt;/span&gt;Spring is well-organized architecture consisting of various modules. Modules in the Spring framework are:&lt;br&gt;&lt;br&gt;1. &lt;span style="font-weight: bold;"&gt;Spring Aspect Oriented Programming (AOP)&lt;/span&gt;&lt;br&gt;AOP is used in Spring&lt;br&gt;&lt;br&gt;a) To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on Spring's transaction abstraction.&lt;br&gt;&lt;br&gt;b) To allow users to implement custom aspects, complementing their use of OOP with AOP&lt;br&gt;&lt;br&gt;2. &lt;span style="font-weight: bold;"&gt;Spring ORM&lt;/span&gt;&lt;br&gt;The ORM package is related to the database access. It provides integration layers for popular object-relational mapping APIs, including JDO, Hibernate and iBatis.&lt;br&gt;&lt;br&gt;3. &lt;span style="font-weight: bold;"&gt;Spring Context&lt;/span&gt;&lt;br&gt;This package builds on the beans package to add support for message sources and for the Observer design pattern, and the ability for application objects to obtain resources using a consistent API.&lt;br&gt;&lt;br&gt;4. &lt;span style="font-weight: bold;"&gt;Spring Web&lt;/span&gt;&lt;br&gt;The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts, JSF and webworks. The Web module also eases the tasks of handling multi part requests and binding request parameters to domain objects.&lt;br&gt;&lt;br&gt;5. &lt;span style="font-weight: bold;"&gt;Spring DAO&lt;/span&gt;&lt;br&gt;The Spring's JDBC and DAO abstraction layer offers a meaningful exception hierarchy for managing the database connection, exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of code that we need to write, such as opening and closing connections. This module also provide transaction management services for objects in a spring application.&lt;br&gt;&lt;br&gt;&lt;br&gt;6. &lt;span style="font-weight: bold;"&gt;Spring Web MVC&lt;/span&gt;&lt;br&gt;The MVC framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles and the generation of PDF and Excel Files.&lt;br&gt;&lt;br&gt;7. &lt;span style="font-weight: bold;"&gt;Spring Core&lt;/span&gt;&lt;br&gt;The Core package is the most import component of the Spring Framework.&lt;br&gt;This component provides the Dependency Injection features. The BeanFactory provides a factory pattern which separates the dependencies like initialization, creation and access of the objects from your actual program logic.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2138129695272076186?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2138129695272076186/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2138129695272076186" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2138129695272076186?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2138129695272076186?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/spring-framework-j2ee-development.html" title="Spring Framework - J2EE Development without EJB" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_b6Hez4oFqv0/RwefP8O9zhI/AAAAAAAAAjY/asA1OGTpJLg/s72-c/spring-overview.gif" height="72" width="72" /><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DkUNSXc4cCp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-3365725702093726943</id><published>2007-09-09T13:24:00.000-07:00</published><updated>2007-11-09T13:38:18.938-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:38:18.938-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><title>What are Checked and UnChecked Exceptions</title><content type="html">A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.&lt;br&gt;&lt;br&gt;Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. Ex, IOException thrown by java.io.FileInputStream's read() method·&lt;br&gt;&lt;br&gt;Unchecked exceptions are &lt;span style="font-style: italic;"&gt;RuntimeException&lt;/span&gt; and any of its subclasses. Class Error and its subclasses also are unchecked.&lt;br&gt;&lt;br&gt;With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method·&lt;br&gt;&lt;br&gt;Checked exceptions must be caught at compile time. Runtime exceptions do not need to be as &lt;span style="font-style: italic;"&gt;Errors&lt;/span&gt; often cannot be.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-3365725702093726943?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/3365725702093726943/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=3365725702093726943" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/3365725702093726943?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/3365725702093726943?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/what-are-checked-and-unchecked.html" title="What are Checked and UnChecked Exceptions" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;Dk4FQ3o5fCp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-2538726567568344491</id><published>2007-06-09T13:05:00.000-07:00</published><updated>2007-11-09T13:48:32.424-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:48:32.424-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="interview" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><title>Java J2EE Interview Questions - 7</title><content type="html">Continuing our Java/J2EE/JEE  interview questions and answers series, today's questions are:&lt;br&gt;&lt;br&gt;Q Describe the principles of OOPS.&lt;br&gt;A There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation. &lt;br&gt;&lt;br&gt;Q Explain the Encapsulation principle.&lt;br&gt;A Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper. &lt;br&gt;&lt;br&gt;Q Explain the Inheritance principle.&lt;br&gt;A Inheritance is the process by which one object acquires the properties of another object. &lt;br&gt;&lt;br&gt;Q Explain the Polymorphism principle.&lt;br&gt;A The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods". &lt;br&gt;&lt;br&gt;Q Explain the different forms of Polymorphism.&lt;br&gt;Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:&lt;br&gt;Method overloading&lt;br&gt;Method overriding through inheritance&lt;br&gt;Method overriding through the Java interface&lt;br&gt;&lt;br&gt;Q What are Access Specifiers available in Java?&lt;br&gt;A Access specifiers are keywords that determines the type of access to the member of a class. These are:&lt;br&gt;Public&lt;br&gt;Protected&lt;br&gt;Private&lt;br&gt;Defaults&lt;br&gt;&lt;br&gt;Q Describe the wrapper classes in Java.&lt;br&gt;A Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.&lt;br&gt;&lt;br&gt;Q What's the difference between J2SDK 1.5 and J2SDK 5.0?&lt;br&gt;A There's no difference, Sun Microsystems just re-branded this version.&lt;br&gt;&lt;br&gt;Q What would you use to compare two String variables - the operator == or the method equals()?&lt;br&gt;A I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.&lt;br&gt;&lt;br&gt;Q Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?&lt;br&gt;A Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.&lt;br&gt;&lt;br&gt;Q Can an inner class declared inside of a method access local variables of this method?&lt;br&gt;A It's possible if these variables are final.&lt;br&gt;&lt;br&gt;Q What can go wrong if you replace &amp;amp;&amp;amp; with &amp;amp; in the following code:&lt;br&gt;String a=null; if (a!=null &amp;amp;&amp;amp; a.length()&amp;gt;10) {...}&lt;br&gt;A A single ampersand here would lead to a NullPointerException.&lt;br&gt;&lt;br&gt;Q What's the main difference between a Vector and an ArrayList&lt;br&gt;A Java Vector class is internally synchronized and ArrayList is not.&lt;br&gt;&lt;br&gt;Q When should the method invokeLater()be used?&lt;br&gt;A This method is used to ensure that Swing components are updated through the event-dispatching thread.&lt;br&gt;&lt;br&gt;Q How can a subclass call a method or a constructor defined in a superclass?&lt;br&gt;A Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.&lt;br&gt;&lt;br&gt;Q You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?&lt;br&gt;A Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.&lt;br&gt;&lt;br&gt;Q What comes to mind when you hear about a young generation in Java?&lt;br&gt;A Garbage collection.&lt;br&gt;&lt;br&gt;Q What comes to mind when someone mentions a shallow copy in Java?&lt;br&gt;A Object cloning.&lt;br&gt;&lt;br&gt;Q If you're overriding the method equals() of an object, which other method you might also consider?&lt;br&gt;A hashCode()&lt;br&gt;&lt;br&gt;Q You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:&lt;br&gt;ArrayList or LinkedList?&lt;br&gt;A ArrayList&lt;br&gt;&lt;br&gt;Q How would you make a copy of an entire Java object with its state?&lt;br&gt;A Have this class implement Cloneable interface and call its method clone().&lt;br&gt;&lt;br&gt;Q How can you minimize the need of garbage collection and make the memory use more effective?&lt;br&gt;A Use object pooling and weak object references.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-2538726567568344491?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/2538726567568344491/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=2538726567568344491" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2538726567568344491?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/2538726567568344491?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/java-j2ee-interview-questions-7.html" title="Java J2EE Interview Questions - 7" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0cCRHw5eyp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-4304193556413850914</id><published>2007-05-09T13:18:00.000-07:00</published><updated>2007-11-09T13:51:05.223-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:51:05.223-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><title>Top 10 Popular Eclipse Plugin</title><content type="html">Eclipse is an open source platform with many vendors behind it. IBM started this initiative in response to take on SUN in IDE market and compete with their offerings in this space now known as Netbeans. Its name came from Lunar Eclipse (hint: think of what happens to Sun during Lunar Eclipse).&lt;br&gt;&lt;br&gt;Since its inception Eclipse platform has come a long way. Its now one of the most popular platform for software development, esp in Java, J2EE development.  Strictly speaking it is not an IDE, it is a platform which allows you to plugin and play various components according to to your technical needs. Most of the plugins offered are opensource, but some companies have SAAS model for their plugin distributions, like MyEclipse.&lt;br&gt;&lt;br&gt;To give you an insight on how eclipse IDE cum platform is used I have compiled a list of top ten popular plugin used.&lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Spring IDE&lt;/li&gt;&lt;li&gt;MyEclipse Enterprise Workbench&lt;/li&gt;&lt;li&gt;Mylyn   &lt;/li&gt;&lt;li&gt;Hibernate Synchronizer&lt;/li&gt;&lt;li&gt;Azzurri Clay &lt;/li&gt;&lt;li&gt;FreeMarker IDE&lt;/li&gt;&lt;li&gt;J2EE Spider  &lt;/li&gt;&lt;li&gt;WindowBuilder Pro&lt;/li&gt;&lt;li&gt;Jigloo SWT/Swing &lt;/li&gt;&lt;li&gt;Checkstyle Plug-in&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-4304193556413850914?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/4304193556413850914/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=4304193556413850914" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4304193556413850914?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/4304193556413850914?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/top-10-popular-eclipse-plugin.html" title="Top 10 Popular Eclipse Plugin" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0QCRns8eip7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-5526937768206573212</id><published>2007-05-09T13:16:00.000-07:00</published><updated>2007-11-09T13:56:07.572-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T13:56:07.572-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><title>How Can i find when a HttpSession is removed/timed-out</title><content type="html">1. Define a class named SessionTimeoutNotifier which implements javax.servlet.http.HttpSessionBindingListener.&lt;br&gt;&lt;br&gt;2. Create a SessionTimeoutNotifier object and add it to the user session.&lt;br&gt;&lt;br&gt;3. When the session is removed, SessionTimeoutNotifier.valueUnbound() will be called by the servlet engine.&lt;br&gt;&lt;br&gt;4. You can implement valueUnbound() method to do whatever you want.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-5526937768206573212?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/5526937768206573212/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=5526937768206573212" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5526937768206573212?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/5526937768206573212?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/how-can-i-find-when-httpsession-is.html" title="How Can i find when a HttpSession is removed/timed-out" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;AkcER3s7eyp7ImA9WB9WGE8.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-8003589315678653057</id><published>2007-04-09T13:21:00.000-07:00</published><updated>2007-11-23T06:26:46.503-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-23T06:26:46.503-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><title>How to do a deep clone of an java object</title><content type="html">Clone() method by default create's a shallow copy. For deep clone/copy you have to either override clone() method or provide a separate method.&lt;br&gt;&lt;br&gt;The simplest approach to deep cloning is to use serialization, where you serialize and deserialize the object and return the deserialized version. This will be a deep copy/clone, assuming everything in the object tree is serializable.&lt;br&gt;If everything is not serializable, you'll have to implement the deep cloning behavior on your own.&lt;br&gt;&lt;br&gt;Assuming everything is serializable, the following code snippet should create a complete deep copy of the current class instance:&lt;br&gt;&lt;br&gt;ByteArrayOutputStream byteArrOs = new ByteArrayOutputStream();&lt;br&gt;ObjectOutputStream objOs = new ObjectOutputStream(byteArrOs);&lt;br&gt;objOs.writeObject(this);&lt;br&gt;&lt;br&gt;ByteArrayInputStream byteArrIs = new ByteArrayInputStream(byteArrOs.toByteArray());&lt;br&gt;ObjectInputStream objIs = new ObjectInputStream(byteArrIs);&lt;br&gt;Object deepCopy = objIs.readObject();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-8003589315678653057?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/8003589315678653057/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=8003589315678653057" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8003589315678653057?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/8003589315678653057?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/how-to-do-deep-clone-of-java-object.html" title="How to do a deep clone of an java object" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;CEcHRHc_eip7ImA9WB9WFU0.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-7256476599036706474</id><published>2007-04-09T13:17:00.000-07:00</published><updated>2007-11-19T11:53:55.942-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-19T11:53:55.942-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><title>What is HTTP tunneling</title><content type="html">HTTP tunneling is a general technique whereby arbitrary data may be sent via an HTTP connection to and from CGI scripts or Java Servlets or other technology on a Web server. This is done by serializing the data to be transmitted into a stream of bytes, and sending an HTTP message with content type "&lt;span style="font-style: italic;"&gt;application/octet-stream&lt;/span&gt;".  HTTP tunneling is also referred to as Firewall tunneling.&lt;br /&gt;&lt;br /&gt;Common reasons for using HTTP-Tunnel&lt;br /&gt;  * Need to bypass any firewall&lt;br /&gt;  * Need secure internet browsing&lt;br /&gt;  * Need to use favorite programs with out being monitored by work, school, ISP or government.&lt;br /&gt;  * Extra security for online transactions&lt;br /&gt;  * Encrypt Internet traffic.&lt;br /&gt;  * Need to play online games&lt;br /&gt;  * Visit sites that you were previously blocked from accessing&lt;br /&gt;  * Prevent 3rd party monitoring or regulation of your Internet browsing and downloads&lt;br /&gt;  * Use your favorite applications previously blocked&lt;br /&gt;  * Hide your IP address&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-7256476599036706474?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/7256476599036706474/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=7256476599036706474" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7256476599036706474?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7256476599036706474?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/what-is-http-tunneling.html" title="What is HTTP tunneling" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0EAR309eSp7ImA9WB9XFkk.&quot;"><id>tag:blogger.com,1999:blog-1483042418080050881.post-7870513024249335555</id><published>2007-01-09T13:10:00.000-08:00</published><updated>2007-11-09T14:00:46.361-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-09T14:00:46.361-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jax-ws" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><category scheme="http://www.blogger.com/atom/ns#" term="websevice" /><title>J2EE Tutorial on Webservices using JBoss</title><content type="html">This J2EE tutorial covers building and porting JAX-RPC style Webservices to JAX-WS.&lt;br&gt;&lt;br&gt;Tools used for this tutorial exercise  are&lt;br&gt;JBossWs 2.0.1GA  (Jboss's JAX-WS implementation)&lt;br&gt;JBoss  4.2.1GA - (J2EE Application server)&lt;br&gt;Eclispe IDE 3.2 &amp;gt;=&lt;br&gt;Apache Ant&lt;br&gt;&lt;br&gt;1.1 Background&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;1.1.1 JAX-RPC&lt;/li&gt;&lt;li&gt;1.1.2 JAX-WS&lt;/li&gt;&lt;/ul&gt;1.2 Differences&lt;br&gt;&lt;ul&gt;&lt;li&gt;1.2.1.1 SOAP 1.2&lt;/li&gt;&lt;li&gt;1.2.1.3 WS-I's Basic Profiles&lt;/li&gt;&lt;li&gt;1.2.1.4 New Java features&lt;/li&gt;&lt;li&gt;1.2.1.5 The data mapping model&lt;/li&gt;&lt;li&gt;1.2.1.6 The interface mapping model&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;1.3 Porting Steps&lt;br&gt;&lt;ul&gt;&lt;li&gt;1.3.1 Naming conventions&lt;/li&gt;&lt;li&gt;1.3.2 Generate Stubs&lt;/li&gt;&lt;li&gt;1.3.3 Ant target to generate stubs&lt;/li&gt;&lt;li&gt;1.3.4 Test Webservices Client&lt;/li&gt;&lt;li&gt;1.3.5 Logging SOAP Packet&lt;/li&gt;&lt;li&gt;1.3.6  Instructions for setting up SOAP packet logging on client side&lt;/li&gt;&lt;li&gt;1.3.7 Test client snippet&lt;/li&gt;&lt;br&gt;&lt;/ul&gt;1.4 Integrate With EJB 3.0&lt;br&gt;&lt;ul&gt;&lt;li&gt;1.4.1  Define a Remote Interface&lt;/li&gt;&lt;li&gt;1.4.2 Implement a Stateless Session Bean&lt;/li&gt;&lt;li&gt;1.4.3 Build Jar&lt;/li&gt;&lt;li&gt;1.4.4 Run an EJB Client&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;&lt;br&gt;1.1 Background&lt;br&gt;&lt;br&gt;1.1.1 JAX-RPC&lt;br&gt;&lt;br&gt;JAX RPC style of webservices is built on JSR-101 specification.&lt;br&gt;&lt;br&gt;JBoss 4.0.4 server comes with JBossWs 1.0 series which has support for JAX-RPC and non JAX-WS style,  i:e; JSR-101 (JAX-RPC) and JSR-109 (non JAX-WS) style webservices respectively, rather than JSR-181  (JAX-WS) compliant. &lt;span style="font-style: italic;"&gt;Strictly speaking,&lt;/span&gt; &lt;span style="font-style: italic;"&gt;JbossWS 1.0&lt;/span&gt; is not a JAX-WS compliant as it is missing JSR-181 impelmentation.&lt;br&gt;&lt;br&gt;It only supports SOAP 1.1.&lt;br&gt;&lt;br&gt;1.1.2 JAX-WS&lt;br&gt;&lt;br&gt;JAX-WS style of web services is built on JSR-224 specification.&lt;br&gt;It uses annotations (JSR-181) and new data binding stack JAXB. JbossWS 2.0 &amp;gt;= series which&lt;br&gt;is used in this porting exercise is JAX-WS compliant.&lt;br&gt;&lt;br&gt;In addition to being JAX-WS compliant, for backward compatibilty it has support for JAX-RPC(JSR-101) and JSR-109 compliant services used in JBoss 4.0.4.&lt;br&gt;&lt;br&gt;It supports SOAP 1.1 and SOAP 1.2.&lt;br&gt;&lt;br&gt;&lt;br&gt;1.2 Differences&lt;br&gt;&lt;br&gt;Their are quiet a few notable differences between JAX-WS and JAX-RPC. Notable ones to keep in mind while porting are in italics.&lt;br&gt;&lt;br&gt;1.2.1.1 SOAP 1.2&lt;br&gt;&lt;br&gt;JAX-RPC and JAX-WS support SOAP 1.1. JAX-WS also supports SOAP 1.2.&lt;br&gt;&lt;br&gt;1.2.1.2 XML/HTTP&lt;br&gt;&lt;br&gt;The WSDL 1.1 specification defined an HTTP binding, which is a means by which you can send XML messages over HTTP without SOAP. JAX-RPC ignored the HTTP binding. JAX-WS adds support for it.&lt;br&gt;&lt;br&gt;1.2.1.3 WS-I's Basic Profiles&lt;br&gt;&lt;br&gt;JAX-RPC supports WS-I's Basic Profile (BP) version 1.0. JAX-WS supports BP 1.1. (WS-I is the Web services interoperability organization.)&lt;br&gt;&lt;br&gt;1.2.1.4 New Java features&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-RPC maps to Java 1.4. JAX-WS maps to Java 5.0. JAX-WS relies on many of the features new in Java 5.0.&lt;/span&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;Java EE 5, the successor to J2EE 1.4, adds support for JAX-WS, but it also retains support for JAX-RPC, which could be confusing to today's Web services novices.&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;1.2.1.5 The data mapping model&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-RPC has its own data mapping model, which covers about 90 percent of all schema types. Those that it does not cover are mapped to javax.xml.soap.SOAPElement.&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-WS's data mapping model is JAXB. JAXB promises mappings for all XML schemas.&lt;/span&gt;&lt;br&gt;&lt;br&gt;1.2.1.6 The interface mapping model&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-WS's basic interface mapping model is not extensively different from JAX-RPC's; however:&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-WS's model makes use of new Java 5.0 features.&lt;/span&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-WS's model introduces asynchronous functionality.&lt;/span&gt;&lt;br&gt;&lt;br&gt;1.2.1.7 The dynamic programming model&lt;br&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-WS's dynamic client model is quite different from JAX-RPC's. Many of the changes acknowledge industry needs:&lt;/span&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;It introduces message-oriented functionality.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;It introduces dynamic asynchronous functionality.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-style: italic;"&gt;    JAX-WS also adds a dynamic server model, which JAX-RPC does not have.&lt;/span&gt;&lt;br&gt;&lt;br&gt;1.2.1.7 MTOM (Message Transmission Optimization Mechanism)&lt;br&gt;&lt;br&gt;JAX-WS, via JAXB, adds support for MTOM, the new attachment specification. Microsoft never bought into the SOAP with Attachments specification; but it appears that everyone supports MTOM, so attachment interoperability should become a reality.&lt;br&gt;&lt;br&gt;1.2.1.8 The handler model&lt;br&gt;&lt;span style="font-style: italic;"&gt;&lt;br&gt;The handler model has changed quite a bit from JAX-RPC to JAX-WS.&lt;/span&gt;&lt;br&gt;&lt;span style="font-style: italic;"&gt;JAX-RPC handlers rely on SAAJ 1.2. JAX-WS handlers rely on the new SAAJ 1.3 specification.&lt;/span&gt;&lt;br&gt;&lt;br&gt;Part - 2 of tutorial is continued &lt;a target="_blank" href="http://java-polis.blogspot.com/2007/11/j2ee-tutorial-on-jax-ws-style.html"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1483042418080050881-7870513024249335555?l=java-polis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://java-polis.blogspot.com/feeds/7870513024249335555/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=1483042418080050881&amp;postID=7870513024249335555" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7870513024249335555?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1483042418080050881/posts/default/7870513024249335555?v=2" /><link rel="alternate" type="text/html" href="http://java-polis.blogspot.com/2007/11/j2ee-tutorial-on-webservices-using.html" title="J2EE Tutorial on Webservices using JBoss" /><author><name>Cloogy</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total></entry></feed>

