<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Good, the Bad and the Ugly</title>
	<atom:link href="http://thegoodthebadtheugly.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thegoodthebadtheugly.wordpress.com</link>
	<description>... about the nice and not so nice things in software technology</description>
	<lastBuildDate>Sun, 20 May 2007 22:04:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thegoodthebadtheugly.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Good, the Bad and the Ugly</title>
		<link>http://thegoodthebadtheugly.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thegoodthebadtheugly.wordpress.com/osd.xml" title="The Good, the Bad and the Ugly" />
	<atom:link rel='hub' href='http://thegoodthebadtheugly.wordpress.com/?pushpress=hub'/>
		<item>
		<title>springOSGi</title>
		<link>http://thegoodthebadtheugly.wordpress.com/2007/05/20/springosgi/</link>
		<comments>http://thegoodthebadtheugly.wordpress.com/2007/05/20/springosgi/#comments</comments>
		<pubDate>Sun, 20 May 2007 21:37:12 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[equinox]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springOSGi]]></category>

		<guid isPermaLink="false">http://thegoodthebadtheugly.wordpress.com/2007/05/20/springosgi/</guid>
		<description><![CDATA[A few weeks ago, the springframework released the 2nd milestone of the spring-OSGi bridge. In my free time over the last two weeks I ported Jürgen Höllers jPetStore example to springOsgi based on M2 (more or less, I still had some issues with broken manifests), Eclipse Equinox (with a Jetty running inside) iBATIS and HSQLDB [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thegoodthebadtheugly.wordpress.com&amp;blog=1117028&amp;post=3&amp;subd=thegoodthebadtheugly&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, the springframework released the 2nd milestone of the <a href="http://springframework.org/osgi" target="_blank">spring-OSGi</a> bridge.</p>
<p>In my free time over the last two weeks I ported Jürgen Höllers jPetStore example to springOsgi based on M2 (more or less, I still had some issues with broken manifests), Eclipse Equinox (with a Jetty running inside) iBATIS and HSQLDB in the backend and Spring WEB-MVC at the frontend.</p>
<p><span id="more-3"></span></p>
<h3>Project setup</h3>
<p>First of all, I needed to find a way to get springOSGi into Eclipse. The thrilling thing there has been to find a possibility to debug the spring and the springOSGi bridge… If you just copy the bundles into your target, Eclipse is not able to find the source code. Finally I got the solution. For me it worked best use the “Import Plug-ins and Fragments” Wizard to import the bundles as binary projects into my workspace. Now I was able to attach the source code. However, I don’t really like the way springOSGi is distributed. If you have a look to the download, you’ll find a folder lib which contains all the libraries, including spring itself, coming with springOSGi. But you don’t find the jars in there, but a whole bunch of folders: one for each library. Inside such a folder again you don’t find the jars, but another folder. Inside this folder you finally get the jar. This structure seems to come from the maven build.</p>
<p>The easiest thing you can do if you are using the same setup as me is to just search for all jars in the download and copy them to one location. Then use this location for your import.<br />
Alin Dreghiciu has reported <a href="http://groups.google.com/group/spring-osgi/web/org-springframework-osgi-eclipse-target" target="_blank">another solution</a> just some days ago. This also seams to work very well.</p>
<h3>Analyzing the example</h3>
<p>When I started, I’d just wanted to see how well the current bridge already was and what I had to do to refactor a running spring application. As an example I have chosen the jPetStore example which comes with the official spring distribution. jPetStore is a simple web-App with a database in the backend. Additionally it uses spring-remoting for the communication with another client.</p>
<p>For me, this example has been mainly a technical prototype. So I decided to create a bundle for each of the technical layers (database, domain-logic and web) and one for the business objects.</p>
<h3>Implementation</h3>
<h4>Dataaccess Layer</h4>
<p>I started with the database layer. The example uses iBATIS and apache.commons.dbcp. As I wanted to change as little as possible at the example I decided to use the same libraries. This was a pretty easy task. The stumbling blocks here have been the broken manifest of commons.collections which came with the official distribution (<a href="http://opensource.atlassian.com/projects/spring/browse/OSGI-132" target="_blank">org.springframework.osgi.commons-collections.osgi has a broken manifest</a>) and the fact that <a href="http://issues.apache.org/jira/browse/DBCP-214" target="_blank">BasicDatasource from DBCP does not respect the context classloader</a>.<br />
As iBATIS has not been in the set of libs that came with the download I had to create a bundle for that on my own. Using the PDE-Project-Creation-Wizard this is really easy. The only thing I added to the generated Manifest was the Eclipse-BuddyPolicy (Eclipse-BuddyPolicy: registered). The only registering bundle is bundle containing the domain-objects. This has also been the only point where I used non-osgi standard mechanisms from equinox.</p>
<p>When running the example the first time, I had to make sure, that the bundle with the symbolic name org.springframework.osgi.spring-osgi-extender has a lower startlevel than my application bundles. Otherwise the spring application contexts of my bundles might not be loaded.</p>
<h4>Middle-tier</h4>
<p>The next layer has been the middle tier. Nothing interesting about the business logic, but this layer also includes some http-based service exporters. Milestone 2 has no support for that. So I had to implement some utilities to make the spring-web-support working in OSGi.<br />
The main issue here has been the locating and loading of resources. All of that has been factored out to a utility bundle to keep it reusable.<br />
Another problem has been the process of registering servlets and resources. I decided to use the OSGi HTTP service implementation by Equinox which uses Jetty as servletcontainer. (Some useful utilities are implemented in the org.eclipse.equinox.http.helper bundle which can be checked out from the eclipse repository (Server: :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse Module: /equinox-incubator/org.eclipse.equinox.http.helper))</p>
<p>In order to get this service I used a ServiceTracker. As in springOSGi each bundle has its own ApplicationContext, the ApplicationContext of the bundle is also needed to create the context for the web application.In a first version I implemented the servlet-registration in the bundles BundleActivator, but there the only possibility to get the ApplicationContext is to import the ApplicationContext as an OSGi service. According to the spec, this is not the way to go (The ApplicationContext you get is from a specific bundle, but you don’t know from which version of the bundle). Another problem with this implementation was the timing: the ApplicationContext is exported as a service after the start() method of the BundleActivator was executed. Hence it is not possible to register the http stuff in the start method. It has to be done asynchronously. So this was a hack.</p>
<p>In the second version I have created a little utility which implements ApplicationContextAware and BundleContextAware.  This utility has to be added to the application context of the bundle. From that utility you can get a callback after the ApplicationContext and the BundleContext/HttpService has been set. Additionally I had to add several 3rd party libs and exchanged some of the libs which have been included in M2 because some packages have not been included in the libs. (<a href="http://opensource.atlassian.com/projects/spring/browse/OSGI-130">Missing packages in several bundles</a>)</p>
<p>Last but not least, Jürgen used some springAOP for transactions. After creating a bundle for aspectj which contains the aspectjweaver.jar and adding dependencies to the respective packages this also worked out of the box <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h4>Web-tier</h4>
<p>After all the registration problems have been solved, I continued with the web layer. Here, the exciting question has been what has to be done to support spring webMVC and JSPs. Equinox comes with a JSPServlet which uses jasper internally to render the JSPs. So this was a really easy job. While adding the dependencies, I noticed that spring comes with a jstl bundle, but does not include the apache commons standard taglibs. This causes a cyclic dependency. As standard taglibs need jstl and vice versa. So I created my own bundle for that and opened this bug <a href="http://opensource.atlassian.com/projects/spring/browse/OSGI-128">org.springframework.osgi.jstl.osgi should include standard.jar</a>.<br />
Now I had to fight a bit with the internals of jasper and see how it resolves (or better tries to resolve) the TagLib definitions. After some debugging I finally noticed that the only possibility for me to place tld-files was a folder called WEB-INF relative to the web-context-path you had to specify when registering the equinox JSP-Servlet ( I used</p>
<p align="center"><code>JspServlet servlet = new JspServlet(context.getBundle(), "/web");</code></p>
<p>so the Taglib definitions had to be in a folder /web/WEB-INF relative to the bundles root.)</p>
<h3>Conclusion</h3>
<p>After sailing around this last rock Jürgens jPetStore finally worked <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  It has not always been an easy job, but given the fact that it is a pre-1.0-release it was pretty straight-forward after the initial installation problems. Most of the problems I had have just been broken manifests and missing dependencies in the libraries coming with the springOSGi bridge.</p>
<p>If you are interested, I have uploaded my workspace to <a href="http://www.kolbware.de/springOsgi/jPetStoreOSGi.zip">http://www.kolbware.de/springOsgi/jPetStoreOSGi.zip</a>. It contains all the necessary bundles including equinox as OSGi platform. The de.kolbware.jpetstore.launcher project contains launchconfigurations for HSQLBD and the web application itself.<br />
I&#8217;d be happy about feedback.</p>
<p>Have fun</p>
<p>Bernd</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thegoodthebadtheugly.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thegoodthebadtheugly.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thegoodthebadtheugly.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thegoodthebadtheugly.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thegoodthebadtheugly.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thegoodthebadtheugly.wordpress.com&amp;blog=1117028&amp;post=3&amp;subd=thegoodthebadtheugly&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thegoodthebadtheugly.wordpress.com/2007/05/20/springosgi/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d8366a03845c828e31ef4db8afe9db52?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Bernd</media:title>
		</media:content>
	</item>
		<item>
		<title>Welcome!</title>
		<link>http://thegoodthebadtheugly.wordpress.com/2007/05/17/hello-world/</link>
		<comments>http://thegoodthebadtheugly.wordpress.com/2007/05/17/hello-world/#comments</comments>
		<pubDate>Thu, 17 May 2007 17:45:35 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Hi! Welcome to our webblog. In the future, you’ll find here news about us, the technologies we are working with and hopefully other interesting things Have fun! B&#38;B<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thegoodthebadtheugly.wordpress.com&amp;blog=1117028&amp;post=1&amp;subd=thegoodthebadtheugly&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi!</p>
<p>Welcome to our webblog. In the future, you’ll find here news about us, the technologies we are working with and hopefully other interesting things <img src="http://berndkolb.wordpress.com/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /></p>
<p>Have fun!</p>
<p>B&amp;B</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thegoodthebadtheugly.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thegoodthebadtheugly.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thegoodthebadtheugly.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thegoodthebadtheugly.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thegoodthebadtheugly.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thegoodthebadtheugly.wordpress.com&amp;blog=1117028&amp;post=1&amp;subd=thegoodthebadtheugly&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thegoodthebadtheugly.wordpress.com/2007/05/17/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d8366a03845c828e31ef4db8afe9db52?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Bernd</media:title>
		</media:content>

		<media:content url="http://berndkolb.wordpress.com/wp-includes/images/smilies/icon_wink.gif" medium="image">
			<media:title type="html">;-)</media:title>
		</media:content>
	</item>
	</channel>
</rss>
