<?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>CarbonRider &#187; Spring</title>
	<atom:link href="http://www.carbonrider.com/tag/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.carbonrider.com</link>
	<description>You make a matrix, you define the limits.</description>
	<lastBuildDate>Thu, 19 Jan 2012 04:35:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring &#8211; Hibernate Annotation &#8211; Entity classes in JAR not recognised [XXX is not mapped]</title>
		<link>http://articles.carbonrider.com/2011/02/27/spring-hibernate-annotation-entity-classes-in-jar-not-recognised-xxx-is-not-mapped/</link>
		<comments>http://articles.carbonrider.com/2011/02/27/spring-hibernate-annotation-entity-classes-in-jar-not-recognised-xxx-is-not-mapped/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 14:02:43 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Annotated Entity]]></category>
		<category><![CDATA[AnnotationSessionFactoryBean]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Hibernate Annotation]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring ORM]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=458</guid>
		<description><![CDATA[Spring provides options to integrate many ORM frameworks available in Market and one of them is Hibernate. With the options like configuring SessionFactory and HibernateTemplate, it makes developer&#8217;s life smooth to integrate other cross cutting concerns. Amongst all the other features, Spring provides a convenient feature is to autodetect &#8220;Annotated&#8221; Entity classes from package(s) using [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Farticles.carbonrider.com%2F2011%2F02%2F27%2Fspring-hibernate-annotation-entity-classes-in-jar-not-recognised-xxx-is-not-mapped%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Farticles.carbonrider.com%2F2011%2F02%2F27%2Fspring-hibernate-annotation-entity-classes-in-jar-not-recognised-xxx-is-not-mapped%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Spring provides options to integrate many ORM frameworks available in Market and one of them is Hibernate. With the options like configuring SessionFactory and HibernateTemplate, it makes developer&#8217;s life smooth to integrate other cross cutting concerns. Amongst all the other features, Spring provides a convenient feature is to autodetect &#8220;Annotated&#8221; Entity classes from package(s) using helper bean &#8220;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&#8221;. The package(s) name can be injected using setter method &#8220;packagesToScan&#8221;. Set the value of this property to the package name where you place the Entity classes and you are good to go. No need to add entry for every *-hbm.xml file OR explicitly configuring annotated classes.</p>
<p>But recently I came across a problem, wherein I found that my application&#8217;s Entity classes were not detected and when I was querying, hibernate was simply throwing an error as &#8220;XXX is not mapped&#8221;.<br />
<span id="more-458"></span><br />
Well after struggling for almost an hour and checking out all the configuration, it was not visible as what was causing the problem [almost clueless <img src='http://www.carbonrider.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ]. The next step was (obvious) jump into the Spring code and checking out what went wrong. Aha! that really helped and I found the reason why Spring was not able to detect Entity classes. The &#8220;AnnotationSessionFactoryBean&#8221; class internally prefixes packages with &#8220;classpath*:&#8221; protocol before searching them and as stated in Spring documentation due to bug in JDK classloader the underlying classloader used by Spring to load resources is not able to recognise files kept within Jar. (mine were kept inside JAR and not in exploded format.). Though the application deployed was a Web Application which creates XmlWebApplicationContext and internally uses &#8220;ServletContextResourcePatternResolver&#8221; to resolve classes (Resolves resources insdie JAR file), was simply failing due to the fact of having prefix &#8220;classpath*:&#8221;</p>
<p>Having no provision to override this behaviour of &#8220;AnnotationSessionFactoryBean&#8221;, I thought of extending the class and added a method to use prefix for loading resources. Also I had to override the scanPackages method to use custom logic for loading resoruces. To load the resources from JAR you need to use inject path as WEB-INF/lib/*.jar!/com.abc. Note the &#8220;!/&#8221; in path, Spring makes use of this delimiter to identify the JAR and the resource path. After deploying the change, I found that Spring was now able to autodetect the Entity from JAR.</p>
]]></content:encoded>
			<wfw:commentRss>http://articles.carbonrider.com/2011/02/27/spring-hibernate-annotation-entity-classes-in-jar-not-recognised-xxx-is-not-mapped/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Webservice Session Maintenance &#8211; Apache CXF, Blaze DS, Spring and Flex</title>
		<link>http://articles.carbonrider.com/2009/11/22/apache-cxf-blaze-ds-spring-and-flex/</link>
		<comments>http://articles.carbonrider.com/2009/11/22/apache-cxf-blaze-ds-spring-and-flex/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 13:50:15 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[CXF]]></category>
		<category><![CDATA[Flex Session]]></category>
		<category><![CDATA[JAX-WS client session]]></category>
		<category><![CDATA[Session maintenance across webservice client]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=157</guid>
		<description><![CDATA[If Flex is dominting RIA world, CXF is dominating SOA world with its feature rich framework. CXF not only makes developers life easy by abstracting many complex task through a set of APIs but also adheres to WS-* standards without a need to having dependency on other frameworks. On an average to develop a webservices [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Farticles.carbonrider.com%2F2009%2F11%2F22%2Fapache-cxf-blaze-ds-spring-and-flex%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Farticles.carbonrider.com%2F2009%2F11%2F22%2Fapache-cxf-blaze-ds-spring-and-flex%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If Flex is dominting RIA world, CXF is dominating SOA world with its feature rich framework. CXF not only makes developers life easy by abstracting many complex task through a set of APIs but also adheres to WS-* standards without a need to having dependency on other frameworks.</p>
<p><span id="more-157"></span></p>
<p>On an average to develop a webservices using CXF, would hardly require 5 minutes (If developers use Code First Approach). Developer need to declare a business interface, implementation class for same and annotate both these entities with JAX-WS annotation, configure the webeservice and pufff, you are done. You don&#8217;t even need to run Webservices, plug the configuration with built-in web container and you can test Webservices right from your IDE.</p>
<p>Well to explain all the features of CXF, this articles won&#8217;t be enough (I would rather end up writing 1000&#8242;s of pages.). While working on one of the project involving CXF, Blaze DS, Spring and Flex, we faced one problem and that turned out to be worst nightmare. We had created a set of webservices exposed through CXF and deployed with its own WAR file. On the other hand, we had created one more application, holding Flex SWF files, JAX-WS client configured through CXF &#8211; Spring configuration in XML. The clients were injected in Remoting Destination, using SPRING dependency injection feature. Finally the remoting destinations were exposed through SPRING &#8211; Blaze DS integration project.</p>
<p>So far, everything worked well except one problem, each time remoting destination invokes webservice operation, a new session was getting created and hence webservices were not able to maintain state of the Client.</p>
<p>After visiting to various forums and going through the CXF documentation we found that, CXF does provide a way to maintain session and same is explained at</p>
<ul>
<li><a href="http://stackoverflow.com/questions/1741314/jaxwsproxyfactorybean-sharing-http-session">http://stackoverflow.com/questions/1741314/jaxwsproxyfactorybean-sharing-http-session</a> (Check first reply, second reply provided by me for handler does work perfectly.)</li>
<li><a href="http://www.theserverside.com/news/thread.tss?thread_id=40839">http://www.theserverside.com/news/thread.tss?thread_id=40839</a></li>
</ul>
<p>While both the approach are able to maintain session at client side, it requires that the client code should be aware of webservices API. In our case, since JAXWS:Client was injected through SPRING configuration, making beans aware of WS API would break the architecture. Also using both the above discussed approach are having there own problem, first solution will not be suitable if the number of webservices is huge. This means it would require tracking all the webservices in application. Second approach works well for a single webservice, the moment you use another webservice of same application, voilaaa.. you will see a new session is again created.</p>
<p>Well, we didnt had an option but to somehow maintain session between WS-Client and WS. A thought came in my mind to check how CXF maintains session for a single webservice using BindingProvider, I started going through <a title="HTTPConduit" href="http://www.docjar.com/html/api/org/apache/cxf/transport/http/HTTPConduit.java.html" target="_blank">HTTPConduit</a>.</p>
<p>After carefully reading the source code, I realised that if I could able to add Message.PROTOCOL_HEADERS to every webservice context in a generic way, my job is done. Adding Message.PROTOCOL_HEADERS to webservice context, gives developer a chance to play with HTTP headers. I developed a JAX-WS handler and tracked the request/response for every webservice invocation and added a logic to cofigure Message.PROTOCOL_HEADERS. And yippy!!! my webservice clients are now able to maintain session and that too without a need of modifying webservice client.</p>
<p>All I need to do is,</p>
<ol>
<li>Create JAX-WS handler and configure it in SPRING configuration file.</li>
<li>Add handler to Webservice client.</li>
<li>Use BlazeDS API to hold/retrieve reference of WS session cookies and play with Message.PROTOCOL_HEADERS.</li>
</ol>
<p>I like the extension points provided by CXF to accomplish tasks which are not so easily available in other frameworks.</p>
]]></content:encoded>
			<wfw:commentRss>http://articles.carbonrider.com/2009/11/22/apache-cxf-blaze-ds-spring-and-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring JMS API, JBoss MQ, BlazeDS &amp; Flex</title>
		<link>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/</link>
		<comments>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 15:34:37 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Blaze DS]]></category>
		<category><![CDATA[Flex Chatting]]></category>
		<category><![CDATA[Flex Messaging]]></category>
		<category><![CDATA[JBoss MQ]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Integration]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=122</guid>
		<description><![CDATA[This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application. Configuring JMS Topic in JBoss To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application.</p>
<p><strong>Configuring JMS Topic in JBoss</strong></p>
<p>To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new Topic Destination.</p>
<p><span id="more-122"></span></p>
<pre name="code" class="xml">
<mbean code="org.jboss.mq.server.jmx.Topic" name="jboss.mq.destination:service=Topic,name=MyTopic">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute name="SecurityConf">
<security>
<role name="guest" read="true" write="true" create="true"/>
</security>
</attribute>
</mbean>
</pre>
<p>Well in actual production system you should not configure guest role access with Read/write permission. Add above XML code snippet below &lt;server&gt; tag and save it. Start JBoss console and you should notice that JBoss will create new topic and bind it to JNDI with name as &#8220;topic/MyTopic&#8221; (Note this is generic JMS client configuration and doesn&#8217;t use any properitory JMS provider APIs. You will have to change the properties of jndiTemplate based on your Messaging Service Provider.)</p>
<p><strong>Using Spring API</strong></p>
<p>Now lets create client code to send messages. I assume that you are using Spring &#8211; BlazeDs integration project and aware of how to configure Spring configuration file with BlazeDS. The following code snippet must be defined in Spring configuration file. Make sure you have also imported Spring-Flex namespace.</p>
<pre  name="code" class="xml">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">localhost</prop>
<prop key="java.naming.factory.url.pkgs"> org.jnp.interfaces:org.jboss.naming </prop>
</props>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>java:/XAConnectionFactory</value>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"><ref bean="jndiTemplate"/></property>
<property name="jndiName"><value>topic/MyTopic</value></property>
</bean>
</pre>
<p>Now you can expose jmsDestination using flex:jms-message-destination tag. (Available with Spring-BlazeDS integration jar.)</p>
<pre name="code" class="xml">
<flex:jms-message-destination id="my-topic-jms"  jms-destination="jmsDestination" />
</pre>
<p><strong>Creating Flex Client</strong></p>
<p>We are done with the server side configuration and now its time to define Flex Client to subscribe to JMS topic. Flex comes with a handy tag as MX:Consumer and MX:Producer. MX:Consumer is useful to subscribe to JMS topics and queues, while MX:Producer by the name itself it is quite clear that this tag is used to publish messages to JMS. Declare following tag to subscribe to JMS topic</p>
<pre name="code" class="xml">
<mx:Consumer destination="my-topic-jms" id="messageConsumer" message="consumerMessageHandler(event)" fault="faultHandler(event)"/>
</pre>
<p>Note that in above example the value of destination attribute is exactly same as the value of id attribute defined for jms-message-destination tag. This still won&#8217;t start subscription to JMS topic and in order to start subscription you must explicitly subscribe to JMS topic by calling subscribe method  on MX:Consumer instance. Let assume that following function is invoked on &#8220;CreationComplete&#8221; event of application.</p>
<p>private function subscribeTopic():void<br />
{<br />
messageConsumer.subscribe();<br />
}</p>
<p>This will start subscription to JMS topic destination and keep on polling to message server for any new message. OK! but how you will receive message notification, notice there are two event handler defined with MX:Consumer tag declaration. And here is the code snippet of &#8220;message&#8221; event handler.</p>
<p>private function consumerMessageHandler(event:MessageEvent):void<br />
{</p>
<p>var msg:AsyncMessage = new AsyncMessage(event.message);<br />
Alert.show(ObjectUtil.toString(msg.body));<br />
}</p>
<p>This function just prints all the contents of the Message. If you are accessing Object style JMS message, the properties of such message can be accessed using &#8220;.&#8221; notation.</p>
<p><strong>Deployment</strong></p>
<p>Package all the generated SWFs and copy all the required files (JAR, XML configuration files etc) to a WAR file and deploy it on JBoss server. Hit your application URL and you should be able to receive any messages sent to JMS topic.</p>
<p><strong>Known Issue</strong></p>
<p>At the time of deployment, you might come across following exception being thrown by JBoss</p>
<p>: Failed to convert property value of type [org.jboss.mq.SpyXAConnectionFactory] to required type [javax.jms.ConnectionFactory] for property &#8216;connectionFactory&#8217;</p>
<p>Make sure that the deployed WAR file doesn&#8217;t contain and JMS-API library file. The above error is occurring due to ClassLoader issue but the error message is misleading.</p>
]]></content:encoded>
			<wfw:commentRss>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

