> you should not depend on HttpService being available when your bundle > activates true, and have to fix this later but as you can see my HelloWorldServlet-Bundle is actually the last to be started, so the HttpService should already be available, shouldn't it?
> unless your bundle starts at higher run level i actually use something similar: when you check where the bundles are loaded from, you'll see that every bundle extept the HelloWorldServlet one lies in systembundles, while the HelloWorldServlet-bundle lies in applicationbundles. And the ones in systembundles are guaranteed to be started before the ones in applicationbundles. > If you are only using Activator then you have two options i'm actually planing on taking the third option: using Blueprint to inject a HttpService(Proxy). But first i want to get the basic setup to work. /Stephan Gesendet: Donnerstag, 14. März 2013 um 13:10 Uhr Von: "Chetan Mehrotra" <[email protected]> An: "[email protected]" <[email protected]> Betreff: Re: No HttpService available As OSGi is a dynamic environment you should not depend on HttpService being available when your bundle activates (unless your bundle starts at higher run level). If you are only using Activator then you have two options 1. Use a ServiceTracker for HttpService [1] 2. Use Felix Whiteboard pattern [2]. You need to install Felix HTTP Whiteboard Bundle for that I find #2 easier to use regards Chetan [1] http://www.aqute.biz/Snippets/Tracker [2] http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html#using-the-whiteboard[http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html#using-the-whiteboard] Chetan Mehrotra On Thu, Mar 14, 2013 at 5:20 PM, "Stephan Schröder" <[email protected]>wrote: > Hi, > > i want to write a HelloWorld-Servlet using Felixes HttpServie. > The setup is to embedd Felix and the HelloWorldServlet in a war-file and > deploy this on Tomcat6. > > The BundleActivator for the HelloWorldServletBundle checks whether a > HttpServie is available a prints out an error message if that's not the > case: > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > > @Override > public void start(BundleContext context) throws Exception > { > ServiceReference sRef = > context.getServiceReference(HttpService.class.getName()); > if (sRef != null) > { > HttpService service = (HttpService) context.getService(sRef); > service.registerServlet(ALIAS, new HelloWorldServlet(), null, > null); > }else{ > System.out.println("no HttpService found to register Servlet > for "+ALIAS); > } > } > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > and sadly this is exectly what happens when deploying the war-file on > Tomcat6: > > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > Connected to server > [2013-03-14 12:34:42,775] Artifact felix-bridge:war exploded: Artifact is > being deployed, please wait... > starting OSGi > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.http.bridge-2.2.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.gogo.runtime_0.10.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.webconsole-3.1.8.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.http.base-2.2.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.bundlerepository-1.6.6.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.gogo.shell_0.10.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.http.api-2.2.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/systemBundles/org.apache.felix.gogo.command_0.12.0.jar] > Installing bundle > [jndi:/localhost/WEB-INF/applicationBundles/HelloWorldServletEmbedded-1.0-SNAPSHOT.jar] > Starting bundle [org.apache.felix.http.bridge] > [INFO] Started bridged http service > Starting bundle [org.apache.felix.gogo.runtime] > Starting bundle [org.apache.felix.webconsole] > Starting bundle [org.apache.felix.http.base] > Starting bundle [org.apache.felix.bundlerepository] > Starting bundle [org.apache.felix.gogo.shell] > Starting bundle [org.apache.felix.http.api] > Starting bundle [org.apache.felix.gogo.command] > Starting bundle [com.mobenga.HelloWorldServletEmbedded] > no HttpService found to register Servlet for /hello > <---no HttpService! > OSGi startet > [2013-03-14 12:34:43,176] Artifact felix-bridge:war exploded: Artifact is > deployed successfully > ____________________________ > Welcome to Apache Felix Gogo > > g! Mar 14, 2013 12:34:52 PM org.apache.catalina.startup.HostConfig > deployDirectory > INFO: Deploying web application directory manager > lb > START LEVEL 1 > ID|State |Level|Name > 0|Active | 0|System Bundle (4.0.2) > 1|Active | 1|Apache Felix Http Bridge (2.2.0) > 2|Active | 1|Apache Felix Gogo Runtime (0.10.0) > 3|Active | 1|Apache Felix Web Management Console (3.1.8) > 4|Active | 1|Apache Felix Http Base (2.2.0) > 5|Active | 1|Apache Felix Bundle Repository (1.6.6) > 6|Active | 1|Apache Felix Gogo Shell (0.10.0) > 7|Active | 1|Apache Felix Http Api (2.2.0) > 8|Active | 1|Apache Felix Gogo Command (0.12.0) > 9|Active | 1|HelloWorldServletEmbedded (1.0.0.SNAPSHOT) > g! > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > Because all bundles are active i assume i forgot some needed bundle or > configuration? > (I assume i don't need an embedded Jetty because this runs on top of > Tomcat!?) > > If you need more information here is the whole maven project as a zip: > > https://docs.google.com/file/d/0BwYlZDH_xJugamxJQ2QzaWJULVU/edit?usp=sharing[https://docs.google.com/file/d/0BwYlZDH_xJugamxJQ2QzaWJULVU/edit?usp=sharing] > > Regards, > Stephan > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

