[jboss-cvs] JBossAS SVN: r97538 - in projects/jboss-osgi/trunk: distribution/docbook/en/images and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 8 09:13:09 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-12-08 09:13:08 -0500 (Tue, 08 Dec 2009)
New Revision: 97538
Added:
projects/jboss-osgi/trunk/distribution/docbook/en/images/extender-approach.png
projects/jboss-osgi/trunk/distribution/docbook/en/images/interceptor-approach.png
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/EventAdminTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/event/
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/event/example-event.bnd
Removed:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jbossxb/XMLBindingActivator.java
Modified:
projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch050-developer-guide.xml
projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml
projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml
projects/jboss-osgi/trunk/pom.xml
projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jbossxb/example-xml-binding.bnd
projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
Add EventAdmin test case
Added: projects/jboss-osgi/trunk/distribution/docbook/en/images/extender-approach.png
===================================================================
(Binary files differ)
Property changes on: projects/jboss-osgi/trunk/distribution/docbook/en/images/extender-approach.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: projects/jboss-osgi/trunk/distribution/docbook/en/images/interceptor-approach.png
===================================================================
(Binary files differ)
Property changes on: projects/jboss-osgi/trunk/distribution/docbook/en/images/interceptor-approach.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch050-developer-guide.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch050-developer-guide.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch050-developer-guide.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -277,4 +277,121 @@
</sect1>
+ <sect1 xml:id="SecLifecycleInterceptors">
+ <title>Lifecycle Interceptors</title>
+
+ <para>A common pattern in OSGi is that a bundle contains some piece of meta data that gets processed by some other infrastructure bundle
+ that is installed in the OSGi Framework. In such cases the well known <ulink url="http://www.osgi.org/blog/2007/02/osgi-extender-model.html">Extender Pattern</ulink>
+ is often being used. JBoss OSGi offeres a differnet approach to address this problem which is covered by the <ulink url="http://jbossosgi.blogspot.com/2009/10/extender-pattern-vs-lifecycle.html">
+ Extender Pattern vs. Lifecycle Interceptor</ulink> post in the <ulink url="http://jbossosgi.blogspot.com/">JBoss OSGi Diary</ulink>.</para>
+
+ <emphasis role="bold">Extending an OSGi Bundle</emphasis>
+
+ <orderedlist>
+ <listitem>Extender registers itself as BundleListener</listitem>
+ <listitem>Bundle gets installed/started</listitem>
+ <listitem>Framework fires a BundleEvent</listitem>
+ <listitem>Extender picks up the BundleEvent (e.g. STARTING)</listitem>
+ <listitem>Extender reads metadata from the Bundle and does its work</listitem>
+ </orderedlist>
+
+ <para>There is no extender specific API. It is a pattern rather than a piece of functionality provided by the Framework.
+ Typical examples of extenders are the Blueprint or Web Application Extender.</para>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata align="center" width="90%" fileref="images/extender-approach.png"/>
+ </imageobject>
+ </mediaobject>
+
+ <para>Client code that installs, starts and uses the registered endpoint could look like this.</para>
+
+ <programlisting role="JAVA">
+ // Install and start the Web Application bundle
+ Bundle bundle = context.installBundle("mywebapp.war");
+ bundle.start();
+
+ // Access the Web Application
+ String response = getHttpResponse("http://localhost:8090/mywebapp/foo");
+ assertEquals("ok", response);
+ </programlisting>
+
+ <para>This seemingly trivial code snippet has a number of issues that are probably worth looking into in more detail</para>
+
+ <itemizedlist>
+ <listitem>The WAR might have missing or invalid web metadata (i.e. an invalid WEB-INF/web.xml descriptor)</listitem>
+ <listitem>The WAR Extender might not be present in the system</listitem>
+ <listitem>There might be multiple WAR Extenders present in the system</listitem>
+ <listitem>Code assumes that the endpoint is available on return of bundle.start()</listitem>
+ </itemizedlist>
+
+ <para>Most Blueprint or WebApp bundles are not useful if their Blueprint/Web metadata is not processed. Even if they are processed
+ but in the "wrong" order a user might see unexpected results (i.e. the webapp processes the first request before the underlying
+ Blueprint app is wired together).</para>
+
+ <para>As a consequence the extender pattern is useful in some cases but not all. It is mainly useful if a bundle can optionally
+ be extended in the true sense of the word.</para>
+
+ <emphasis role="bold">Intercepting the Bundle Lifecycle</emphasis>
+
+ <para>If the use case requires the notion of "interceptor" the extender pattern is less useful. The use case might be such that
+ you would want to intercept the bundle lifecycle at various phases to do mandatory metadata processing.</para>
+
+ <para>An interceptor could be used for annotation processing, byte code weaving, and other non-optional/optional metadata processing steps.
+ Typically interceptors have a relative order, can communicate with each other, veto progress, etc.</para>
+
+ <para>Lets look at how multiple interceptors can be used to create Web metadata and publish endpoints on the HttpService based on that metadata.</para>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata align="center" width="90%" fileref="images/interceptor-approach.png"/>
+ </imageobject>
+ </mediaobject>
+
+ <para>Here is how it works</para>
+
+ <orderedlist>
+ <listitem>The Wep Application processor registers two LifecycleInterceptors with the LifecycleInterceptorService</listitem>
+ <listitem>The Parser interceptor declares no required input and WebApp metadata as produced output</listitem>
+ <listitem>The Publisher interceptor declares WebApp metadata as required input</listitem>
+ <listitem>The LifecycleInterceptorService reorders all registered interceptors according to their input/output requirements and relative order</listitem>
+ <listitem>The WAR Bundle gets installed and started</listitem>
+ <listitem>The Framework calls the LifecycleInterceptorService prior to the actual state change</listitem>
+ <listitem>The LifecycleInterceptorService calls each interceptor in the chain</listitem>
+ <listitem>The Parser interceptor processes WEB-INF/web.xml in the invoke(int state, InvocationContext context) method and attaches WebApp metadata to the InvocationContext</listitem>
+ <listitem>The Publisher interceptor is only called when the InvocationContext has WebApp metadata attached. If so, it publishes the endpoint from the WebApp metadata</listitem>
+ <listitem>If no interceptor throws an Exception the Framework changes the Bundle state and fires the BundleEvent. </listitem>
+ </orderedlist>
+
+ <para>Client code is identical to above.</para>
+
+ <programlisting role="JAVA">
+ // Install and start the Web Application bundle
+ Bundle bundle = context.installBundle("mywebapp.war");
+ bundle.start();
+
+ // Access the Web Application
+ String response = getHttpResponse("http://localhost:8090/mywebapp/foo");
+ assertEquals("ok", response);
+ </programlisting>
+
+ <para>The behaviour of that code however, is not only different but also provides a more natural user experience.</para>
+
+ <itemizedlist>
+ <listitem>Bundle.start() fails if WEB-INF/web.xml is invalid</listitem>
+ <listitem>An interceptor could fail if web.xml is not present</listitem>
+ <listitem>The Publisher interceptor could fail if the HttpService is not present</listitem>
+ <listitem>Multiple Parser interceptors would work mutually exclusiv on the presents of attached WebApp metadata</listitem>
+ <listitem>The endpoint is guaranteed to be available when Bundle.start() returns</listitem>
+ </itemizedlist>
+
+ <para>The general idea is that each interceptor takes care of a particular aspect of processing during state changes.
+ In the example above WebApp metadata might get provided by an interceptor that scans annotations or by another one that
+ generates the metadata in memory. The Publisher interceptor would not know nor care who attached the WebApp metadata object,
+ its task is to consume the WebApp metadata and publish endpoints from it.</para>
+
+ <para>For details on howto provide and register liefecycle interceptors have a look at the <link linkend="SecInterceptorExample">
+ Lifecycle Interceptor Example</link>.</para>
+ </sect1>
+
</chapter>
Modified: projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch070-provided-bundles.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -203,7 +203,7 @@
<title>XML Parser Services</title>
<para>The JBoss OSGi <emphasis role="bold">jboss-osgi-apache-xerces.jar</emphasis> bundle provides services
- from DOM and SAX parsing.</para>
+ for DOM and SAX parsing.</para>
<para>The services are registered with the Framework under the name</para>
@@ -220,19 +220,15 @@
<sect1 xml:id="SecBundleXMLBinding">
<title>XML Binding Services</title>
- <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-xml-binding.jar</emphasis> bundle provides services
- from DOM and SAX parsing.</para>
+ <para>The JBoss OSGi <emphasis role="bold">jboss-osgi-xml-binding.jar</emphasis> bundle provides an
+ <ulink url="http://www.jboss.org/community/wiki/JBossXB">JBossXB</ulink> unmarshaller service.</para>
- <para>The services are registered with the Framework under the name</para>
+ <para>The service is registered with the Framework under the name</para>
<itemizedlist>
- <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html">javax.xml.parsers.SAXParserFactory</ulink></emphasis></listitem>
- <listitem><emphasis role="bold"><ulink url="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html">javax.xml.parsers.DocumentBuilderFactory</ulink></emphasis></listitem>
+ <listitem><emphasis role="bold"><ulink url="http://jbmuc.dyndns.org/jboss-osgi-1.0.0.Beta5/apidocs/org/jboss/osgi/jbossxb/UnmarshallerService.html">org.jboss.osgi.jbossxb.UnmarshallerService</ulink></emphasis></listitem>
</itemizedlist>
- <para>Please see <ulink url="http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html">XMLParserActivator</ulink>
- for details.</para>
-
</sect1>
</chapter>
Modified: projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/distribution/docbook/en/modules/ch080-provided-examples.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -22,37 +22,18 @@
-------------------------------------------------------
T E S T S
-------------------------------------------------------
- Running org.jboss.test.osgi.example.webapp.WebAppTestCase
- Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.202 sec
- Running org.jboss.test.osgi.example.blueprint.BlueprintTestCase
- Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.447 sec
- Running org.jboss.test.osgi.example.xml.jaxb.JAXBTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.722 sec
- Running org.jboss.test.osgi.example.microcontainer.MicrocontainerTestCase
- Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.444 sec
- Running org.jboss.test.osgi.example.xml.parser.SAXParserTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.452 sec
- Running org.jboss.test.osgi.example.http.HttpServiceTestCase
- Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.562 sec
- Running org.jboss.test.osgi.example.xml.parser.DOMParserTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.032 sec
- Running org.jboss.test.osgi.example.jndi.JNDITestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.836 sec
- Running org.jboss.test.osgi.example.jmx.JMXTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.058 sec
- Running org.jboss.test.osgi.example.simple.SimpleTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.772 sec
- Running org.jboss.test.osgi.example.simple.SimpleHuskyTestCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.262 sec
+ Running org.jboss.test.osgi.example.webapp.WebAppInterceptorTestCase
+ Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 14.417 sec
+ ...
- Tests run: 21, Failures: 0, Errors: 0, Skipped: 0
+ Tests run: 24, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
- [INFO] Total time: 49 seconds
- [INFO] Finished at: Tue Oct 13 13:04:20 CEST 2009
- [INFO] Final Memory: 25M/47M
+ [INFO] Total time: 1 minute 31 seconds
+ [INFO] Finished at: Tue Dec 08 11:15:08 CET 2009
+ [INFO] Final Memory: 35M/139M
[INFO] ------------------------------------------------------------------------
</programlisting>
@@ -361,28 +342,13 @@
<programlisting role="JAVA">
class Transactional implements Synchronization
{
- private String volatileMessage;
- private String message;
-
- public void beforeCompletion()
- {
- }
-
public void afterCompletion(int status)
{
if (status == Status.STATUS_COMMITTED)
message = volatileMessage;
}
- public String getMessage()
- {
- return message;
- }
-
- public void setMessage(String message)
- {
- this.volatileMessage = message;
- }
+ ...
}
</programlisting>
@@ -504,4 +470,127 @@
</programlisting>
</sect1>
+ <sect1 xml:id="SecXMLBindingServiceExample">
+ <title>XML Unmarshaller Service</title>
+
+ <para>The <emphasis role="bold">example-xml-binding.jar</emphasis> bundle unmarshalls an XML document through the UnmarshallerService.
+ This example is very similar to the <link linkend="SecJAXBServiceExample">JAXB Example</link>. However, it uses JBossXB to do the
+ unmarshalling.</para>
+
+ <programlisting role="JAVA">
+ ServiceReference sref = context.getServiceReference(UnmarshallerService.class.getName());
+ UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
+
+ Bundle bundle = context.getBundle();
+ URL xsdurl = bundle.getEntry("booking.xsd");
+ URL xmlurl = bundle.getEntry("booking.xml");
+
+ unmarshaller.registerSchemaLocation("http://org.jboss.test.osgi.jbossxb.simple/booking.xsd", xsdurl.toExternalForm());
+ unmarshaller.addClassBinding(CourseBooking.NAMESPACE_XML_SIMPLE, CourseBooking.class);
+
+ CourseBooking booking = (CourseBooking)unmarshaller.unmarshal(xmlurl.toExternalForm());
+ </programlisting>
+ </sect1>
+
+ <sect1 xml:id="SecInterceptorExample">
+ <title>Lifecycle Interceptor</title>
+
+ <para>The interceptor example deployes a bundle that contains some metadata and an interceptor bundle that processes
+ the metadata and registeres an http endpoint from it. The idea is that the bundle does not process its own metadata.
+ Instead this work is delegated to some specialized metadata processor (i.e. the interceptor).</para>
+
+ <para>Each interceptor is itself registered as a service. This is the well known <ulink url="www.osgi.org/wiki/uploads/Links/whiteboard.pdf">
+ Whiteboard Pattern</ulink>.</para>
+
+ <programlisting role="JAVA">
+ public class InterceptorActivator implements BundleActivator
+ {
+ public void start(BundleContext context)
+ {
+ LifecycleInterceptor publisher = new PublisherInterceptor();
+ LifecycleInterceptor parser = new ParserInterceptor();
+
+ // Add the interceptors, the order of which is handles by the service
+ context.registerService(LifecycleInterceptor.class.getName(), publisher, null);
+ context.registerService(LifecycleInterceptor.class.getName(), parser, null);
+ }
+ }
+ </programlisting>
+
+ <programlisting role="JAVA">
+ public class ParserInterceptor extends AbstractLifecycleInterceptor
+ {
+ ParserInterceptor()
+ {
+ // Add the provided output
+ addOutput(HttpMetadata.class);
+ }
+
+ public void invoke(int state, InvocationContext context)
+ {
+ // Do nothing if the metadata is already available
+ HttpMetadata metadata = context.getAttachment(HttpMetadata.class);
+ if (metadata != null)
+ return;
+
+ // Parse and create metadta on STARTING
+ if (state == Bundle.STARTING)
+ {
+ VirtualFile root = context.getRoot();
+ VirtualFile propsFile = root.getChild("/http-metadata.properties");
+ if (propsFile != null)
+ {
+ log.info("Create and attach HttpMetadata");
+ metadata = createHttpMetadata(propsFile);
+ context.addAttachment(HttpMetadata.class, metadata);
+ }
+ }
+ }
+ ...
+ }
+ </programlisting>
+
+ <programlisting role="JAVA">
+ public class PublisherInterceptor extends AbstractLifecycleInterceptor
+ {
+ PublisherInterceptor()
+ {
+ // Add the required input
+ addInput(HttpMetadata.class);
+ }
+
+ public void invoke(int state, InvocationContext context)
+ {
+ // HttpMetadata is guaratied to be available because we registered
+ // this type as required input
+ HttpMetadata metadata = context.getAttachment(HttpMetadata.class);
+
+ // Register HttpMetadata on STARTING
+ if (state == Bundle.STARTING)
+ {
+ String servletName = metadata.getServletName();
+
+ // Load the endpoint servlet from the bundle
+ Bundle bundle = context.getBundle();
+ Class servletClass = bundle.loadClass(servletName);
+ HttpServlet servlet = (HttpServlet)servletClass.newInstance();
+
+ // Register the servlet with the HttpService
+ HttpService httpService = getHttpService(context, true);
+ httpService.registerServlet("/servlet", servlet, null, null);
+ }
+
+ // Unregister the endpoint on STOPPING
+ else if (state == Bundle.STOPPING)
+ {
+ log.info("Unpublish HttpMetadata: " + metadata);
+ HttpService httpService = getHttpService(context, false);
+ if (httpService != null)
+ httpService.unregister("/servlet");
+ }
+ }
+ }
+ </programlisting>
+ </sect1>
+
</chapter>
Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/pom.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -67,7 +67,7 @@
<version.jboss.osgi.runtime.equinox>3.5.1</version.jboss.osgi.runtime.equinox>
<version.jboss.osgi.runtime.felix>2.0.2</version.jboss.osgi.runtime.felix>
<version.jboss.osgi.runtime.jbossas>1.0.2</version.jboss.osgi.runtime.jbossas>
- <version.jboss.osgi.spi>1.0.3</version.jboss.osgi.spi>
+ <version.jboss.osgi.spi>1.0.3-SNAPSHOT</version.jboss.osgi.spi>
<version.jboss.osgi.webapp>0.7.2</version.jboss.osgi.webapp>
<version.jboss.osgi.webconsole>1.0.2</version.jboss.osgi.webconsole>
<version.jboss.osgi.xml.binding>2.0.2.Beta3</version.jboss.osgi.xml.binding>
Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -45,6 +45,9 @@
<!-- blueprint -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-blueprint.jar" files="${tests.resources.dir}/blueprint/example-blueprint.bnd" />
+ <!-- event -->
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-event.jar" files="${tests.resources.dir}/event/example-event.bnd" />
+
<!-- http -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-http.jar" files="${tests.resources.dir}/http/example-http.bnd" />
Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -29,6 +29,7 @@
<include>*:jboss-osgi-webapp:jar</include>
<include>*:jboss-osgi-xml-binding:jar</include>
<include>*:org.apache.felix.configadmin:jar</include>
+ <include>*:org.apache.felix.eventadmin:jar</include>
<include>*:org.apache.felix.log:jar</include>
<include>*:org.apache.felix.metatype:jar</include>
<include>*:pax-web-extender-war:jar</include>
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/EventAdminTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/EventAdminTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/EventAdminTestCase.java 2009-12-08 14:13:08 UTC (rev 97538)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.event;
+
+//$Id$
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeNotNull;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.jboss.osgi.husky.BridgeFactory;
+import org.jboss.osgi.husky.HuskyCapability;
+import org.jboss.osgi.husky.RuntimeContext;
+import org.jboss.osgi.spi.capability.EventAdminCapability;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * A test that deployes a bundle that containes a HttpServlet which is registered through the OSGi HttpService
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 08-Dec-2009
+ */
+public class EventAdminTestCase extends OSGiTest
+{
+ static String TOPIC = "org/jboss/test/osgi/example/event";
+
+ @RuntimeContext
+ public BundleContext context;
+
+ private OSGiRuntime runtime;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ if (context == null)
+ {
+ runtime = getDefaultRuntime();
+ runtime.addCapability(new HuskyCapability());
+ runtime.addCapability(new EventAdminCapability());
+
+ OSGiBundle bundle = runtime.installBundle("example-event.jar");
+ bundle.start();
+ }
+ }
+
+ @After
+ public void tearDown() throws BundleException
+ {
+ if (context == null)
+ runtime.shutdown();
+ }
+
+ @Test
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void testEventHandler() throws Exception
+ {
+ if (context == null)
+ BridgeFactory.getBridge().run();
+
+ assumeNotNull(context);
+
+ // Register the EventHandler
+ Dictionary param = new Hashtable();
+ param.put(EventConstants.EVENT_TOPIC, new String[] { TOPIC });
+ TestEventHandler eventHandler = new TestEventHandler();
+ context.registerService(EventHandler.class.getName(), eventHandler, param);
+
+ ServiceReference sref = context.getServiceReference(EventAdmin.class.getName());
+ EventAdmin eventAdmin = (EventAdmin)context.getService(sref);
+ eventAdmin.sendEvent(new Event(TOPIC, null));
+
+ assertEquals("Event received", 1, eventHandler.received.size());
+ assertEquals(TOPIC, eventHandler.received.get(0).getTopic());
+ }
+
+ static class TestEventHandler implements EventHandler
+ {
+ List<Event> received = new ArrayList<Event>();
+
+ public void handleEvent(Event event)
+ {
+ received.add(event);
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/event/EventAdminTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jbossxb/XMLBindingActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jbossxb/XMLBindingActivator.java 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jbossxb/XMLBindingActivator.java 2009-12-08 14:13:08 UTC (rev 97538)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.osgi.example.xml.jbossxb;
-
-//$Id$
-
-import java.net.URL;
-
-import org.jboss.osgi.jbossxb.UnmarshallerService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-/**
- * A bundle activator that uses the unmarshaller service
- *
- * @author thomas.diesler at jboss.com
- * @since 26-Nov-2009
- */
-public class XMLBindingActivator implements BundleActivator
-{
- public void start(BundleContext context) throws Exception
- {
- ServiceReference sref = context.getServiceReference(UnmarshallerService.class.getName());
- UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
- unmarshaller.setSchemaValidation(true);
- unmarshaller.setNamespaceAware(true);
- unmarshaller.setValidation(true);
-
- Bundle bundle = context.getBundle();
- URL xsdurl = bundle.getEntry("booking.xsd");
- URL xmlurl = bundle.getEntry("booking.xml");
-
- unmarshaller.registerSchemaLocation("http://org.jboss.test.osgi.jbossxb.simple/booking.xsd", xsdurl.toExternalForm());
- unmarshaller.addClassBinding(CourseBooking.NAMESPACE_XML_SIMPLE, CourseBooking.class);
-
- unmarshaller.unmarshal(xmlurl.toExternalForm());
- }
-
- public void stop(BundleContext context) throws Exception
- {
- }
-}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/event/example-event.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/event/example-event.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/event/example-event.bnd 2009-12-08 14:13:08 UTC (rev 97538)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example/example-event.jar src/test/resources/example/event/example-event.bnd
+
+Bundle-SymbolicName: example-event
+Export-Package: org.jboss.test.osgi.example.event
+Import-Package: org.osgi.framework, org.osgi.service.event, org.jboss.osgi.husky, org.jboss.osgi.spi.capability, org.jboss.osgi.testing, org.junit
+
+# Tell Husky that there are test cases in this package
+Test-Package: org.jboss.test.osgi.example.event
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jbossxb/example-xml-binding.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jbossxb/example-xml-binding.bnd 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jbossxb/example-xml-binding.bnd 2009-12-08 14:13:08 UTC (rev 97538)
@@ -1,8 +1,6 @@
# bnd build -classpath target/test-classes -output target/test-libs/example-xml-binding.jar src/test/resources/simple/example-xml-binding.bnd
Bundle-SymbolicName: example-xml-binding
-Bundle-Activator: org.jboss.test.osgi.example.xml.jbossxb.XMLBindingActivator
-
Export-Package: org.jboss.test.osgi.example.xml.jbossxb
Import-Package: \
Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml 2009-12-08 14:05:24 UTC (rev 97537)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml 2009-12-08 14:13:08 UTC (rev 97538)
@@ -75,6 +75,36 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.eventadmin</artifactId>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.metatype</artifactId>
<scope>provided</scope>
<exclusions>
More information about the jboss-cvs-commits
mailing list