<?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>Ralf Zahn&#039;s blog &#187; OSGi</title>
	<atom:link href="http://ralfzahn.wordpress.com/category/osgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://ralfzahn.wordpress.com</link>
	<description>My experiences with Java EE, OSGi and Eclipse.</description>
	<lastBuildDate>Mon, 06 May 2013 17:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ralfzahn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/138fe77c669b3a268149cb0200b280e7?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Ralf Zahn&#039;s blog &#187; OSGi</title>
		<link>http://ralfzahn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ralfzahn.wordpress.com/osd.xml" title="Ralf Zahn&#039;s blog" />
	<atom:link rel='hub' href='http://ralfzahn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Deploying RWT applications to IBM WebSphere Application Server</title>
		<link>http://ralfzahn.wordpress.com/2011/10/10/deployin-rwt-applications-to-ibm-websphere-application-server/</link>
		<comments>http://ralfzahn.wordpress.com/2011/10/10/deployin-rwt-applications-to-ibm-websphere-application-server/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 08:08:57 +0000</pubDate>
		<dc:creator>ralf.zahn</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://ralfzahn.wordpress.com/?p=97</guid>
		<description><![CDATA[The last days, I tried to get a demo RWT application run on IBM WebSphere Application Server by using the OSGi feature. And the result is: It works! I have written a short manual within the RAP Wiki. But there are some restrictions and notes: Ensure that you have the RWT 1.5 Nightly Build later [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=97&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The last days, I tried to get a demo RWT application run on IBM WebSphere Application Server by using the OSGi feature. And the result is: It works! I have written a short manual within the <a href="http://wiki.eclipse.org/RAP/Running_RAP_on_WebSphere" title="RAP Wiki page on running RAP on WebSphere Application Server">RAP Wiki</a>. But there are some restrictions and notes:</p>
<ul>
<li>Ensure that you have the RWT 1.5 Nightly Build later than October 6th, because there was a bug on registering RWT resources.</li>
<li>There is a strange bug of IBM WebSphere Application Server 8 that provides the Servlet 3.0 API with the <tt>javax.servlet.*</tt> packages exported as version 2.6.0! Fortunately, the RAP team has <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=352338" title="RAP Bug minding the WAS bug with Servlet API">minded this bug</a>. Thanks guys!</li>
<li>I did not already test the whole RAP platform, only RWT and JFace.</li>
<li>I only got it work using the isolated way of running the RWT platform. WebSphere provides a Shared Bundle Framework to all applications. Each application is run in an isolated framework, but can access services running in the Shared Bundle Framework. It is possible to install the OSGi Http Service into the Shared Bundle Framework and register servlets of applications to this service. This way, you have a single context root that can be extended by multiple applications. Installing the <tt>org.eclipse.rap.rwt</tt> bundle into the Shared Bundle Framework did not work because of some strange errors (without any details). I have tested to remove some entries from the manifest file, but this is like finding the needle in a haystack. And I guess, this would not be the default scenario because isolation is one of the requirements to multiple applications running on a single server.</li>
</ul>
<p>You can find my demo EBA <a href="http://www.ars.de/web/resources/blog/rzahn/20111009/org.eclipse.rap.rwt.demo.eba_1.0.0.201110100824.eba" title="Demo RWT EBA" target="_blank">here</a>. The RWT and JFace bundles are not packaged into the EBA. You can add those that are named within the <tt>META-INF/APPLICATION.MF</tt> file to the EBA or provide the bundles using WAS&#8217; bundle repository configuration. Take care of the versions, because I used RWT 1.5 with Eclipse 3.6.0 bundles, because WebSphere Application Server provides the <tt>org.eclipse.osgi bundle</tt> version 3.6.0.</p>
<p>After installing this EBA on WebSphere Application Server, you can open the demo with the URL <tt><a href="http://&lt;host&#038;gt" rel="nofollow">http://&lt;host&#038;gt</a>;:&lt;port&gt;/http/demo</tt>. You should then get this:</p>
<p><a href="http://ralfzahn.files.wordpress.com/2011/10/rwt_was.jpg"><img src="http://ralfzahn.files.wordpress.com/2011/10/rwt_was.gif?w=400&#038;h=266" alt="RWT Demo on WAS8" title="RWT Demo on WAS8" width="400" height="266" class="aligncenter size-medium wp-image-109" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralfzahn.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralfzahn.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=97&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ralfzahn.wordpress.com/2011/10/10/deployin-rwt-applications-to-ibm-websphere-application-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/184e677b8185b4811013ec5669d55fcb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">masseur81</media:title>
		</media:content>

		<media:content url="http://ralfzahn.files.wordpress.com/2011/10/rwt_was.gif?w=400" medium="image">
			<media:title type="html">RWT Demo on WAS8</media:title>
		</media:content>
	</item>
		<item>
		<title>Some thoughts about OSGi and Java EE 6</title>
		<link>http://ralfzahn.wordpress.com/2011/06/28/some-thoughts-about-osgi-and-java-ee-6/</link>
		<comments>http://ralfzahn.wordpress.com/2011/06/28/some-thoughts-about-osgi-and-java-ee-6/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 08:02:12 +0000</pubDate>
		<dc:creator>ralf.zahn</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://ralfzahn.wordpress.com/?p=52</guid>
		<description><![CDATA[Last week, I played around with the new features of Java EE 6, especially with the Servlet 3.0 API. Because developing Java Enterprise applications with the OSGi application programming model is pretty attractive for me, I had a focus on the comparison of concepts that both &#8220;worlds&#8221; introduced and how to use them in a [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=52&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Last week, I played around with the new features of Java EE 6, especially with the Servlet 3.0 API. Because developing Java Enterprise applications with the OSGi application programming model is pretty attractive for me, I had a focus on the comparison of concepts that both &#8220;worlds&#8221; introduced and how to use them in a conflated environment.<br />
<span id="more-52"></span></p>
<h3 style="font-size:1em;">Servlet Annotations</h3>
<pre class="brush: java; title: ; notranslate">
@WebServlet(value = &quot;/control&quot;, name=&quot;Controller Servlet&quot;, initParams = { 
  @WebInitParam(name = &quot;param1&quot;, value = &quot;value1&quot;), 
  @WebInitParam(name = &quot;param2&quot;, value = &quot;value2&quot;) 
})
public class ControllerServlet extends HttpServlet {
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // implement request processing
  }
}
</pre>
<p>Okay, it&#8217;s a nice feature that servlets can now be declared using annotations to replace the web deployment descriptor and to have all metadata within the Java code. This fits common concepts of modern frameworks. But the Servlet API is still invasive, i.e. you have to implement a Servlet interface and you are dependent from a request and a response object which makes testing difficult. I would expect to change this in the future, but it does not seem to matter in the <a href="http://jcp.org/en/jsr/detail?id=340#2" title="Request of Servlet 3.1 API" target="_blank">next release</a>. So  you have to extract your controller logic from the Servlet API by yourself or use frameworks like Spring Web furthermore.</p>
<h3 style="font-size:1em;">Pluggability</h3>
<p>Since Servlet API 3.0, it is possible to split a web module into (a web module and) multiple web fragments. Web applications can be divided by special functionality, and web frameworks can configure the web application by itself instead of writing manuals how to install the framework into the web application. In addition, servlets, filters and listeners can be installed into the web application programmatically (in a very dynamic way).</p>
<pre class="brush: java; title: ; notranslate">
final Dynamic servlet = getServletContext()
  .addServlet(&quot;Controller Servlet&quot;, new ControllerServlet());
servlet.addMapping(&quot;/control&quot;);
servlet.setInitParameter(&quot;param1&quot;, &quot;value1&quot;);
servlet.setInitParameter(&quot;param2&quot;, &quot;value2&quot;);
</pre>
<p>With regard to OSGi, the concepts of web fragments and OSGi bundle fragments are very similar, because both extend web modules and OSGi bundles respectively. But the devil is in the details, because</p>
<ul>
<li>OSGi bundle fragments have a dependency to a single host bundle, whereas web fragments are published into the <span style="font-family:courier new;">WEB-INF/lib</span> folder of the web app (<strong>any</strong> desired web app!) &#8211; so we have reverse dependencies</li>
<li>Servlets, filters and listeners can only be registered during application startup within a ServletContextListener (and cannot be removed) &#8211; so in comparison to the lifecycle of OSGi bundles, it does not provide such a dynamic behaviour. If you want to register and remove servlets at runtime without restarting the web application, you should use the OSGi HttpService that only provides a Servlet 2.x API. (see my notes on <a href="http://ralfzahn.wordpress.com/2011/05/14/using-the-osgi-http-service-on-ibm-websphere-application-server/" title="Using the OSGi Http Service on IBM WebSphere Application Server">&#8220;Using the OSGi Http Service on IBM WebSphere Application Server&#8221;</a>)
</ul>
<h3 style="font-size:1em;">Upload Support</h3>
<pre class="brush: java; title: ; notranslate">
@WebServlet(&quot;/upload.html&quot;)
@MultipartConfig(
  location = &quot;/upload-files&quot;, 
  fileSizeThreshold = 1024 * 1024, 
  maxFileSize = 1024 * 1024 * 5, 
  maxRequestSize = 1024 * 1024 * 5 * 5
)
public class FileUploadServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    resp.setContentType(&quot;text/plain&quot;);
    final PrintWriter out = resp.getWriter();
    try {
      final Collection&lt;Part&gt; parts = req.getParts();
      out.println(&quot;Total parts : &quot; + parts.size());
      for (Part part : parts) {
        out.println();
        out.println(&quot;Name : &quot; + part.getName());
        out.println(&quot;Content-Type : &quot; + part.getContentType());
        //part.getInputStream();
      }
    } finally {
      out.close();
    }
  }
	
}
</pre>
<p>Nice feature. The <span style="font-family:courier new;">location</span> attribute of the <span style="font-family:courier new;">@MultipartConfig</span> is used as temporary directory to store uploaded files on the server. You can specify both an absolute and relative (to the app server&#8217;s temp) directory.</p>
<p><strong>Be aware</strong> that WebSphere Application Server uses the web app&#8217;s installation directory as the temporary directory and does not prevent that the <span style="font-family:courier new;">location</span> attribute has the value &#8220;<span style="font-family:courier new;">/WEB-INF</span>&#8220;. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_confused.gif' alt=':???:' class='wp-smiley' /> </p>
<h3 style="font-size:1em;">Asynchronous Request Processing</h3>
<pre class="brush: java; title: ; notranslate">
final AsyncContext ctx = request.startAsync();
executor.execute(new Runnable() {
			
  @Override
  public void run() {
    // Asynchronous processing
    // Write response
    // Complete request processing
    ctx.complete();
  }
});
</pre>
<p>Okay, I understood that I can use it for &#8220;COMET&#8221;, &#8220;Reverse Ajax&#8221; or however they call it. For me, it sounds like the possibility to shift the problems that occur within the request processing thread to another thread. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
The risk is that the web container&#8217;s thread limitation is bypassed. This should only be used for managing custom queues or any other algorithm that does not slow down performance when it is invoked 100 times in parallel.</p>
<h3 style="font-size:1em;">Contexts and Dependency Injection (CDI)</h3>
<p>This is the greatest new feature of Java EE 6 for me. It allows to simplify application code by using annotations to manage beans and replace lookups. CDI also introduces Interceptors and Decorators for cross-cutting concerns (e.g. logging, dealing with transactions) and to extend the business logic by separate components.<br />
Concerning OSGi, it would be helpful to get OSGi services injected into a servlet or EJB. Apache Aries declares such a possibility with the usage of the <span style="font-family:courier new;">@Resource</span> annotation.</p>
<pre class="brush: java; title: ; notranslate">
@Resource(lookup = &quot;osgi:service/de.ars.demo.helloworld.api.HelloWorldService&quot;)
private HelloWorldService hw;
</pre>
<p>This should also be possible using the <span style="font-family:courier new;">@Inject</span> annotation with a qualifier to avoid the usage of JNDI namespaces. GlassFish provides such a mechanism:</p>
<pre class="brush: java; title: ; notranslate">
@Inject @OSGiService
private HelloWorldService hw;
</pre>
<p>Wouldn&#8217;t it be nice to have such dependency injection within (non-JavaEE) OSGi environments too? I guess this could be a good alternative to declarative services. I know that OSGi core does not use annotations to support (all) mobile devices (that do not run a Java 5 JVM), but it could be part of OSGi enterprise. Eclipse 4.x also uses these annotations for dependency injection. So CDI has the potential to provide an application model for multiple environments (because it is independent from the environment).</p>
<p>CDI interceptors can be used for cross-cutting concerns.</p>
<pre class="brush: java; title: ; notranslate">
@AroundInvoke
private Object log(InvocationContext ctx) throws Exception {
  final long d1 = System.currentTimeMillis();
  try {
    return ctx.proceed();
  } finally {
    final long d2 = System.currentTimeMillis();
    log(&quot;Method &quot; + ctx.getMethod().getName() + &quot; invoked (&quot; + (d2 - d1) + &quot;ms)&quot;);
  }
</pre>
<p>This is a simple example for an interceptor within a single class. Interceptors can also be written as separate classes and bound to other classes or single methods using a custom annotation.<br />
OSGi 4.3 introduced a Weaving Hook mechanism for bytecode instruction. The developer has to use frameworks like Javassist or ASM to add concerns. But CDI interceptors are much easier to use&#8230;</p>
<h3 style="font-size:1em;">Bean Validation API</h3>
<p>The Bean Validation API also uses annotations to declare constraints. Within the Java EE environment, managed beans are validated automatically at some layers, but validation can also be done programmatically.</p>
<p>This could be the code of a servlet class (maybe a little bit dirty to change instance variables during request processing):</p>
<pre class="brush: java; title: ; notranslate">
@Inject
private Validator validator;
@Inject
private Person person;

protected void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException {
  person.setFirstName(request.getParameter(&quot;firstName&quot;));
  person.setLastName(request.getParameter(&quot;lastName&quot;));
  person.setEmail(request.getParameter(&quot;email&quot;));
  final Set&lt;ConstraintViolation&lt;Person&gt;&gt; result = validator.validate(person);
  // continue...
}
</pre>
<p>Bean validation is automatically invoked when using JSF. But it&#8217;s a cool thing that can also be used out-of-the-box.</p>
<h3 style="font-size:1em;">Conclusion</h3>
<p>Java EE 6 introduces some nice features. Especially CDI for resolving OSGi service instances would be very cool. I have a dream&#8230; <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':razz:' class='wp-smiley' />  that the whole CDI framework is part of the Eclipse 4 application programming model.<br />
There are still some stumbling blocks like the &#8220;web fragment vs. OSGi bundle fragment&#8221; comparison.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralfzahn.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralfzahn.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=52&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ralfzahn.wordpress.com/2011/06/28/some-thoughts-about-osgi-and-java-ee-6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/184e677b8185b4811013ec5669d55fcb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">masseur81</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the OSGi Http Service on IBM WebSphere Application Server</title>
		<link>http://ralfzahn.wordpress.com/2011/05/14/using-the-osgi-http-service-on-ibm-websphere-application-server/</link>
		<comments>http://ralfzahn.wordpress.com/2011/05/14/using-the-osgi-http-service-on-ibm-websphere-application-server/#comments</comments>
		<pubDate>Sat, 14 May 2011 21:48:34 +0000</pubDate>
		<dc:creator>ralf.zahn</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://ralfzahn.wordpress.com/?p=12</guid>
		<description><![CDATA[Since version 7 (Feature Pack) and version 8 (integrated), IBM WebSphere Application Server (WAS) provides the OSGi application model to enterprise application developers. It allows to develop OSGi bundles and to deploy applications as enterprise bundle archives (EBA). As WebSphere uses Equinox as the OSGi implementation, it should be possible to install and run the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=12&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Since version 7 (Feature Pack) and version 8 (integrated), IBM WebSphere Application Server (WAS) provides the OSGi application model to enterprise application developers. It allows to develop OSGi bundles and to deploy applications as enterprise bundle archives (EBA). As WebSphere uses Equinox as the OSGi implementation, it should be possible to install and run the Rich Ajax Platform on the server. The first step is to evaluate how to install the OSGi Http Service into WebSphere&#8217;s web container and how to use it.</p>
<p><span id="more-12"></span></p>
<p><strong>OSGi Feature of WebSphere Application Server</strong></p>
<p>First, let me say some words about the OSGi feature in general. You can find a very detailed introduction at <a title="OSGi feature description" href="http://www.ibm.com/developerworks/websphere/techjournal/1007_robinson/1007_robinson.html" target="_blank">developerWorks</a>. Developers that are familiar with OSGi core concepts should notice the following specifics:</p>
<ul>
<li>WAS7 provides the org.eclipse.osgi bundle version 3.5.2 to OSGi applications, WAS8 provides version 3.6.1.</li>
<li>Although Equinox is the OSGi runtime, it is not intended to support features like the Extension Point Registry or the Declarative Services Specification.</li>
<li>WAS implements the OSGi Web Application Specification. Enterprise Applications are now deployed as Enterprise Bundle Archives (EBAs instead of EARs), Web modules are packaged as Web Application Bundles (WABs instead of WARs). Non-OSGi WARs can be part of an EBA and are automatically wrapped into a WAB.</li>
<li>WAS integrates Apache Aries technologies. OSGi Services can be declared by using the OSGi BluePrint Container specification. OSGi services are published to the JNDI and vice versa to connect both &#8220;worlds&#8221;.</li>
<li>Because one very important requirement to an application server is the isolation of enterprise applications, OSGi applications are launched within their own framework. Nevertheless, it is possible to resolve bundles from a bundle repository, which are then shared between multiple applications. See the following picture from the WAS7 Infocenter that explains these facts:
<p><div class="wp-caption alignnone" style="width: 488px"><a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.osgifep.multiplatform.doc/topics/ca_sharing_isolation.html"><img title="Isolated Frameworks" src="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.osgifep.multiplatform.doc/images/isolation.gif" alt="Isolated Frameworks" width="478" height="403" /></a><p class="wp-caption-text">Isolated Frameworks</p></div></li>
<li>It is possible to place bundles within a composite bundle, which is then started within its own framework too. An EBA can contain single and composite bundles.</li>
<li>Bundle dependencies should be declared using the Import-Package header. On WAS, the Require-Bundle header is only allowed between bundles within the EBA. It is not possible to declare this header within a bundle of the EBA to a bundle resolved from the shared repository. (The EBA manifest names a list of bundles and their versions that can be resolved from the shared repository.)</li>
<li>I use IBM Rational Application Developer V8 with PDE to create OSGi applications for WebSphere. It is also possible to use Eclipse PDE and install the <a title="Link to IBM Rational Development Tools for OSGi Applications" href="http://www.ibm.com/developerworks/rational/downloads/10/rationaldevtoolsforosgiapplications.html" target="_blank">IBM Rational Development Tools for OSGi Applications</a> into the IDE.</li>
</ul>
<p><strong>OSGi Http Service Implementation of Equinox</strong></p>
<p>The Equinox Server-Side Project provides an implementation of the OSGi Http Service Specification. The HttpServiceServlet registers the service at the platform and delegates requests from the webcontainer to the Http Service. In contrast to previous versions of WAS, we do not need the BridgeServlet anymore, that launches an external OSGi framework and does not allow sharing resources between multiple applications.</p>
<p>So we need the org.eclipse.osgi.services bundle (that defines the HttpService interface) and the org.eclipse.equinox.http.servlet bundle (containing the HttpServiceServlet). They are configured to be part of the PDE target platform. To make them available on WAS for testing your applications, you can install them into the internal bundle repository or refer to an external bundle repository that can be created using the <a title="OSGi BIndex tool" href="http://www.osgi.org/Repository/BIndex" target="_blank">OSGi BIndex Tool</a>.</p>
<p><strong>Creating the WAB</strong></p>
<p>We need to create a WAB that delegates incoming requests from the web container to the OSGi platform. After creating the OSGi Bundle Project, do the following steps:</p>
<ul>
<li>Extend the Import-Package header of the manifest to list the &#8220;org.eclipse.equinox.http.servlet&#8221; package.</li>
<li>Add a servlet to the web.xml with the servlet class &#8220;org.eclipse.equinox.http.servlet.HttpServiceServlet&#8221; and the URL mapping &#8220;/*&#8221;. Configure the servlet to be initialized immediately, if you want the HttpService implementation to be published to the OSGi platform during application startup, which can be a long operation because this can invoke the registration of servlets to the HttpService by other bundles.</li>
</ul>
<p>That&#8217;s all! You can <a href="http://www.ars.de/web/resources/blog/rzahn/20110514/org.eclipse.equinox.http.embedded.web_1.0.0.201105142219.jar">download the example WAB</a>.</p>
<p><strong>Using the OSGi Http Service</strong></p>
<p>You can bind the Http Service programmatically using OSGi Servicetracker, or you can use Blueprint. See the BluePrint file example below:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;blueprint xmlns=&quot;http://www.osgi.org/xmlns/blueprint/v1.0.0&quot;&gt;
	&lt;bean id=&quot;ServletRegistry&quot;
		class=&quot;de.ars.ws.http.example.internal.ServletRegistry&quot; /&gt;
	&lt;reference interface=&quot;org.osgi.service.http.HttpService&quot;
		activation=&quot;eager&quot; availability=&quot;optional&quot;&gt;
		&lt;reference-listener bind-method=&quot;bind&quot; unbind-method=&quot;unbind&quot; ref=&quot;ServletRegistry&quot;/&gt;
	&lt;/reference&gt;
&lt;/blueprint&gt;
</pre>
<p>And the bean that registers the servlet to the Http Service:</p>
<pre class="brush: java; title: ; notranslate">
package de.ars.ws.http.example.internal;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;

import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;

public class ServletRegistry {

	private static final Logger logger = Logger.getLogger(ServletRegistry.class
			.getName());

	public void bind(HttpService service) {
		if (null != service) {
			try {
				logger.log(Level.INFO, &quot;HTTP Service bound: &quot; + service);
				service.registerServlet(&quot;/example/servlet&quot;, new ExampleServlet(service),
						null, null);
				service.registerResources(&quot;/example/resources&quot;, &quot;/resources&quot;, null);
			} catch (ServletException e) {
				logger.log(Level.WARNING,
						&quot;Unable to register example servlet!&quot;, e);
			} catch (NamespaceException e) {
				logger.log(Level.WARNING,
						&quot;Unable to register example servlet!&quot;, e);
			}
		}
	}

	public void unbind(HttpService service) {
		if (null != service) {
			logger.log(Level.INFO, &quot;HTTP Service unbound: &quot; + service);
			service.unregister(&quot;/example/servlet&quot;);
			service.unregister(&quot;/example/resources&quot;);
		}
	}

}
</pre>
<p>You can <a href="http://www.ars.de/web/resources/blog/rzahn/20110514/de.ars.ws.http.example_1.0.0.201105142307.jar">download the example bundle</a>.</p>
<p><strong>Putting it all together &#8211; the EBA</strong></p>
<p>Last but not least, let&#8217;s create an EBA with a single META-INF/APPLICATION.MF file with the following content:</p>
<pre class="brush: plain; title: ; notranslate">
Application-Name: Embedded OSGi Http Service
Application-SymbolicName: org.eclipse.equinox.http.embedded
Application-ManifestVersion: 1.0
Application-Version: 1.0.0.qualifier
Application-Content: org.eclipse.equinox.http.embedded.web;version=&quot;1.0.0&quot;,
  org.eclipse.equinox.http.servlet;version=1.0.200,
  org.eclipse.osgi.services;version=3.2.0,
  de.ars.ws.http.example;version=1.0.0
Manifest-Version: 1.0
</pre>
<p>This is the isolated version of the Http Service that is created for each application framework. You have to include the Equinox bundles and the WAB for each EBA (take care about the context root of the WAB to be unique) together with your application bundles.</p>
<p>Another possibility would be to share the Http Service between all applications. The EBA manifest would then look like this:</p>
<pre class="brush: plain; title: ; notranslate">
Application-Name: Embedded OSGi Http Service
Application-SymbolicName: org.eclipse.equinox.http.embedded
Application-ManifestVersion: 1.0
Application-Version: 1.0.0.qualifier
Application-Content: org.eclipse.equinox.http.embedded.web;version=&quot;1.0.0&quot;
Manifest-Version: 1.0
Use-Bundle: org.eclipse.equinox.http.servlet;version=1.0.200,
  org.eclipse.osgi.services;version=3.2.0
</pre>
<p>You can <a href="http://www.ars.de/web/resources/blog/rzahn/20110514/org.eclipse.equinox.http.embedded_1.0.0.201105142333.eba">download the EBA</a>.</p>
<p>The difference is that the HttpServiceServlet is resolved from the bundle repository, which causes the HttpService to be published to the Shared Bundle Space. Your application bundles can then be packaged into a separate EBA.</p>
<p><strong>Conclusion</strong></p>
<p>As you can see, it is possible to use the OSGi Http Service both within isolated applications and within a shared space where the Http Service acts as a singleton like the web container does (with the exception that the Http Service does not support context roots). The next step is to test how to deploy the Rich Ajax Platform on WebSphere Application Server.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralfzahn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralfzahn.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ralfzahn.wordpress.com&#038;blog=17945081&#038;post=12&#038;subd=ralfzahn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ralfzahn.wordpress.com/2011/05/14/using-the-osgi-http-service-on-ibm-websphere-application-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/184e677b8185b4811013ec5669d55fcb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">masseur81</media:title>
		</media:content>

		<media:content url="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.osgifep.multiplatform.doc/images/isolation.gif" medium="image">
			<media:title type="html">Isolated Frameworks</media:title>
		</media:content>
	</item>
	</channel>
</rss>