<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tsolak.com</title>
	<atom:link href="http://www.tsolak.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.tsolak.com</link>
	<description>Tsolak Petrosian</description>
	<lastBuildDate>Fri, 23 Apr 2010 17:19:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring WS client.</title>
		<link>http://www.tsolak.com/?p=55</link>
		<comments>http://www.tsolak.com/?p=55#comments</comments>
		<pubDate>Thu, 28 Jan 2010 22:04:02 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=55</guid>
		<description><![CDATA[<p>In my previous post  I described how to create sample Spring Web Service.
In this article I am going to show how to write generic Web Services client for it (or for any other Web Services).</p>
<p>The idea here is to define java interface that will mirror WS request/response messages and have a Spring proxy to [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://www.tsolak.com/?p=28">post </a> I described how to create sample Spring Web Service.<br />
In this article I am going to show how to write generic Web Services client for it (or for any other Web Services).</p>
<p>The idea here is to define java interface that will mirror WS request/response messages and have a Spring proxy to take care of WS calls and XML marshalling.<br />
In <a href="http://www.tsolak.com/?p=28">previous</a> article we defined SampleEndpoint that was Java back bone of our WS.<br />
What we whould like to do is to have Java interface that will mimic SampleEndpoint public methods and have Spring create WS proxy for it to be injected into our WS clients.</p>
<p><span id="more-55"></span></p>
<p>1. Generic WS client spring proxy:</p>
<div class="codesnip-container" >
<div class="codesnip">package com.<span class="me1">localmatters</span>.<span class="me1">util</span>.<span class="me1">spring</span>.<span class="me1">proxy</span>;</p>
<p><span class="co2">import java.lang.reflect.InvocationTargetException;</span></p>
<p><span class="co2">import org.springframework.util.ClassUtils;</span><br />
<span class="co2">import org.aopalliance.intercept.MethodInvocation;</span><br />
<span class="co2">import org.aopalliance.intercept.MethodInterceptor;</span></p>
<p><span class="co2">import org.springframework.aop.support.AopUtils;</span><br />
<span class="co2">import org.springframework.beans.factory.FactoryBean;</span><br />
<span class="co2">import org.springframework.aop.framework.ProxyFactory;</span><br />
<span class="co2">import org.springframework.beans.factory.InitializingBean;</span></p>
<p><span class="co2">import org.springframework.ws.client.core.WebServiceTemplate;</span><br />
<span class="co2">import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;</span></p>
<p><span class="kw2">public</span> <span class="kw2">class</span> WebServiceProxy <span class="kw2">implements</span> FactoryBean, InitializingBean<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AClassLoader+java.sun.com&#038;bntl=1"><span class="kw3">ClassLoader</span></a> beanClassLoader = ClassUtils.<span class="me1">getDefaultClassLoader</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> uri = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw2">private</span> Marshaller marshaller = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw2">private</span> Unmarshaller unmarshaller = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="kw2">private</span> WebServiceTemplate webServiceTemplate = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">Class</span> serviceInterface = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> proxy = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> getUri<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> uri;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setUri<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> uri<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">uri</span> = uri;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> Marshaller getMarshaller<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> marshaller;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setMarshaller<span class="br0">&#40;</span>Marshaller marshaller<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">marshaller</span> = marshaller;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> Unmarshaller getUnmarshaller<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> unmarshaller;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setUnmarshaller<span class="br0">&#40;</span>Unmarshaller unmarshaller<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">unmarshaller</span> = unmarshaller;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> WebServiceTemplate getWebServiceTemplate<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> webServiceTemplate;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setWebServiceTemplate<span class="br0">&#40;</span>WebServiceTemplate webServiceTemplate<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">webServiceTemplate</span> = webServiceTemplate;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">Class</span> getServiceInterface<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> serviceInterface;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setServiceInterface<span class="br0">&#40;</span><span class="kw2">Class</span> serviceInterface<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">serviceInterface</span> = serviceInterface;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> afterPropertiesSet<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">proxy</span> = <span class="kw2">new</span> ProxyFactory<span class="br0">&#40;</span> serviceInterface, createMethodInterceptor<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>.<span class="me1">getProxy</span><span class="br0">&#40;</span>beanClassLoader<span class="br0">&#41;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>webServiceTemplate != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="kw2">return</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; webServiceTemplate = <span class="kw2">new</span> WebServiceTemplate<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; SaajSoapMessageFactory factory = <span class="kw2">new</span> SaajSoapMessageFactory<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; factory.<span class="me1">afterPropertiesSet</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; webServiceTemplate.<span class="me1">setMessageFactory</span><span class="br0">&#40;</span>factory<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; webServiceTemplate.<span class="me1">setDefaultUri</span><span class="br0">&#40;</span>uri<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; webServiceTemplate.<span class="me1">setMarshaller</span><span class="br0">&#40;</span>marshaller<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; webServiceTemplate.<span class="me1">setUnmarshaller</span><span class="br0">&#40;</span>unmarshaller<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> getObject<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> proxy;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">Class</span> getObjectType<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> serviceInterface;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">boolean</span> isSingleton<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">true</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> MethodInterceptor createMethodInterceptor<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="br0">&#40;</span><span class="kw2">new</span> MethodInterceptor<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> invoke<span class="br0">&#40;</span>MethodInvocation methodInvocation<span class="br0">&#41;</span> <span class="kw2">throws</span> <a href="http://www.google.com/search?q=allinurl%3AThrowable+java.sun.com&#038;bntl=1"><span class="kw3">Throwable</span></a><span class="br0">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> invokeMethod<span class="br0">&#40;</span>methodInvocation<span class="br0">&#41;</span>;<span class="br0">&#125;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> invokeMethod<span class="br0">&#40;</span>MethodInvocation methodInvocation<span class="br0">&#41;</span> <span class="kw2">throws</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a>, <a href="http://www.google.com/search?q=allinurl%3AIllegalAccessException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalAccessException</span></a>, <a href="http://www.google.com/search?q=allinurl%3AInvocationTargetException+java.sun.com&#038;bntl=1"><span class="kw3">InvocationTargetException</span></a><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//we assume that WS should contain only one argument (something like SampleRequest)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> methodInvocation.<span class="me1">getArguments</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == <span class="kw2">null</span> || methodInvocation.<span class="me1">getArguments</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">length</span> != <span class="nu0">1</span> <span class="br0">&#41;</span> <span class="kw2">throw</span> <span class="kw2">new</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a><span class="br0">&#40;</span><span class="st0">&#8220;Should contain exactly one argument&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> arg = methodInvocation.<span class="me1">getArguments</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> result = webServiceTemplate.<span class="me1">marshalSendAndReceive</span><span class="br0">&#40;</span>arg<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> result;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Note that we are assuming that WS is based on single argument Request object (which should be true for most of cases).</p>
<p>2. WS service interface:</p>
<p>As said before we have to define Java interface for WS to be used by out client:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">public</span> <span class="kw2">interface</span> SampleService<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw2">public</span> SampleResponse processSampleRequest<span class="br0">&#40;</span>SampleRequest request<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>3. Defining proxy with SampleService:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=“sampleJaxbMarshaller” <span class="re0">class</span>=“org.springframework.oxm.jaxb.Jaxb2Marshaller”<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=“classesToBeBound”<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>com.equilibriums.samplespringws.SampleRequest<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>com.equilibriums.samplespringws.SampleResponse<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=“marshallerProperties”<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;map<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;entry</span> <span class="re0">key</span>=“jaxb.formatted.output”<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;value</span> <span class="re0">type</span>=“java.lang.Boolean”<span class="re2">&gt;</span></span>true<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/entry<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/map<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;alias</span> <span class="re0">name</span>=“sampleJaxbMarshaller” <span class="re0">alias</span>=“sampleJaxbUnmarshaller” <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;wsSampleService&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;WebServiceProxy&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;uri&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;http://localhost:8080/sample&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;serviceInterface&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;SampleService&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;marshaller&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;sampleJaxbMarshaller&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;unmarshaller&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;sampleJaxbUnmarshaller&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">name</span>=<span class="st0">&#8220;someSampleClient&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;&#8230;&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;sampleService&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;wsSampleService&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></div>
</div>
<p>Note that we need to redefine Marshallers in our context file. To simplify this you can define them in separate Spring XML file and share then between client and WS server web app.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring WS+JAXB</title>
		<link>http://www.tsolak.com/?p=28</link>
		<comments>http://www.tsolak.com/?p=28#comments</comments>
		<pubDate>Fri, 22 Jan 2010 01:27:45 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=28</guid>
		<description><![CDATA[<p>Download projects</p>


sample-spring-ws.zip


<p>Here is sample Spring WS application that shows how to expose your bean method as WS service and handle XML marshaling using JAXB.</p>
<p>There are 4 major parts involved here.</p>
<p></p>
<p>1. Define your XML schemas. Unlike some other WS frameworks Spring WS starts from WSDL&#8217;s or XSD&#8217;s.</p>

&#60;?xml version=&#8220;1.0&#8243; encoding=&#8220;UTF-8&#8243;?&#62;
&#60;xs:schema xmlns=&#8220;http://equilibriums.com/sample-spring-ws&#8221;
targetNamespace=&#8220;http://equilibriums.com/sample-spring-ws&#8221;
elementFormDefault=&#8220;qualified&#8221; xmlns:xs=&#8220;http://www.w3.org/2001/XMLSchema&#8221;&#62;</p>
<p>&#160; &#160;&#60;xs:element name=&#8220;sampleRequest&#8221; type=&#8220;sampleRequestType&#8221; /&#62;</p>
<p>&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><strong><font color="red">Download projects</font></strong></p>
<ul>
<li>
<a id="p23" href="http://www.tsolak.com/wordpress/wp-content/sample-spring-ws.zip">sample-spring-ws.zip</a>
</li>
</ul>
<p>Here is sample Spring WS application that shows how to expose your bean method as WS service and handle XML marshaling using JAXB.</p>
<p>There are 4 major parts involved here.</p>
<p><span id="more-28"></span></p>
<p>1. Define your XML schemas. Unlike some other WS frameworks Spring WS starts from WSDL&#8217;s or XSD&#8217;s.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">&#8220;1.0&#8243;</span> <span class="re0">encoding</span>=<span class="st0">&#8220;UTF-8&#8243;</span>?<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;xs</span>:schema <span class="re0">xmlns</span>=<span class="st0">&#8220;http://equilibriums.com/sample-spring-ws&#8221;</span><br />
<span class="re0">targetNamespace</span>=<span class="st0">&#8220;http://equilibriums.com/sample-spring-ws&#8221;</span><br />
<span class="re0">elementFormDefault</span>=<span class="st0">&#8220;qualified&#8221;</span> xmlns:<span class="re0">xs</span>=<span class="st0">&#8220;http://www.w3.org/2001/XMLSchema&#8221;</span><span class="re2">&gt;</span></span></p>
<p>&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;xs</span>:element <span class="re0">name</span>=<span class="st0">&#8220;sampleRequest&#8221;</span> <span class="re0">type</span>=<span class="st0">&#8220;sampleRequestType&#8221;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:complexType <span class="re0">name</span>=<span class="st0">&#8220;sampleRequestType&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:sequence<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:element <span class="re0">name</span>=<span class="st0">&#8220;request&#8221;</span> <span class="re0">type</span>=<span class="st0">&#8220;xs:string&#8221;</span> <span class="re0">minOccurs</span>=<span class="st0">&#8220;0&#8243;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/xs</span>:sequence<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/xs</span>:complexType<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:element <span class="re0">name</span>=<span class="st0">&#8220;sampleResponse&#8221;</span> <span class="re0">type</span>=<span class="st0">&#8220;sampleResponseType&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;xs</span>:complexType <span class="re0">name</span>=<span class="st0">&#8220;sampleResponseType&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:sequence<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;xs</span>:element <span class="re0">name</span>=<span class="st0">&#8220;response&#8221;</span> <span class="re0">type</span>=<span class="st0">&#8220;xs:string&#8221;</span> <span class="re0">minOccurs</span>=<span class="st0">&#8220;0&#8243;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/xs</span>:sequence<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/xs</span>:complexType<span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;/xs</span>:schema<span class="re2">&gt;</span></span></div>
</div>
<p>2. web.xml.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;servlet<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>sample-spring-ws<span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;servlet</span>-class<span class="re2">&gt;</span></span>org.springframework.web.servlet.DispatcherServlet<span class="sc3"><span class="re1">&lt;/servlet</span>-class<span class="re2">&gt;</span></span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;load</span>-on-startup<span class="re2">&gt;</span></span>1<span class="sc3"><span class="re1">&lt;/load</span>-on-startup<span class="re2">&gt;</span></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/servlet<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;servlet</span>-mapping<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>sample-spring-ws<span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;url</span>-pattern<span class="re2">&gt;</span></span>/*<span class="sc3"><span class="re1">&lt;/url</span>-pattern<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/servlet</span>-mapping<span class="re2">&gt;</span></span></div>
</div>
<p>Please note, that according to Spring documentation, its better to use &#8220;MessageDispatcherServlet&#8221; but I found it too limiting. For example I could not use multiple &#8220;SoapMessageDispatcher&#8221;&#8216;.</p>
<p>3. Boring Spring WebServices beans and JAXB marshaller.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;transformLocations&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;true&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;messageFactory&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.soap.saaj.SaajSoapMessageFactory&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;payloadMapping&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping&#8221;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;defaultHandlerMapping&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping&#8221;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;baseWsdlDefinition&#8221;</span> <span class="re0">abstract</span>=<span class="st0">&#8220;true&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;requestSuffix&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;Request&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;responseSuffix&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;Response&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;sampleJaxbMarshaller&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.oxm.jaxb.Jaxb2Marshaller&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;classesToBeBound&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>com.equilibriums.samplespringws.SampleRequest<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>com.equilibriums.samplespringws.SampleResponse<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;marshallerProperties&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;map<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;entry</span> <span class="re0">key</span>=<span class="st0">&#8220;jaxb.formatted.output&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;value</span> <span class="re0">type</span>=<span class="st0">&#8220;java.lang.Boolean&#8221;</span><span class="re2">&gt;</span></span>true<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/entry<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/map<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;alias</span> <span class="re0">name</span>=<span class="st0">&#8220;sampleJaxbMarshaller&#8221;</span> <span class="re0">alias</span>=<span class="st0">&#8220;sampleJaxbUnmarshaller&#8221;</span> <span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;sampleSoapMessageDispatcher&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.soap.server.SoapMessageDispatcher&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;endpointAdapters&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;marshaller&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;sampleJaxbMarshaller&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;unmarshaller&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;sampleJaxbUnmarshaller&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;alias</span> <span class="re0">name</span>=<span class="st0">&#8220;sampleSoapMessageDispatcher&#8221;</span> <span class="re0">alias</span>=<span class="st0">&#8220;/sample-spring-ws&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">name</span>=<span class="st0">&#8220;sampleWsdl&#8221;</span> <span class="re0">parent</span>=<span class="st0">&#8220;baseWsdlDefinition&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;schemaCollection&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;xsds&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/xsd/sample.xsd<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/list<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;inline&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;true&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;portTypeName&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;Sample&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;locationUri&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;/sample-spring-ws&#8221;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;targetNamespace&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;http://equilibriums.com/sample-spring-ws&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;alias</span> <span class="re0">name</span>=<span class="st0">&#8220;sampleWsdl&#8221;</span> <span class="re0">alias</span>=<span class="st0">&#8220;/sample.wsdl&#8221;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;sampleEndpoint&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;com.equilibriums.samplespringws.SampleEndpoint&#8221;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></div>
</div>
<p>As mentioned above we can define multiple &#8220;SoapMessageDispatcher&#8221; that use different parsers (some times its cleaner to have multiple JAXB marshallers that are configured with POJOs for each WebService).</p>
<p>4. Your Endpoint.  Spring will use your Endpoint PayloadRoot annotation to match WS request to appropriate method. </p>
<div class="codesnip-container" >
<div class="codesnip">package com.<span class="me1">equilibriums</span>.<span class="me1">samplespringws</span>;</p>
<p><span class="co2">import org.springframework.ws.server.endpoint.annotation.Endpoint;</span><br />
<span class="co2">import org.springframework.ws.server.endpoint.annotation.PayloadRoot;</span></p>
<p>@Endpoint<br />
<span class="kw2">public</span> <span class="kw2">class</span> SampleEndpoint<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; @PayloadRoot<span class="br0">&#40;</span>localPart = <span class="st0">&#8220;sampleRequest&#8221;</span>, namespace = <span class="st0">&#8220;http://equilibriums.com/sample-spring-ws&#8221;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> SampleResponse processSampleRequest<span class="br0">&#40;</span>SampleRequest request<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SampleResponse result = <span class="kw2">new</span> SampleResponse<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; result.<span class="me1">setResponse</span><span class="br0">&#40;</span> <span class="st0">&#8220;Request was: &#8220;</span> + request.<span class="me1">getRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> result;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And finally you can access WSDL using &#8220;http://localhost:8080/sample.wsdl&#8221; (assuming its deployed under http://localhost:8080) and call WebService using <a href="http://www.soapui.org/">soapUI</a> standalone application or its Eclipse plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring MVC+Custom Multy Action support.</title>
		<link>http://www.tsolak.com/?p=21</link>
		<comments>http://www.tsolak.com/?p=21#comments</comments>
		<pubDate>Sat, 31 May 2008 03:05:52 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=21</guid>
		<description><![CDATA[<p>Download projects</p>


eqs-pim.zip


eqs-spring.zip


eqs-springmvc.zip


<p>
Test (default tomcat 6.0.14 install) &#8211; http://localhost:8080/eqs-pim-webapp-1.0.0/login.htm
Enter nothing on login.

This article tries to show how to put together relatively complex web application using Spring MVC and is an attempt to show some of the best practices of web application development and packaging.
To address some of the Java web development problems and to achieve simplicity [...]]]></description>
			<content:encoded><![CDATA[<p><strong><font color="red">Download projects</font></strong></p>
<ul>
<li>
<a id="p23" href="http://www.tsolak.com/wordpress/wp-content/eqs-pim.zip">eqs-pim.zip</a>
</li>
<li>
<a id="p24" href="http://www.tsolak.com/wordpress/wp-content/eqs-spring.zip">eqs-spring.zip</a>
</li>
<li>
<a id="p25" href="http://www.tsolak.com/wordpress/wp-content/eqs-springmvc.zip">eqs-springmvc.zip</a>
</li>
</ul>
<p>
<strong><font color="red">Test (default tomcat 6.0.14 install)</font></strong> &#8211; <a href="http://localhost:8080/eqs-pim-webapp-1.0.0/login.htm">http://localhost:8080/eqs-pim-webapp-1.0.0/login.htm</a><br />
<font color="red">Enter nothing on login.</font><br />
<br />
This article tries to show how to put together relatively complex web application using Spring MVC and is an attempt to show some of the best practices of web application development and packaging.<br />
To address some of the Java web development problems and to achieve simplicity of Ruby on Rails additional abstract classes and tag libraries have been introduce as part of this sample application.<br />
You can use included source code as template for your future projects.<br />
<span id="more-21"></span><br />
<br />
<strong>View and Controller.</strong><br />
<br />
Traditionally in MVC2 type of application you would have at least two different Controllers. One which prepares data for View to render and another which will get action request from View and process them.<br />
This definitely is a good practice but does not really adhere to MVC paradigm where there is only one Controller for given View.<br />
What I would like to have is one Controller that handles all rendering and action processing similarly to how it is in RoR.<br />
Here is diagram that shows the difference between MVC2 and our approaches.<br />
<br />
<a href="http://www.tsolak.com/wordpress/wp-content/view-and-controller.gif"><img src="http://www.tsolak.com/wordpress/wp-content/view-and-controller.gif" height="572"/></a><br />
<strong>Figure 1.</strong><br />
<br />
<strong>Passing Action from JSP</strong><br />
<br />
What I have done is define Action tag that will pass &#8220;actionId&#8221; and additional action parameters to Spring controller as request parameters through URL query parameters or hidden input during POST action.<br />
Additionally this tag will automatically get its name, title and image for html link or button from resource bundle.<br />
If multiple submit button are required or there is need for HREF to submit a form the tag will auto generate necessary JavaScript to handle &#8220;onclick&#8221; events.<br />
In most cases you only need to define &#8220;actionId&#8221; and controller path, the rest are filled automatically.<br />
Here is example action tags:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;action</span>:action <span class="re0">action</span>=<span class="st0">&#8220;logoff&#8221;</span> <span class="re0">targetUri</span>=<span class="st0">&#8220;login.htm&#8221;</span><span class="re2">/&gt;</span></span></div>
</div>
<p>which will be rendered as: </p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;a</span> <span class="re0">href</span>=<span class="st0">&#8220;/eq-pim-webapp/login.htm;jsessionid=B4F536972F875BD1C7A18DF18DC1F36B?action=logoff&#8221;</span> <span class="re0">title</span>=<span class="st0">&#8220;Logoff and return to Login page&#8221;</span> <span class="re2">&gt;</span></span>Logoff<span class="sc3"><span class="re1">&lt;/a<span class="re2">&gt;</span></span></span></div>
</div>
<p>or for form submit:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;action</span>:action <span class="re0">action</span>=<span class="st0">&#8220;login&#8221;</span> <span class="re0">submitForm</span>=<span class="st0">&#8220;true&#8221;</span><span class="re2">/&gt;</span></span> <br />
//targetUri is not used here since the controller to post form when //this action is invoked will be the one defines in form action</div>
</div>
<p>which will be rendered as: </p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;input</span> <span class="re0">type</span>=<span class="st0">&#8220;hidden&#8221;</span> <span class="re0">name</span>=<span class="st0">&#8220;action&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;login&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;input</span> <span class="re0">type</span>=<span class="st0">&#8220;submit&#8221;</span> <span class="re0">value</span>=<span class="st0">&#8220;Login&#8221;</span><span class="re2">&gt;</span></span></div>
</div>
<p>
<strong>Mapping action to a method in controller</strong><br />
<br />
This is another feature I like from RoR. Instead of handling every single action in one &#8220;handleRequest&#8221; method, what &#8220;AbstractActionMethodController&#8221; (the one that all your controllers will extend from) does is that it maps &#8220;actionId&#8221; to method names and action parameters to method parameters. This is more like Spring &#8220;MultiActionController&#8221; but I choose not to use it because I needed better control on how method parameters were getting parsed from request query parameters.<br />
<br />
PropetyEditors are used to parse query parameters to non string parameters that action methods are taking.<br />
Like &#8220;MultiActionController&#8221; it will pass HttpServletRequest and HttpServletResponse objects to action method if it has them as first parameters.<br />
<br />
<strong>ModelAndView.</strong><br />
<br />
Here are some practical rules to help in deciding what to put in Model and how to choose a View.</p>
<ul>
<li>
Externalize the decision what View to use into Spring context file.<br />
Controller should not really care what View to use to render its Model, its job is to process user action and prepare Model for the view.<br />
This also should make our Controller more reusable.
</li>
<p></p>
<li>
View can be a JSP or another Controller. Usually you need to &#8220;forward&#8221; to JSP and to &#8220;redirect&#8221; to Controller. Spring already supports defining &#8220;forward&#8221; and &#8220;redirect&#8221; instruction in Spring context file so your Controller does not to hardcode them.
</li>
<p></p>
<li>
Always redirect after successfully processing action.<br />
If we don&#8217;t do this, the browser will still have URL to previously processed action and when user refreshes the browser, we will undesirable get request to re-process the same action again.<br />
This is true even if we use one Controller per action.<br />
This rule is related to <a href="http://www.theserverside.com/tt/articles/content/RedirectAfterPost/article.html">RedirectAfterPost</a>.
</li>
<p></p>
<li>
On failure when processing action you can use forward or redirect.<br />
If forward is used, then when user refreshes page you will repeat same action again but this time it is ok since the action failed processing first time and data integrity should have stayed unchanged.
</li>
<p></p>
<li>
Don&#8217;t redirect to JSP. Actually if you put your JSP inside WEB-INF directory you cant directly access it with Spring MVC. Instead if you want to redirect to JSP view due to  rule #3 or #4 redirect to self controller which in turn will forward to JSP.<br />
Here is sample configuration which will do it:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">name</span>=<span class="st0">&#8220;/contacts.htm&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;com.equilibriums.pim.controller.contacts.ContactsController&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;contactsView&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>contacts.page<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;newContactView&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>redirect:/contactEdit.htm<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;editContactView&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>redirect:/contactEdit.htm<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;deleteContactFailedView&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span> redirect:/contacts.htm<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;deleteContactSuccessView&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>redirect:/contacts.htm<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;contactService&#8221;</span> <span class="re0">ref</span>=<span class="st0">&#8220;contactService&#8221;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></div>
</div>
<p>As, you can see we can change the forward/redirect behavior without modifying our &#8220;contacts.htm&#8221; controller.
</li>
<p></p>
<li>
Don&#8217;t use &#8220;forward&#8221; instead of &#8220;redirect&#8221; just to be able to pass non string object in between Controllers. Even though Spring will put Model data into URL as query parameters before it does redirect, it is still not enough since Model data now should be fetched using &#8220;request.getParameter&#8221; instead of &#8220;request.getAttribute&#8221; and non String Model data is converted into String using &#8220;toString&#8221; which in most cases is impossible to deserialize. What I have done, and which is common practice, is to define Spring Handler that will put model data into session and resurrect it in between redirects.<br />
This is quite usefull when passing messages in between controllers for display.<br />
In our example application &#8220;contact edit&#8221; Controller will pass successful saved message to &#8220;contacts&#8221; Controller.<br />
Again all this is totally transparent to Controllers.
</li>
</ul>
<p>
<strong>i18n, resource bundles.</strong><br />
<br />
Spring has excellent support for internationalization. The sample app fully supports internalization without requiring to change the code or JSPs.<br />
I have separated resource bundles into 3 categories.</p>
<ul>
<li>
Action resource bundles which contain Name, Images and Descriptions for each action.
</li>
<p></p>
<li>
Caption resource bundle which contains text that needs to internationalized in JSPs.
</li>
<p></p>
<li>
Message resource bundle that contain text used in Info or Error messages.
</li>
</ul>
<p>Here is content from each resource bundle files for login pages.<br />
<br />
action.properties</p>
<div class="codesnip-container" >
<div class="codesnip"># Login<br />
login.login.Name=Login<br />
login.login.ShortDescription=Login to application</p>
<p>login.logoff.Name=Logoff<br />
login.logoff.ShortDescription=Logoff and return to Login page</div>
</div>
<p>
caption.properties</p>
<div class="codesnip-container" >
<div class="codesnip">#these will be used in login form page for labels<br />
login.form.userName=User Name:<br />
login.form.userPassword=User Password:</div>
</div>
<p>
messages.properties</p>
<div class="codesnip-container" >
<div class="codesnip"># LOGIN<br />
login.invalid.user.error=Invalid user name or password.<br />
login.logoff.before.login.info=Not logged in.</div>
</div>
<p>This resource files are configured in Spring like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="coMULTI">&lt;!&#8211;&nbsp; SPECIFY RESOURCE BUNDLE FILES (actions.properties will simply be actions, remember ResourceBundleMessageSource wont be able to load from outside classpath which is classes folder) &#8211;&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&#8220;messageSource&#8221;</span> <span class="re0">class</span>=<span class="st0">&#8220;org.springframework.context.support.ReloadableResourceBundleMessageSource&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">&#8220;basenames&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;list<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/app/actions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/app/captions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/app/messages<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span></p>
<p><span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/login/actions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/login/captions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/login/messages<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span></p>
<p><span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/contacts/actions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/contacts/captions<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>/WEB-INF/i18n/contacts/messages<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/list<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></div>
</div>
<p>The action descriptions are automatically loaded and used by ActionTag.<br />
The captions, like messages, are rendered using &#8220;spring:message&#8221; tag, like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;spring</span>:message <span class="re0">code</span>=<span class="st0">&#8220;login.form.userName&#8221;</span> <span class="re0">text</span>=<span class="st0">&#8220;User Name:&#8221;</span><span class="re2">/&gt;</span></span></div>
</div>
<p>To pass messages from controller to View layers you need to add them into Model object, like this: </p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">new</span> ModelAndView<span class="br0">&#40;</span> logoffView, <span class="st0">&#8220;info&#8221;</span>, <a href="http://www.google.com/search?q=allinurl%3AArrays+java.sun.com&#038;bntl=1"><span class="kw3">Arrays</span></a>.<span class="me1">asList</span><span class="br0">&#40;</span> <span class="kw2">new</span> DefaultMessageSourceResolvable<span class="br0">&#40;</span><span class="st0">&#8220;login.logoff.before.login.info&#8221;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span>;</div>
</div>
<p>messages.jsp will take the list of  DefaultMessageSourceResolvable from request and render them using &#8220;spring:message&#8221; tag.<br />
<br />
message.jsp</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>%@ taglib <span class="re0">uri</span>=<span class="st0">&#8220;http://java.sun.com/jstl/core&#8221;</span> <span class="re0">prefix</span>=<span class="st0">&#8220;c&#8221;</span> %<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;</span>%@ taglib <span class="re0">uri</span>=<span class="st0">&#8220;http://java.sun.com/jsp/jstl/functions&#8221;</span> <span class="re0">prefix</span>=<span class="st0">&#8220;fn&#8221;</span> %<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;</span>%@ taglib <span class="re0">uri</span>=<span class="st0">&#8220;http://www.springframework.org/tags&#8221;</span> <span class="re0">prefix</span>=<span class="st0">&#8220;spring&#8221;</span> %<span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&#8220;infos&#8221;</span><span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;c</span>:if <span class="re0">test</span>=<span class="st0">&#8220;${info != null}&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;table</span> <span class="re0">width</span>=<span class="st0">&#8220;100%&#8221;</span> <span class="re0">border</span>=<span class="st0">&#8220;0&#8243;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;tr<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;td</span> <span class="re0">align</span>=<span class="st0">&#8220;left&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;c</span>:forEach <span class="re0">items</span>=<span class="st0">&#8220;${info}&#8221;</span> <span class="re0">var</span>=<span class="st0">&#8220;infoMessage&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;spring</span>:message <span class="re0">message</span>=<span class="st0">&#8220;${infoMessage}&#8221;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;br<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/c</span>:forEach<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/td<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/tr<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/table<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/c</span>:if<span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span></p>
<p><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">class</span>=<span class="st0">&#8220;errors&#8221;</span><span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;c</span>:if <span class="re0">test</span>=<span class="st0">&#8220;${error != null}&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;table</span> <span class="re0">width</span>=<span class="st0">&#8220;100%&#8221;</span> <span class="re0">border</span>=<span class="st0">&#8220;0&#8243;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;tr<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;td<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;c</span>:forEach <span class="re0">items</span>=<span class="st0">&#8220;${error}&#8221;</span> <span class="re0">var</span>=<span class="st0">&#8220;errorMessage&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;spring</span>:message <span class="re0">message</span>=<span class="st0">&#8220;${errorMessage}&#8221;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;br<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/c</span>:forEach<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/td<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/tr<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/table<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/c</span>:if<span class="re2">&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;spring</span>:hasBindErrors <span class="re0">name</span>=<span class="st0">&#8220;command&#8221;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;c</span>:if <span class="re0">test</span>=<span class="st0">&#8220;${errors.fieldErrorCount &gt;</span> 0}&quot;&gt;<br />
<span class="sc3">&lt;table width=&#8221;</span><span class="nu0">100</span>%<span class="st0">&#8221; border=&#8221;</span>0<span class="st0">&#8220;&gt;</span><br />
<span class="sc3">&lt;tr&gt;</span><br />
<span class="sc3">&lt;td&gt;</span><br />
Please fix the following (<span class="sc3">&lt;c:out value=&#8221;</span>$<span class="br0">&#123;</span>errors.fieldErrorCount<span class="br0">&#125;</span><span class="st0">&#8220;/&gt;</span>) errors in the form marked with red labels!<br />
<span class="sc3">&lt;/td&gt;</span><br />
<span class="sc3">&lt;/tr&gt;</span><br />
<span class="sc3">&lt;tr&gt;</span><br />
<span class="sc3">&lt;td&gt;</span><br />
<span class="sc3">&lt;c:forEach items=&#8221;</span>$<span class="br0">&#123;</span>errors.fieldErrors<span class="br0">&#125;</span><span class="st0">&#8221; var=&#8221;</span>fieldError<span class="st0">&#8221; varStatus=&#8221;</span>status<span class="st0">&#8220;&gt;</span><br />
<span class="sc3">&lt;c:forEach items=&#8221;</span>$<span class="br0">&#123;</span>fieldError.codes<span class="br0">&#125;</span><span class="st0">&#8221; var=&#8221;</span>fieldErrorCode<span class="st0">&#8220;&gt;</span><br />
<span class="sc3">&lt;spring:message code=&#8221;</span>$<span class="br0">&#123;</span>fieldErrorCode<span class="br0">&#125;</span><span class="st0">&#8221; text=&#8221;</span><span class="st0">&#8221; var=&#8221;</span>fieldErrorText<span class="st0">&#8221; scope=&#8221;</span>page<span class="st0">&#8220;/&gt;</span><br />
<span class="sc3">&lt;c:if test=&#8221;</span>$<span class="br0">&#123;</span>fieldErrorText != <span class="st0">&#8221;</span><span class="br0">&#125;</span><span class="st0">&#8220;&gt;</span><br />
- <span class="sc3">&lt;c:out value=&#8221;</span>$<span class="br0">&#123;</span>fieldErrorText<span class="br0">&#125;</span><span class="st0">&#8220;/&gt;</span><br />
<span class="sc3">&lt;c:if test=&#8221;</span>$<span class="br0">&#123;</span>!status.last<span class="br0">&#125;</span><span class="st0">&#8220;&gt;</span><span class="sc3">&lt;br&gt;</span><span class="sc3">&lt;/c:if&gt;</span><br />
<span class="sc3">&lt;/c:if&gt;</span><br />
<span class="sc3">&lt;/c:forEach&gt;</span><br />
<span class="sc3">&lt;/c:forEach&gt;</span><br />
<span class="sc3">&lt;/td&gt;</span><br />
<span class="sc3">&lt;/tr&gt;</span><br />
<span class="sc3">&lt;/table&gt;</span><br />
<span class="sc3">&lt;/c:if&gt;</span><br />
<span class="sc3">&lt;/spring:hasBindErrors&gt;</span></p>
<p><span class="sc3">&lt;/div&gt;</span> </span></div>
</div>
<p>
<strong>Spring themes.</strong><br />
<br />
Spring themes allow us to switch in between themes without modifying CSS&#8217;s or their import statements.<br />
In our example app we have CSS defined for grey theme and instead of directly importing it in our JSP we use &#8220;spring:theme&#8221; to dynamically get CSS path using &#8220;stylePrefix&#8221; (defined in grey.properties&#8221;) variable.<br />
<br />
<strong>Packaging</strong><br />
<br />
Most of web application can contain non Java code resources such as JSPs, CSS and images and resource bundle files. I have decided to separate these resources into separate directories based on their functionality. This is totally personal preference and can be customized as needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=21</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CXF+SPRING+POJO</title>
		<link>http://www.tsolak.com/?p=20</link>
		<comments>http://www.tsolak.com/?p=20#comments</comments>
		<pubDate>Fri, 28 Mar 2008 18:15:29 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=20</guid>
		<description><![CDATA[<p>
Full maven project can be downloaded from HERE.

This is a follow up article to XFIRE+EJB+POJO.
Here I show how to expose POJO using CXF project instead of XFire. Setting up WebServices with CXF is very easy and consists of two steps:
</p>


Setting up web.xml with CXFServlet.


Defining POJO endpoint.

<p>

Setting up web.xml with CXFServlet.</p>


&#60;!DOCTYPE web-app PUBLIC&#160; &#34;-//Sun Microsystems, Inc.//DTD [...]]]></description>
			<content:encoded><![CDATA[<p>
Full maven project can be downloaded from <a href="http://www.tsolak.com/wordpress/wp-content/cxf-numberservice.zip">HERE</a>.<br />
<br />
This is a follow up article to <a href="http://www.tsolak.com/?p=15">XFIRE+EJB+POJO</a>.<br />
Here I show how to expose POJO using CXF project instead of XFire. Setting up WebServices with CXF is very easy and consists of two steps:<br />
</p>
<ul>
<li>
Setting up <em>web.xml</em> with <em>CXFServlet</em>.
</li>
<li>
Defining POJO endpoint.
</li>
<p></ui><br />
<span id="more-20"></span><br />
<strong>Setting up <em>web.xml</em> with <em>CXFServlet</em>.</strong></p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc0">&lt;!DOCTYPE web-app PUBLIC&nbsp; &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;&nbsp; 
&quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; &gt;</span> 
<span class="sc3"><span class="re1">&lt;web</span>-app<span class="re2">&gt;</span></span>

<span class="sc3"><span class="re1">&lt;display</span>-name<span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;/display</span>-name<span class="re2">&gt;</span></span> 

<span class="sc3"><span class="coMULTI">&lt;!-- CXFServlet expect these spring configs already loaded by listeners, endpoint context files will be defined as servlet param. 
This will allow us to have different CXFServlets with different endpoints --&gt;</span></span>
<span class="sc3"><span class="re1">&lt;context</span>-param<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;param</span>-name<span class="re2">&gt;</span></span>contextConfigLocation<span class="sc3"><span class="re1">&lt;/param</span>-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;param</span>-value<span class="re2">&gt;</span></span>
classpath:/META-INF/cxf/cxf.xml
classpath:/META-INF/cxf/cxf-servlet.xml
classpath:/META-INF/cxf/cxf-extension-soap.xml
<span class="sc3"><span class="re1">&lt;/param</span>-value<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/context</span>-param<span class="re2">&gt;</span></span>

<span class="sc3"><span class="re1">&lt;listener<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;listener</span>-class<span class="re2">&gt;</span></span>
org.springframework.web.context.ContextLoaderListener
<span class="sc3"><span class="re1">&lt;/listener</span>-class<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/listener<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;servlet<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>numberservice<span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span> 
<span class="sc3"><span class="re1">&lt;servlet</span>-class<span class="re2">&gt;</span></span>org.apache.cxf.transport.servlet.CXFServlet<span class="sc3"><span class="re1">&lt;/servlet</span>-class<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;init</span>-param<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;param</span>-name<span class="re2">&gt;</span></span>config-location<span class="sc3"><span class="re1">&lt;/param</span>-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;param</span>-value<span class="re2">&gt;</span></span>/WEB-INF/numberservice-servlet.xml<span class="sc3"><span class="re1">&lt;/param</span>-value<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/init</span>-param<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;load</span>-on-startup<span class="re2">&gt;</span></span>1<span class="sc3"><span class="re1">&lt;/load</span>-on-startup<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/servlet<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;servlet</span>-mapping<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>numberservice<span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;url</span>-pattern<span class="re2">&gt;</span></span>/*<span class="sc3"><span class="re1">&lt;/url</span>-pattern<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/servlet</span>-mapping<span class="re2">&gt;</span></span>

<span class="sc3"><span class="re1">&lt;/web</span>-app<span class="re2">&gt;</span></span></div>
</div>
</pre>
<p>
Most of CXF examples have one spring context file that gets loaded through a servlet listener.<br />
The one above shows how to have multiple CXFServlets defined with their own endpoints context file.<br />
<br />
<strong>Defining POJO endpoint.</strong></p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">"1.0"</span> <span class="re0">encoding</span>=<span class="st0">"UTF-8"</span>?<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;beans</span> <span class="re0">xmlns</span>=<span class="st0">"http://www.springframework.org/schema/beans"</span>
xmlns:<span class="re0">xsi</span>=<span class="st0">"http://www.w3.org/2001/XMLSchema-instance"</span>
xmlns:<span class="re0">simple</span>=<span class="st0">"http://cxf.apache.org/simple"</span>
xsi:<span class="re0">schemaLocation</span>=<span class="st0">"http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"</span><span class="re2">&gt;</span></span>
&nbsp; &nbsp; 
<span class="sc3"><span class="coMULTI">&lt;!-- ENDPOINTS --&gt;</span></span>
<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">name</span>=<span class="st0">"numberService"</span> <span class="re0">class</span>=<span class="st0">"com.tsolak.numberservice.NumberServiceImpl"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp;
<span class="sc3"><span class="re1">&lt;simple</span>:server <span class="re0">id</span>=<span class="st0">"numberServiceEndpoint"</span> <span class="re0">address</span>=<span class="st0">"/numberservice"</span> <span class="re0">serviceClass</span>=<span class="st0">"com.tsolak.numberservice.NumberService"</span> <span class="re0">endpointName</span>=<span class="st0">"e:NumberService"</span> 
<span class="re0">serviceName</span>=<span class="st0">"s:NumberService"</span> xmlns:<span class="re0">e</span>=<span class="st0">"http://service.jaxws.cxf.apache.org/endpoint"</span> xmlns:<span class="re0">s</span>=<span class="st0">"http://numberservice.tsolak.com"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;simple</span>:serviceBean<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;ref</span> <span class="re0">bean</span>=<span class="st0">"numberService"</span><span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/simple</span>:serviceBean<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/simple</span>:server<span class="re2">&gt;</span></span>

<span class="sc3"><span class="re1">&lt;/beans<span class="re2">&gt;</span></span></span></div>
</div>
</pre>
<p></p>
<p>Like in XFire with EJB article &#8220;numberService&#8221; bean can be replaced with EJB proxy in order to expose EJB as SOAP WebService.<br />
<br />
After deploying to Tomcat hit http://localhost:8080/number-services-webapp/numberservice?wsdl for autogenerated WSDL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=20</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mule+Maven+Eclipse</title>
		<link>http://www.tsolak.com/?p=18</link>
		<comments>http://www.tsolak.com/?p=18#comments</comments>
		<pubDate>Mon, 07 May 2007 19:10:33 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=18</guid>
		<description><![CDATA[<p>This article shows how to get Maven based Mule project to easily work within Eclipse without the need of constant redeployment to mule lib/user directory.</p>
<p>I will use &#8220;hello&#8221; sample project from Mule installation. </p>
<p>hello.zip contains modified &#8220;hello&#8221; Mule project
where I removed &#8220;.bat&#8221; file, commented out &#8220;version&#8221; tag in pom.xml to make maven build work, added [...]]]></description>
			<content:encoded><![CDATA[<p>This article shows how to get Maven based Mule project to easily work within Eclipse without the need of constant redeployment to mule lib/user directory.</p>
<p>I will use &#8220;hello&#8221; sample project from Mule installation. </p>
<p><a href="/software_engineering/mule_maven_eclipse/hello.zip">hello.zip</a> contains modified &#8220;hello&#8221; Mule project<br />
where I removed &#8220;.bat&#8221; file, commented out &#8220;version&#8221; tag in pom.xml to make maven build work, added dependency to vm and stream transports and put log4j.properties for easy access.<br />
<span id="more-18"></span></p>
<ol>
<li>
Run &#8220;mvn eclipse:eclipse&#8221; on your project to create Eclipse project from it and go to &#8220;File->Import->General\Existing Projects into Workspace&#8221; to import it into Eclipse.
</li>
<li>
Go-to Run->Run menu open &#8220;Run&#8221; dialog. It should look like this:<br />
<br />
<a href="/software_engineering/mule_maven_eclipse/sc1.gif"><br />
<img src="/software_engineering/mule_maven_eclipse/sc1.gif" height="90%" width="90%"/></a>
</li>
<li>
Now we need to create a new Java Application configuration that will launch Mule. Right click on &#8220;Java Application&#8221; node and select &#8220;New&#8221; you should see this:<br />
<br />
<a href="/software_engineering/mule_maven_eclipse/sc2.gif"><br />
<img src="/software_engineering/mule_maven_eclipse/sc2.gif" height="90%" width="90%"/></a>
</li>
<li>
<ul>
<li>
Type &#8220;mule-example-hello&#8221; in the &#8220;Name:&#8221; field.
</li>
<li>
For project click &#8220;Browse&#8221; and select the mule project you imported, in our case it will be &#8220;mule-example-hello&#8221;.
</li>
<li>
Type &#8220;org.mule.MuleServer&#8221; in &#8220;Main class:&#8221; field.
</li>
<li>
Check &#8220;Include libraries when searching for main class&#8221; and &#8220;Include inherited mains when searching for a main class&#8221;
</li>
</ul>
<p>After all it should look like this:<br />
<br />
<a href="/software_engineering/mule_maven_eclipse/sc3.gif"><br />
<img src="/software_engineering/mule_maven_eclipse/sc3.gif" height="90%" width="90%"/></a>
</li>
<li>
Select &#8220;Arguments&#8221; tab and type <em>&#8220;-config ${resource_loc}&#8221;</em> in &#8220;Program Arguments&#8221; field. Type <em>&#8220;-Dlog4j.configuration=file:///${project_loc}\log4j.properties&#8221;</em> in &#8220;VM Arguments&#8221; field for Mule to find the log4j config file.<br />
This assumes that log4j config file is in the root of the project (you can change the path to your own log4j config location).<br />
<br />
<a href="/software_engineering/mule_maven_eclipse/sc4.gif"><br />
<img src="/software_engineering/mule_maven_eclipse/sc4.gif" height="90%" width="90%"/></a>
</li>
<li>
Click &#8220;Close&#8221;.
</li>
<li>
Now to run mule ESB with desired mule config file select the desired config file and click run button in the toolbar.<br />
To bypass the config file selection change the &#8220;Program arguments&#8221; to <em>&#8220;-config ${project_loc}\conf\hello-config.xml&#8221;</em> to always run &#8220;hello-config.xml&#8221; configuration.
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=18</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DOJO+DWR+SPRING+AUTHENTICATION</title>
		<link>http://www.tsolak.com/?p=17</link>
		<comments>http://www.tsolak.com/?p=17#comments</comments>
		<pubDate>Fri, 15 Dec 2006 03:46:46 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=17</guid>
		<description><![CDATA[<p>Intro:</p>
<p>Download project &#8211; dwr-test.zip
Download WAR &#8211; dwr-test-war-1.0.0.war
Test (default weblogic install) &#8211; http://localhost:7001/dwr-test-war-1.0.0/test.html
When promted type user name &#8220;weblogic&#8221; password &#8220;weblogic&#8221; for default weblogic install.</p>
<p>

Screenshot.</p>
<p>This article shows how to implement pure AJAX application that does round trip communication to Java back end using custom DOJO widgets for client, DWR for JavaScript to Java communication and Spring that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Intro:</strong></p>
<p><strong><font color="red">Download project</font></strong> &#8211; <a href="/software_engineering/dojo_dwr_spring/dwr-test.zip">dwr-test.zip</a><br />
<strong><font color="red">Download WAR</font></strong> &#8211; <a href="/software_engineering/dojo_dwr_spring/dwr-test-war-1.0.0.war">dwr-test-war-1.0.0.war</a><br />
<strong><font color="red">Test (default weblogic install)</font></strong> &#8211; <a href="http://localhost:7001/dwr-test-war-1.0.0/test.html">http://localhost:7001/dwr-test-war-1.0.0/test.html</a><br />
<font color="red">When promted type user name &#8220;weblogic&#8221; password &#8220;weblogic&#8221; for default weblogic install.</font></p>
<p>
<a href="/software_engineering/dojo_dwr_spring/screenshot.gif"><img src="/software_engineering/dojo_dwr_spring/screenshot.gif"/></a><br />
<strong>Screenshot.</strong></p>
<p>This article shows how to implement pure AJAX application that does round trip communication to Java back end using custom DOJO widgets for client, DWR for JavaScript to Java communication and Spring that will manage back end Java objects.<br />
Full Maven2 project is provided for download.<br />
<strong><br />
There are two ways of building AJAX applications.</p>
<ul>
<li>
Single page approach where the AJAX application get loaded one into browser and all of subsequent server side communications are AJAX calls.
</li>
<li>
Multiage approach where it is more like MVC2 where each JSP page served back to browser contains AJAX components.
</li>
</ul>
<p>The approach I like and took is Single page (1) because its more natural to client/server development where the only thing passed in-between is data.<br />
But I wont be shy of using multi page approach if need arises.<br />
</strong><br />
<span id="more-17"></span><br />
The reason for technology choices:<br />
<br />
<strong>DOJO</strong> &#8211; a very comprehensive cross browser JavaScript framework with good<br />
support for packaging, AJAX, AOP like method interceptors, event handling and most<br />
important built in and custom widgets that can be composed together much like in Swing.<br />
<br />
<strong>DWR </strong> &#8211; you can use plain AJAX for client server communication or simply let<br />
DWR marshal your JavaScript object to Java.<br />
<br />
<strong>Spring</strong> &#8211; it is always my choice of Java integration/container framework.<br />
<br />
The project I put together is J2EE Web application which contain Java back end components and simple html file that will bootstrap our Dojo widget which in turn will use DWR to communicate back to Java backend (no JSP is involved).<br />
In addition I incorporated Servlet security to show how to authorize your Dojo app user against Java back end.</p>
<p><strong>DOJO:</strong><br />
<br />
In earlier Dojo releases no custom widget could have been developed outside of Dojo source package. This was fixed in latest releases where it is possible to move custom<br />
widget code base outside of Dojo package but with one restriction which is the custom package needs to share same parent directory as the Dojo package, like this:<br />
<br />
<em>js/dojo/src</em> (dojo packaging)<br />
<em>js/app/widget</em> (custom packaging)<br />
<br />
Dojos recommended packaging structure for custom widgets is &#8220;namespace/widget&#8221; directory structure. From above directory layout &#8220;app&#8221; is will be our namespace.<br />
Theoretically it is possible to have deeper directory structure for custom widgets after &#8220;app&#8221; directory but it never worked for me.<br />
For more information how to Dojo finds custom package look at &#8220;manifest.js&#8221; file under &#8220;app&#8221; directory and widgets themselves.<br />
Included with the sample project is non widget code that shows how to package non widget package outside of Dojo (yes it is different), it is under &#8220;js/app/common/data&#8221;.<br />
<br />
One of issues I had with Dojo is its documentation. Most of my time was spent on investigating widget API which is close to impossible with dynamic nature of JavaScript.<br />
The best place to get familiar with Dojo is DojoBook, to see Dojo widgets in action and how to use them look here <a href="http://archive.dojotoolkit.org/nightly/tests/widget/">http://archive.dojotoolkit.org/nightly/tests/widget/</a> (click on links that start with â€œtestâ€) and finally the discussion group can be found at <a href="http://news.gmane.org/gmane.comp.web.dojo.user">http://news.gmane.org/gmane.comp.web.dojo.user</a>.<br />
<br />
<strong>- dojo.debugDeep(obj)</strong> is quite a useful utility which will pop up dialog and allow to drill down the object properties. This helps a lot when you are dealing with object of unknown type.</p>
<p><strong>DWR:</strong><br />
What I like about DWR java support is that it is very straightforward (more like Spring Framework, I think it should be integrated more into Spring at some point).<br />
<br />
DWR allows different ways of exposing Java objects, one of which is exposing them through Spring context. For more info check out &#8220;WEB_INF/dwr.xml&#8221;,<br />
&#8220;WEB-INF/servlet-context.xml&#8221; and &#8220;web.xml&#8221; to see how DWR gets integrated with our  Service objects.<br />
Official DWR/Spring examples can be found here <a href="http://getahead.ltd.uk/dwr/server/spring">http://getahead.ltd.uk/dwr/server/spring</a>.<br />
<br />
In a nutshell we use DWR Servlet that will find Spring context previously loaded by configured Servlet Listener and automatically marshal JavaScript to Java calls<br />
probably using JSON underneath.<br />
<br />
<strong>Security &#8211; Authentication and Authorization:</strong><br />
<br />
JavaScript has always been regarded as a security issue. One of the main issues DWR lists is that anyone from outside can call Java objects which are exposed through DWR and JavaScript.<br />
Personally I consider this more of generic Web client/server security issue which is commonly solved in J2EE Web clients thought Servlet security model.<br />
Since our Dojo widgets are loaded from Servlet container we can secure them same way as we secure JSPs and Servlets. All we have to do is tell Servlet container<br />
to secure html file that bootstraps Dojo widgets so that when we first access it the container will prompt for user name/password.<br />
<br />
DWR can automatically pass &#8220;HttpServletRequest&#8221; object from which we can get logged in user for further authorization (check <a href="http://getahead.ltd.uk/dwr/server/javaapi">http://getahead.ltd.uk/dwr/server/javaapi</a> for more information). This does pollute Service interface but we have to threat this object more like JavaScript proxy which will delegate calls to actual Service object that contains actual business logic.<br />
Current implementation uses BASIC Servlet authentication but it should be easy to change it to FORM based and embed into our DOJO widget.</p>
<p><strong><font color="red">Download project</font></strong> &#8211; <a href="/software_engineering/dojo_dwr_spring/dwr-test.zip">dwr-test.zip</a><br />
<strong><font color="red">Download WAR</font></strong> &#8211; <a href="/software_engineering/dojo_dwr_spring/dwr-test-war-1.0.0.war">dwr-test-war-1.0.0.war</a><br />
<strong><font color="red">Test (default weblogic install)</font></strong> &#8211; <a href="http://localhost:7001/dwr-test-war-1.0.0/test.html">http://localhost:7001/dwr-test-war-1.0.0/test.html</a><br />
<font color="red">When promted type user name &#8220;weblogic&#8221; password &#8220;weblogic&#8221; for default weblogic install.</font></p>
<p><strong>Note:</strong><br />
Looks like Tomcat authentication does not like
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;role</span>-name<span class="re2">&gt;</span></span>*<span class="sc3"><span class="re1">&lt;/role</span>-name<span class="re2">&gt;</span></span></div>
</div>
<p> defined in web.xml.<br />
To get authentication working on Tomcat change
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;role</span>-name<span class="re2">&gt;</span></span>*<span class="sc3"><span class="re1">&lt;/role</span>-name<span class="re2">&gt;</span></span></div>
</div>
<p> to
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;role</span>-name<span class="re2">&gt;</span></span>user<span class="sc3"><span class="re1">&lt;/role</span>-name<span class="re2">&gt;</span></span></div>
</div>
<p>in web.xml and add &#8220;user&#8221; to &#8220;conf/tomcat-users.xml&#8221; like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">&#8216;1.0&#8242;</span> <span class="re0">encoding</span>=<span class="st0">&#8216;utf-8&#8242;</span>?<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;tomcat</span>-users<span class="re2">&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;role</span> <span class="re0">rolename</span>=<span class="st0">&#8220;manager&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;role</span> <span class="re0">rolename</span>=<span class="st0">&#8220;admin&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;role</span> <span class="re0">rolename</span>=<span class="st0">&#8220;user&#8221;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;user</span> <span class="re0">username</span>=<span class="st0">&#8220;user&#8221;</span> <span class="re0">password</span>=<span class="st0">&#8220;user&#8221;</span> <span class="re0">roles</span>=<span class="st0">&#8220;user&#8221;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/tomcat</span>-users<span class="re2">&gt;</span></span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Maven Run/Build Plugin 2</title>
		<link>http://www.tsolak.com/?p=16</link>
		<comments>http://www.tsolak.com/?p=16#comments</comments>
		<pubDate>Thu, 28 Sep 2006 02:38:32 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=16</guid>
		<description><![CDATA[<p>maven-run-plugin-1.0.jar</p>
<p>This is a simplified and more flexible version of build plugin.</p>
<p>This plugin allows to execute specified goals on all project and sub projects under current base directory.</p>
<p>The plugin is using &#8220;maven.multiproject.type&#8221; and &#8220;command&#8221; property to determine project and command types in order to execure appropriate list of goals.</p>
<p>The plugin will append the value specified in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tsolak.com//software_engineering/maven/maven-run-plugin-1.0.jar">maven-run-plugin-1.0.jar</a></p>
<p>This is a simplified and more flexible version of <a href="http://www.tsolak.com/?p=14">build plugin</a>.</p>
<p>This plugin allows to execute specified goals on all project and sub projects under current base directory.</p>
<p>The plugin is using &#8220;maven.multiproject.type&#8221; and &#8220;command&#8221; property to determine project and command types in order to execure appropriate list of goals.</p>
<p>The plugin will append the value specified in &#8220;maven.multiproject.type&#8221; and &#8220;command&#8221; properties to &#8220;.goals&#8221; to get list of maven goals to run.<br />
<span id="more-16"></span></p>
<p>NOTE: There should not be any space in goals or ignore failures list.</p>
<p>Use cases:</p>
<p>1. Command specified but no goals and ignore failurs are specified. The command will be used as goal name.</p>
<p>   #Goal<br />
   maven -Dcommand=clean run</p>
<p>   #Property Files (build.properties or project.properties at base or parent level)<br />
   Nothing</p>
<p>   OR</p>
<p>   #Goal<br />
   maven run</p>
<p>   #Property Files (build.properties or project.properties at base or parent level)<br />
   command=clean    </p>
<p>   Will run clean goal on base and sub projects.</p>
<p>2. Command, goals and ingnore failures are specified.</p>
<p>   #Goal<br />
   maven -Dcommand=build run</p>
<p>   #Property Files (build.properties or project.properties at base or parent level)<br />
   jar.build.goals = clean,jar:jar,jar:install<br />
   ejb.build.goals = clean,ejb:ejb,ejb:install<br />
   war.build.goals = clean,war:war,war:install<br />
   ear.build.goals = clean,ear:ear,ear:install</p>
<p>   OR</p>
<p>   #Goal<br />
   maven run</p>
<p>   #Property Files (build.properties or project.properties at base or parent level)<br />
   command=build<br />
   jar.build.goals = clean,jar:jar,jar:install<br />
   ejb.build.goals = clean,ejb:ejb,ejb:install<br />
   war.build.goals = clean,war:war,war:install<br />
   ear.build.goals = clean,ear:ear,ear:install</p>
<p>   Will run &#8220;clean&#8221; ,&#8221;jar:jar&#8221; and &#8220;jar:install&#8221; on jar project, &#8220;clean&#8221; ,<br />
   &#8220;ejb:ejb&#8221; and &#8220;ejb:install&#8221; on ejb project an same for war and ear.</p>
<p>3. If &#8220;command&#8221; or &#8220;maven.multiproject.type&#8221; are not specified the plugin will<br />
   replace them with empty string.<br />
   The following will achieve same as above, since command is not specified it<br />
   is replaced with empty string in goals:</p>
<p>   #Goal<br />
   maven run</p>
<p>   #Property Files (build.properties or project.properties at base or parent level)<br />
   jar..goals = clean,jar:jar,jar:install<br />
   ejb..goals = clean,ejb:ejb,ejb:install<br />
   war..goals = clean,war:war,war:install<br />
   ear..goals = clean,ear:ear,ear:install</p>
<p>4. Optionally you can specify the &#8220;ignore.failures&#8221; property which will be used during maven reactor. For example the first goal will be run with ignoreFailures=true the rest with ignoreFailures=false</p>
<p>   jar.build.goals = clean,jar:jar,jar:install<br />
   jar.build.ignore.failures = true,false,false</p>
<p>5. If ignore is omitted for particular goal it will be replaced with last ignore. For example this will acieve the same as above:</p>
<p>   jar.build.goals = clean,jar:jar,jar:install<br />
   jar.build.ignore.failures = true,false</p>
<p>6. If nothing is specified or is undefined in ignore failures list<br />
   it will be replaced with &#8220;true&#8221; value:<br />
   For example these two will acieve the same as above:</p>
<p>   jar.build.goals = clean,jar:jar,jar:install<br />
   jar.build.ignore.failures = ,false,false</p>
<p>   OR </p>
<p>   jar.build.goals = clean,jar:jar,jar:install<br />
   jar.build.ignore.failures = fsdfdsf,false,false</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=16</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XFIRE+EJB+POJO</title>
		<link>http://www.tsolak.com/?p=15</link>
		<comments>http://www.tsolak.com/?p=15#comments</comments>
		<pubDate>Sat, 26 Aug 2006 06:04:08 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=15</guid>
		<description><![CDATA[<p>Full Maven Project.</p>
<p>This article brings together Spring and XFire configuration examples to show how to expose simple POJO into SOAP service with EJB faÃ§ade in between.

Lets take a simple example of number add and subtract service.

Here is component diagram of what we are trying to achieve.


</p>
<p>To accomplish the above setup we&#8217;ll follow these simple steps.

Create [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/software_engineering/xfire/numberservice.zip">Full Maven Project</a>.</p>
<p>This article brings together Spring and XFire configuration examples to show how to expose simple POJO into SOAP service with EJB faÃ§ade in between.<br />
<br />
Lets take a simple example of number add and subtract service.<br />
<br />
Here is component diagram of what we are trying to achieve.<br />
<span id="more-15"></span><br />
<br />
<a href="/software_engineering/xfire/xfireejbpojo.gif"><img src="/software_engineering/xfire/xfireejbpojo.gif" height="50%" width="50%"/></a></p>
<p>To accomplish the above setup we&#8217;ll follow these simple steps.<br />
<br />
<strong>Create NumberService interface and implementation.</strong><br />
</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">public</span> <span class="kw2">interface</span> NumberService<span class="br0">&#123;</span>

&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> add<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span>;
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> substract<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span>;
<span class="br0">&#125;</span>&nbsp; 

<span class="kw2">public</span> <span class="kw2">class</span> NumberServiceImpl <span class="kw2">implements</span> NumberService<span class="br0">&#123;</span>

&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> add<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw2">return</span> n1 + n2;
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> substract<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw2">return</span> n1 - n2;
&nbsp;<span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>
<strong>Create app-context.xml (you can name this file anything you want).</strong><br />
<br />
Since we are using Spring Framework it just makes sense to define the NumberServiceImpl in spring context file to be later injected into NumberServiceSessionBean. This will allow us to decouple<br />
NumberServiceSessionBean from  NumberServiceImpl. Here is the full context file called app-context.<br />
</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">"1.0"</span> <span class="re0">encoding</span>=<span class="st0">"UTF-8"</span>?<span class="re2">&gt;</span></span>
<span class="sc0">&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;</span>
<span class="sc3"><span class="re1">&lt;beans<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">name</span>=<span class="st0">"numberService"</span> <span class="re0">class</span>=<span class="st0">"NumberServiceImpl"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;/beans<span class="re2">&gt;</span></span></span></div>
</div>
</pre>
<p>Make sure this file is in classpath for EJB to load.<br />
<br />
<strong>Create NumberServiceSessionBean</strong><br />
</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="co2">import java.rmi.RemoteException;</span>
<span class="co2">import javax.ejb.CreateException;</span>

<span class="co2">import org.springframework.ejb.support.AbstractStatelessSessionBean;</span>

<span class="kw2">public</span> <span class="kw2">class</span> NumberServiceSessionBean <span class="kw2">extends</span> AbstractStatelessSessionBean<span class="br0">&#123;</span>&nbsp; 
&nbsp;<span class="kw2">private</span> NumberService numberService = <span class="kw2">null</span>;
&nbsp;
&nbsp;<span class="kw2">protected</span> <span class="kw4">void</span> onEjbCreate<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> CreateException<span class="br0">&#123;</span>
&nbsp; numberService = <span class="br0">&#40;</span>NumberService<span class="br0">&#41;</span>getBeanFactory<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getBean</span><span class="br0">&#40;</span><span class="st0">"numberService"</span><span class="br0">&#41;</span>;
&nbsp;<span class="br0">&#125;</span>

&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> add<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span> <span class="kw2">throws</span> <a href="http://www.google.com/search?q=allinurl%3ARemoteException+java.sun.com&#038;bntl=1"><span class="kw3">RemoteException</span></a> <span class="br0">&#123;</span>
&nbsp; <span class="kw2">return</span> numberService.<span class="me1">add</span><span class="br0">&#40;</span>n1, n2<span class="br0">&#41;</span>;
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> substract<span class="br0">&#40;</span><span class="kw4">int</span> n1, <span class="kw4">int</span> n2<span class="br0">&#41;</span> <span class="kw2">throws</span> <a href="http://www.google.com/search?q=allinurl%3ARemoteException+java.sun.com&#038;bntl=1"><span class="kw3">RemoteException</span></a> <span class="br0">&#123;</span>
&nbsp; <span class="kw2">return</span> numberService.<span class="me1">substract</span><span class="br0">&#40;</span>n1, n2<span class="br0">&#41;</span>;
&nbsp;<span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
<p>
Here are few things worth to mention.<br />
</p>
<ul>
<li>
It extends Spring helper AbstractStatelessSessionBean class which will load spring context behind the scene and expose it through<br />
<em>BeanFactory getBeanFactory()</em> method.<br />
Some might ask how it knows which context file to load? Well in order to tell the AbstractStatelessSessionBean the location of context file we need to define it in EJB deployment (called ejb-jar.xml ) file like this.</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;br<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;env</span>-entry<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;env</span>-entry-name<span class="re2">&gt;</span></span>ejb/BeanFactoryPath<span class="sc3"><span class="re1">&lt;/env</span>-entry-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;env</span>-entry-type<span class="re2">&gt;</span></span>java.lang.String<span class="sc3"><span class="re1">&lt;/env</span>-entry-type<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;env</span>-entry-value<span class="re2">&gt;</span></span><span class="sc2">&lt;![CDATA[app-context.xml]]&gt;</span><span class="sc3"><span class="re1">&lt;/env</span>-entry-value<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/env</span>-entry<span class="re2">&gt;</span></span></div>
</div>
</pre>
</li>
<p></p>
<li>
Each NumberServiceSessionBean instance will load context file separately and will have its own instance of NumberServiceImpl.
</li>
<p></p>
<li>
It does not directly implement NumberService but implements the exact methods. The reason behind this is two-part. First it is the infamous issues of the need to declare  RemoteException in NumberService. Second one will be explainined later when we expose it as proxy to Xfire servlet.
</li>
</ul>
<p>
<strong>Create XFire web component.</strong><br />
For XFire to be able to receive SOAP calls we need to configure it as Servlet.<br />
<br />
What we are going to do is again leverage Spring Framework by reusing its org.springframework.web.servlet.DispatcherServlet and expose XFire to it as Spring MVC controller.<br />
<br />
The good news is that XFire already provides implementation of this controller in &#8220;org.codehaus.xfire.spring.remoting.XFireExporter&#8221; class.</p>
<p>
To have complete web application we need to create web.xml and Spring nameservice-context.xml file that will contain Controller and EJB proxy definitions.<br />
Put both under WEB-INF directory.<br />
<br />
<strong>web.xml</strong><br />
</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc0">&lt;!DOCTYPE web-app PUBLIC
&nbsp;&quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; &gt;</span>

<span class="sc3"><span class="re1">&lt;web</span>-app<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;display</span>-name<span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;/display</span>-name<span class="re2">&gt;</span></span>

<span class="sc3"><span class="re1">&lt;servlet<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>nameservice<span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;servlet</span>-class<span class="re2">&gt;</span></span>
org.springframework.web.servlet.DispatcherServlet
<span class="sc3"><span class="re1">&lt;/servlet</span>-class<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;load</span>-on-startup<span class="re2">&gt;</span></span>1<span class="sc3"><span class="re1">&lt;/load</span>-on-startup<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/servlet<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;servlet</span>-mapping<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;servlet</span>-name<span class="re2">&gt;</span></span>nameservice <span class="sc3"><span class="re1">&lt;/servlet</span>-name<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;url</span>-pattern<span class="re2">&gt;</span></span>/*<span class="sc3"><span class="re1">&lt;/url</span>-pattern<span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/servlet</span>-mapping<span class="re2">&gt;</span></span>
&nbsp; 
<span class="sc3"><span class="re1">&lt;/web</span>-app<span class="re2">&gt;</span></span></div>
</div>
</pre>
<p>Once deployed and loaded in Servlet container DispatcherServlet will assume there is Spring context file under WEB-INF directory with name {servlet-name}-servlet.xml<br />
which is in our case nameservice-servlet.xml.<br />
<br />
<strong>nameservice-servlet.xml</strong></p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">"1.0"</span> <span class="re0">encoding</span>=<span class="st0">"UTF-8"</span>?<span class="re2">&gt;</span></span>
<span class="sc0">&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;</span>
<span class="sc3"><span class="re1">&lt;beans<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="coMULTI">&lt;!-- include xfire specific beans --&gt;</span></span>
<span class="sc3"><span class="re1">&lt;import</span> <span class="re0">resource</span>=<span class="st0">"classpath:org/codehaus/xfire/spring/xfire.xml"</span><span class="re2">/&gt;</span></span>

<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">"NameServiceSessionBeanProxy"</span> 
<span class="re0">class</span>=<span class="st0">"org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"jndiName"</span><span class="re2">&gt;</span></span>

<span class="sc3"><span class="coMULTI">&lt;!-- this name depends on how you bind your EJB. Usually it is by
its Home package name --&gt;</span></span>

<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>NameServiceSessionHome<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"jndiEnvironment"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;props<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;prop</span> <span class="re0">key</span>=<span class="st0">"java.naming.factory.initial"</span><span class="re2">&gt;</span></span>weblogic.jndi.WLInitialContextFactory<span class="sc3"><span class="re1">&lt;/prop<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/props<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"resourceRef"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="coMULTI">&lt;!-- Set this property to false so that to avoid not finding NameServiceSessionBean when servlet is deployed prior to NameServiceSessionBean is deployed --&gt;</span></span>

<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"lookupHomeOnStartup"</span><span class="re2">&gt;</span></span> 
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"businessInterface"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>NameService<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">"NameServiceSessionWS"</span> <span class="re0">class</span>=<span class="st0">"org.codehaus.xfire.spring.remoting.XFireExporter"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"style"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>rpc<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"use"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>encoded<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"serviceFactory"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;ref</span> <span class="re0">bean</span>=<span class="st0">"xfire.serviceFactory"</span><span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"xfire"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;ref</span> <span class="re0">bean</span>=<span class="st0">"xfire"</span><span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"serviceBean"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;ref</span> <span class="re0">bean</span>=<span class="st0">"NameServiceSessionBeanProxy"</span><span class="re2">/&gt;</span></span>

&nbsp;<span class="sc3"><span class="coMULTI">&lt;!-- Here we cheat XFireExporter into thinking that it is dealing with simple NameService POJO --&gt;</span></span>

<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"serviceInterface"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;value<span class="re2">&gt;</span></span></span>NameService<span class="sc3"><span class="re1">&lt;/value<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="coMULTI">&lt;!-- DispatcherServlet will always invoke NameServiceSessionWS controller when URL ends with &quot;nameservice&quot; --&gt;</span></span>
<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">class</span>=<span class="st0">"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;property</span> <span class="re0">name</span>=<span class="st0">"urlMap"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;map<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;entry</span> <span class="re0">key</span>=<span class="st0">"/nameservice"</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;ref</span> <span class="re0">bean</span>=<span class="st0">"NameServiceSessionWS"</span><span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/entry<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/map<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/property<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span>

<span class="sc3"><span class="re1">&lt;/beans<span class="re2">&gt;</span></span></span></div>
</div>
</pre>
<p>
Finally to test your WebService invoke http://localhost:7001/nameservice?wsdl which will generate the WSDL.<br />
<br />
Included with the war project is JUnit test that uses Spring and XFireClientFactoryBean to remotely call XFire service using Spring and XFire proxies. For more detailed tutorial<br />
on XFireClientFactoryBean check <a href="http://xfire.codehaus.org/Spring+Remoting">http://xfire.codehaus.org/Spring+Remoting</a>.<br />
<br />
The unit test requires &#8220;commons http client&#8221; libraries, so make sure to include them as dependencies in your war as is done in attached maven projects.<br />
<br />
Full maven project can be downloaded from <a href="/software_engineering/xfire/numberservice.zip">HERE</a>.<br />
<br />
<strong>Build Instructions</strong><br />
</p>
<ul>
<li>
This project is based on Maven2. Currently standard Maven2 remote repositories dont have xfire-all-1.2.2.jar. You might need to manually get it from <a href="http://xfire.codehaus.org/Download">here</a> and put into your local repository under xfire\xfire-all\1.2 directory.
</li>
<p></p>
<li>
If you are going to deploy it to Weblogic it wont work unless resolve QName issue as shown <a href="http://xfire.codehaus.org/XFire+on+Weblogic+8.1">here</a>.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Maven Build Plug-In</title>
		<link>http://www.tsolak.com/?p=14</link>
		<comments>http://www.tsolak.com/?p=14#comments</comments>
		<pubDate>Thu, 17 Aug 2006 02:25:18 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=14</guid>
		<description><![CDATA[<p>maven-build-plugin-1.0.jar</p>
<p>Please use improved version of this plugin from this post.</p>
<p>This pugin will allow to run single command on one or set of maven projects to build or deploy them instead of doing separate maven goals on each project. This will even work inside a single project as well as on root project containing sub-projects.
The only [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tsolak.com//software_engineering/maven/maven-build-plugin-1.0.jar">maven-build-plugin-1.0.jar</a></p>
<p>Please use improved version of this plugin from this <a href="http://www.tsolak.com/?p=16">post</a>.</p>
<p>This pugin will allow to run single command on one or set of maven projects to build or deploy them instead of doing separate maven goals on each project. This will even work inside a single project as well as on root project containing sub-projects.<br />
The only requirement is to have &#8220;maven.multiproject.type&#8221; property defined in each project.<br />
<br />
Generic plugin which provides build and deploy goals that can be customized to run list of maven goals across maven projects using maven:rector.<br />
The plugin is using &#8220;maven.multiproject.type&#8221; property to determine project type in order to execute appropriate list of commands.<br />
The plugin will append the value specified in &#8220;maven.multiproject.type&#8221; to &#8220;.build.commands&#8221; and &#8220;.deploy.commands&#8221; to get list of maven goals to run.<br />
For example here is the list of default goals to be run when doing build on jar, ejb, war and ear:<br />
<br />
jar.build.commands = clean,jar:jar,jar:install<br />
ejb.build.commands = clean,ejb:ejb,ejb:install<br />
war.build.commands = clean,war:war,war:install<br />
ear.build.commands = clean,ear:ear,ear:install<br />
<br />
The properties can be customized in project.properties to add/remove goals.<br />
<br />
There are no deploy commands defined by default. The deploy goals are specific to the project and need to be defined in build.properties or project.properties.<br />
For example it would make sense to have ear.deploy.commands = weblogic:undeploy,weblogic:deploy property ser in root project.properties.</p>
<ul>
<li>
<strong>build </strong>- will execute ${maven.multiproject.type}.build.commands on<br />
        each project under base directory. Will stop on first build failure.
</li>
<p></p>
<li>
<strong>deploy </strong>- will execute ${maven.multiproject.type}.deploy.commands on<br />
         each project under base directory. Wont stop on failure.
</li>
<p></p>
<li>
<strong>build-deploy</strong> &#8211; will execute ${maven.multiproject.type}.deploy.commands and<br />
               ${maven.multiproject.type}.deploy.commands on<br />
               each project under base directory. Will only stop on first build failure,<br />
               deploy failures will be ignored.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=14</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Map Object.</title>
		<link>http://www.tsolak.com/?p=13</link>
		<comments>http://www.tsolak.com/?p=13#comments</comments>
		<pubDate>Fri, 04 Aug 2006 01:34:01 +0000</pubDate>
		<dc:creator>Tsolak Petrosian</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.tsolak.com/?p=13</guid>
		<description><![CDATA[<p>Have you wished you could attach arbitrary data to plain any Java object during the runtime? I have and not once or twice.

Something like adding these two methods &#8220;get(Object key)&#8221; and &#8220;put(Object key, Object data)&#8221;.

This often happens when objects, while interacting, need to associate arbitrary data with each other without having the appropriate get/set methods [...]]]></description>
			<content:encoded><![CDATA[<p>Have you wished you could attach arbitrary data to plain any Java object during the runtime? I have and not once or twice.<br />
<br />
Something like adding these two methods &#8220;get(Object key)&#8221; and &#8220;put(Object key, Object data)&#8221;.<br />
<br />
This often happens when objects, while interacting, need to associate arbitrary data with each other without having the appropriate get/set methods for that data.<br />
<br />
During my past experience I have encountered quite a number of scenarios (some of which are described below) requiring that capability with the only solution of having custom sub type of object with addition of those two methods.<br />
</p>
<ul>
<li>
Caching. In high volume transaction environment where thousands of short lived event objects go thought the system components it might be best to have the components associate the data they retrieve for that event to the event itself instead of caching internally with the reference to that event and later going through the trouble of identifying dead events for cleanup.
</li>
<p></p>
<li>
Identification. Again instead of storing reference to the object internally for later identification the component can associate ID data to the object itself, something like passport in real life..
</li>
</ul>
<p>
This has been partially influenced by Servlet API session/request objects with the similar functionalities (which are the most heavily relied upon methods in any Servlet based application written on the earth).<br />
Like in case of Servlet session object it can also be misused.</p>
<p><span id="more-13"></span></p>
<p><strong>Sample Code.</strong></p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1">// Our object replacement.</span>

<span class="kw2">public</span> <span class="kw2">class</span> MapObject <span class="kw2">extends</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a><span class="br0">&#123;</span>
&nbsp;<span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AMap+java.sun.com&#038;bntl=1"><span class="kw3">Map</span></a> dataMap = <span class="kw2">null</span>;
&nbsp;
&nbsp;<span class="co1">// Map methods</span>
&nbsp;<span class="co1">// The lazy loading can fine tuned further (ie creating HashMap only after 2-4 call to putData)</span>
&nbsp;<span class="co1">// Depending on the environment need to be synchronized. If dealing with POJOs behind EJB facade</span>
&nbsp;<span class="co1">// no need to synchronize.</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> getData<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> key<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>dataMap == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">null</span>;
&nbsp; <span class="kw2">return</span> dataMap.<span class="me1">get</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span>;
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;punlic <span class="kw4">void</span> putData<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> key, <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> data<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>dataMap == <span class="kw2">null</span><span class="br0">&#41;</span> dataMap = <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AHashMap+java.sun.com&#038;bntl=1"><span class="kw3">HashMap</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp; dataMap.<span class="me1">put</span><span class="br0">&#40;</span>key, data<span class="br0">&#41;</span>;
&nbsp;<span class="br0">&#125;</span>
<span class="br0">&#125;</span>


<span class="co1">// Application specific code</span>


<span class="kw2">public</span> <span class="kw2">class</span> <a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a> <span class="kw2">extends</span> MapObject<span class="br0">&#123;</span>
&nbsp;<span class="kw2">private</span> <span class="kw4">int</span> id = -<span class="nu0">1</span>;
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw4">int</span> getId<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw2">return</span> id;
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw4">void</span> setId<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <span class="kw2">this</span>.<span class="me1">id</span> = id;
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="co1">//other event methods</span>
<span class="br0">&#125;</span>


<span class="kw2">public</span> <span class="kw2">interface</span> EventOwnerManager<span class="br0">&#123;</span>

&nbsp;<span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AOwner+java.sun.com&#038;bntl=1"><span class="kw3">Owner</span></a> getOwner<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a> event<span class="br0">&#41;</span>; 

<span class="br0">&#125;</span>


<span class="kw2">public</span> <span class="kw2">class</span> EventOwnerManagerImpl<span class="br0">&#123;</span>
&nbsp;<span class="kw2">private</span> <span class="kw4">static</span> <span class="kw2">final</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> OWNER_KEY = EventOwnerManagerImpl.<span class="kw2">class</span> + <span class="st0">"owner"</span>;
&nbsp;
&nbsp;<span class="co1">// similarly synchronization should be handled as needed</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AOwner+java.sun.com&#038;bntl=1"><span class="kw3">Owner</span></a> getOwner<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a> event<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp; <a href="http://www.google.com/search?q=allinurl%3AOwner+java.sun.com&#038;bntl=1"><span class="kw3">Owner</span></a> owner = event.<span class="me1">getData</span><span class="br0">&#40;</span>OWNER_KEY<span class="br0">&#41;</span>;
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>owner == <span class="kw2">null</span><span class="br0">&#41;</span> event.<span class="me1">putData</span><span class="br0">&#40;</span> OWNER_KEY, owner = longGetOwner<span class="br0">&#40;</span>event<span class="br0">&#41;</span> <span class="br0">&#41;</span>;
&nbsp; <span class="kw2">return</span> owner;&nbsp; 
&nbsp;<span class="br0">&#125;</span>
<span class="br0">&#125;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tsolak.com/?feed=rss2&amp;p=13</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
