<?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>Ayone Blog &#187; Java</title>
	<atom:link href="http://ayonesoftware.com/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://ayonesoftware.com/blog</link>
	<description>Sharing ideas on Rich Internet Application Development</description>
	<lastBuildDate>Tue, 18 Aug 2009 06:40:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring BlazeDS Integration on top of SpringSource dm Server</title>
		<link>http://ayonesoftware.com/blog/2009/07/spring-blazeds-integration-on-top-of-springsource-dm-server/</link>
		<comments>http://ayonesoftware.com/blog/2009/07/spring-blazeds-integration-on-top-of-springsource-dm-server/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 11:56:26 +0000</pubDate>
		<dc:creator>Andrei Aioanei</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://ayonesoftware.com/blog/?p=34</guid>
		<description><![CDATA[In this post I will gradually develop a sample application build with Spring framework, BlazeDS integration and other SpringSource technologies. As an example it is linked with the previous post Architecting a Flex 4 component, building the backend services for the contact form.
To get started we need the Spring dm server and Spring Source Tools [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will gradually develop a sample application build with Spring framework, BlazeDS integration and other SpringSource technologies. As an example it is linked with the previous post <a href="http://ayonesoftware.com/blog/2009/06/architecting-a-flex-4-component/">Architecting a Flex 4 component</a>, building the backend services for the contact form.</p>
<p>To get started we need the Spring dm server and Spring Source Tools Suite. The Tool Suite includes the Spring IDE and dm Server Tools which will help you configure the dm server instances.The dm Server is a new generation of Java EE application servers. It brings together traditional Java EE and OSGi worlds.</p>
<p>1. Create the domain bundle:<br />
I will create a new dm server Bundle Project called  contactForm-domain. This project will contain our domain classes.<br />
In the MANIFEST.MF file expose the com.ayone.examples.contactForm.domain package.</p>
<p>MANIFEST.MF file:</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:660px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">Manifest-Version: 1.0<br />
Bundle-Name: ContactForm Domain Bundle<br />
Bundle-ManifestVersion: 2<br />
Bundle-Description: AYONE<br />
Bundle-SymbolicName: com.ayone.examples.contactForm.domain<br />
Bundle-Version: 1.0.0<br />
Export-Package: com.ayone.examples.contactForm.domain;version=&quot;1.0.0&quot;</div></td></tr></tbody></table></div>
<p>The Contact class:</p>
<div class="codecolorer-container java " style="overflow:auto;white-space:nowrap;width:660px;height:300px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">package</span> <span class="co2">com.ayone.examples.contactForm.domain</span><span class="sy0">;</span><br />
<br />
<span class="kw1">import</span> <span class="co2">java.io.Serializable</span><span class="sy0">;</span><br />
<br />
<span class="kw1">public</span> <span class="kw1">class</span> Contact <span class="kw1">implements</span> <span class="kw3">Serializable</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">private</span> <span class="kw3">Long</span> id<span class="sy0">;</span><br />
<span class="kw1">private</span> <span class="kw3">String</span> email<span class="sy0">;</span><br />
<span class="kw1">private</span> <span class="kw3">String</span> message<span class="sy0">;</span><br />
<br />
<span class="kw1">public</span> Contact<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw3">Long</span> getId<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> id<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">void</span> setId<span class="br0">&#40;</span><span class="kw3">Long</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">this</span>.<span class="me1">id</span> <span class="sy0">=</span> id<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw3">String</span> getEmail<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> email<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">void</span> setEmail<span class="br0">&#40;</span><span class="kw3">String</span> email<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">this</span>.<span class="me1">email</span> <span class="sy0">=</span> email<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw3">String</span> getMessage<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> message<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">void</span> setMessage<span class="br0">&#40;</span><span class="kw3">String</span> message<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">this</span>.<span class="me1">message</span> <span class="sy0">=</span> message<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>2. Create the Repository Bundle<br />
This bundle contains the Hibernate DAO classes. It will be presented in details in another post.</p>
<p>3. Create the Service Bundle<br />
We now create another bundle project with our service classes called contactForm-service.<br />
We create a spring service with annotation @Service(&#8221;contactFormService&#8221;) register this in the service-context.xml. This file is the application context where we scan for our annotated spring beans.<br />
The service bean must also be exposed in the OSGi context so we also have an osgi-context.xml.</p>
<div class="codecolorer-container java " style="overflow:auto;white-space:nowrap;width:660px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">package</span> <span class="co2">com.ayone.examples.contactForm.service.impl</span><span class="sy0">;</span><br />
<br />
<span class="kw1">import</span> <span class="co2">org.springframework.beans.factory.annotation.Autowired</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">org.springframework.stereotype.Service</span><span class="sy0">;</span><br />
<br />
<span class="kw1">import</span> <span class="co2">com.ayone.examples.contactForm.domain.Contact</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">com.ayone.examples.contactForm.repository.ContactRepository</span><span class="sy0">;</span><br />
<span class="kw1">import</span> <span class="co2">com.ayone.examples.contactForm.service.ContactFormService</span><span class="sy0">;</span><br />
<br />
@Service<span class="br0">&#40;</span><span class="st0">&quot;contactFormService&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">public</span> <span class="kw1">class</span> ContactFormServiceImpl <span class="kw1">implements</span> ContactFormService<br />
<span class="br0">&#123;</span><br />
@Autowired<br />
<span class="kw1">private</span> ContactRepository contactRepository<span class="sy0">;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">void</span> addContact<span class="br0">&#40;</span>Contact contact<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
contactRepository.<span class="me1">save</span><span class="br0">&#40;</span>contact<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p><b>service-context.xml</b></p>
<p>&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;<br />
	    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;     xmlns:p=&quot;http://www.springframework.org/schema/p&quot;<br />
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;<br />
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br />
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd<br />
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd&quot;&gt;</p>
<p>	&lt;context:component-scan base-package=&quot;com.ayone.contactForm.service.impl&quot; /&gt;</p>
<p>	&lt;context:annotation-config /&gt;<br />
&lt;/beans&gt;</p>
<p><b>osgi-context.xml</b></p>
<p>&lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/osgi&quot;<br />
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;<br />
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/osgi<br />
       http://www.springframework.org/schema/osgi/spring-osgi.xsd<br />
       http://www.springframework.org/schema/beans<br />
       http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt;</p>
<p>	&lt;service ref=&quot;contactFormService&quot;<br />
		interface=&quot;com.ayone.examples.contactForm.service.ContactFormService&quot; /&gt;</p>
<p>	&lt;reference id=&quot;contactRepository&quot;<br />
		interface=&quot;com.ayone.examples.contactForm.repository.ContactRepository&quot; /&gt;<br />
&lt;/beans:beans&gt;</p>
<p>MANIFEST.MF</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:660px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">Manifest-Version: 1.0<br />
Bundle-Name: ContactForm Service Bundle<br />
Bundle-ManifestVersion: 2<br />
Bundle-Description: AYONE<br />
Bundle-SymbolicName: com.ayone.examples.contactForm.service<br />
Bundle-Version: 1.0.0<br />
Import-Package: com.ayone.examples.contactForm.domain;version=&quot;[1.0.0,1.0.0]&quot;,<br />
com.ayone.examples.contactForm.repository;version=&quot;[1.0.0,1.0.0]&quot;<br />
Import-Library: org.springframework.spring;version=&quot;[2.5.6.A,2.5.6.A]&quot;<br />
Export-Package: com.ayone.examples.contactForm.service;version=&quot;1.0.0&quot;</div></td></tr></tbody></table></div>
<p>4. Create the Web Module:<br />
Next we create our the Web Module called contactForm-web which is also a spring dm server bundle project.In addition<br />
Web Modules benefit from reduced configuration via OSGi manifest headers such as Web-DispatcherServletUrlPatterns, Web-ContextPath and Web-FilterMappings.Based on web module metadata the dm Server will auto-generate the web.xml.</p>
<p>In this project we have the Spring BlazeDS Integration 1.0 configuration.<br />
The contactFormService spring bean is exposed for remoting to the Flex client.<br />
Similar to a standard WAR, MODULE-INF is also the directory in which you should place WEB-INF and related subdirectories like BlazeDS channel definitions. The basic setup for the BlazeDS MessageBroker is in the web-context:</p>
<p>&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;<br />
	xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br />
	xsi:schemaLocation=&quot;<br />
		http://www.springframework.org/schema/beans<br />
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br />
		http://www.springframework.org/schema/flex<br />
		http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;</p>
<p>	&lt;!&#8211; Bootstraps and exposes the BlazeDS MessageBroker &#8211;&gt;<br />
	&lt;flex:message-broker&gt;<br />
		&lt;flex:message-service default-channels=&quot;my-streaming-amf,my-polling-amf&quot; /&gt;<br />
	&lt;/flex:message-broker&gt;</p>
<p>	&lt;!&#8211; Maps request paths at /* to the BlazeDS MessageBroker &#8211;&gt;<br />
	&lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;<br />
		&lt;property name=&quot;mappings&quot;&gt;<br />
			&lt;value&gt;<br />
				/*=_messageBroker<br />
			&lt;/value&gt;<br />
		&lt;/property&gt;<br />
	&lt;/bean&gt;</p>
<p>	&lt;!&#8211; Dispatches requests mapped to a MessageBroker &#8211;&gt;<br />
	&lt;bean class=&quot;org.springframework.flex.servlet.MessageBrokerHandlerAdapter&quot; /&gt;</p>
<p>	&lt;!&#8211; Expose the taskioService bean for BlazeDS remoting &#8211;&gt;<br />
	&lt;flex:remoting-destination destination-id=&quot;contactFormService&quot;<br />
		ref=&quot;contactFormService&quot; /&gt;<br />
&lt;/beans&gt;</p>
<p><b>osgi-context.xml</b></p>
<p>&lt;beans:beans xmlns=&quot;http://www.springframework.org/schema/osgi&quot;<br />
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:beans=&quot;http://www.springframework.org/schema/beans&quot;<br />
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/osgi<br />
           http://www.springframework.org/schema/osgi/spring-osgi.xsd<br />
           http://www.springframework.org/schema/beans<br />
           http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt;</p>
<p>	&lt;reference id=&quot;contactFormService&quot;<br />
		interface=&quot;com.ayone.examples.contactForm.service.ContactFormService&quot; /&gt;</p>
<p>&lt;/beans:beans&gt;</p>
<p>MANIFEST.MF</p>
<div class="codecolorer-container text " style="overflow:auto;white-space:nowrap;width:660px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">Manifest-Version: 1.0<br />
Bundle-Name: Web<br />
Web-DispatcherServletUrlPatterns: /messagebroker/*<br />
Bundle-Description: AYONE<br />
Web-ContextPath: contactForm<br />
Bundle-ManifestVersion: 2<br />
Bundle-SymbolicName: com.ayone.contactForm.web<br />
Module-Type: Web<br />
Bundle-Version: 1.0.0<br />
Import-Library: org.springframework.spring;version=&quot;[2.5.6.A,2.5.6.A]&quot;<br />
Import-Bundle: org.springframework.flex;version=&quot;[1.0.0.RELEASE,1.0.0.RELEASE]&quot;,<br />
com.springsource.flex.messaging;version=&quot;[3.2.0.3978,3.2.0.3978]&quot;,<br />
com.springsource.flex.messaging.common;version=&quot;[3.2.0.3978,3.2.0.3978]&quot;,<br />
com.springsource.flex.messaging.services.http;version=&quot;[3.2.0.3978,3.2.0.3978]&quot;,<br />
com.springsource.flex.messaging.services.remoting;version=&quot;[3.2.0.3978,3.2.0.3978]&quot;,<br />
com.springsource.net.sf.cglib;version=&quot;[2.1.3,2.1.3]&quot;<br />
Import-Package: com.ayone.examples.contactForm.service;version=&quot;[1.0.0,1.0.0]&quot;,<br />
javax.servlet;version=&quot;[2.5.0,2.5.0]&quot;,<br />
javax.servlet.http;version=&quot;[2.5.0,2.5.0]&quot;</div></td></tr></tbody></table></div>
<p>5.Deploy the bundles</p>
<p>Add the projects to the Spring DM server. In order to deployed and run the sample, dependencies must be added to the server provisioning repository ($SERVER_HOME/repository/bundles/usr) or you can use the Repository Browser to install bundles from the SpringSource Enterprise Bundle Repository.</p>
<p>You can now call remote services from http://localhost:8080/contactForm/messagebroker/amf.<br />
You can find more about Spring BlazeDS Integration at: <a href="http://www.springsource.org/spring-flex">http://www.springsource.org/spring-flex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ayonesoftware.com/blog/2009/07/spring-blazeds-integration-on-top-of-springsource-dm-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
