Return-Path: X-Original-To: apmail-felix-users-archive@minotaur.apache.org Delivered-To: apmail-felix-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 71FE6E216 for ; Thu, 14 Mar 2013 14:31:27 +0000 (UTC) Received: (qmail 74823 invoked by uid 500); 14 Mar 2013 14:31:24 -0000 Delivered-To: apmail-felix-users-archive@felix.apache.org Received: (qmail 74487 invoked by uid 500); 14 Mar 2013 14:31:24 -0000 Mailing-List: contact users-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@felix.apache.org Delivered-To: mailing list users@felix.apache.org Received: (qmail 74023 invoked by uid 99); 14 Mar 2013 14:31:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2013 14:31:23 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of chetan.mehrotra@gmail.com designates 209.85.214.179 as permitted sender) Received: from [209.85.214.179] (HELO mail-ob0-f179.google.com) (209.85.214.179) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2013 14:31:16 +0000 Received: by mail-ob0-f179.google.com with SMTP id un3so2209086obb.38 for ; Thu, 14 Mar 2013 07:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=QVYP+uoojMgKgUEef5JDdOsyvQZ9tMc0ypVPQHxh+Ag=; b=Zs3mnJmHB6Li0DY0/OOEwhZZ22dtwav7DmjmCbMw13VD6vYcCDo0oge4mLdRPKTp3T a877OUkG0jsgkZhpMgovpRSCNqEwCGuhOQ9aDzgpLKAv4M3B+wKURoITPEf9rkcD+9Tr na9gYvhu4qua4ZtgPpiJBWoOKu9GI689GPkk+sdMcuGXWI5unrhH/GJrRN6ZbpY6gDh4 Nmk1irKBboj7jdr7pw6JPDaJT341Y7IAPt9zL1yJpmaOiuBDBxc5gc7uPK9RWOcuomUs jPcfeFV5XDqgziCdaNfYsj0Kf9eosULqrXUYdNzNKBUyMuWkfLwL/wyLWotUPQUu7V1T 1rbA== MIME-Version: 1.0 X-Received: by 10.182.134.100 with SMTP id pj4mr1242045obb.64.1363271455014; Thu, 14 Mar 2013 07:30:55 -0700 (PDT) Received: by 10.60.34.132 with HTTP; Thu, 14 Mar 2013 07:30:54 -0700 (PDT) In-Reply-To: <82112B3C-468C-47A9-9BB9-F6421A542F94@adobe.com> References: <68F5378B-2205-453A-AF7B-8BC0BECEE1B5@adobe.com> <82112B3C-468C-47A9-9BB9-F6421A542F94@adobe.com> Date: Thu, 14 Mar 2013 20:00:54 +0530 Message-ID: Subject: Re: No HttpService available From: Chetan Mehrotra To: "users@felix.apache.org" Content-Type: multipart/alternative; boundary=e89a8f83aa33cf07f804d7e35e07 X-Virus-Checked: Checked by ClamAV on apache.org --e89a8f83aa33cf07f804d7e35e07 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable >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? Not necessarily. The story with Http Bridge stuff is bit convoluted. The bridge bundle Activator registers a DispatcherServlet. The Felix proxy servlet registers a tracker for that servlet and upon its registration it triggers a call which leads to registration of HttpService. In brief the HttpService would be registered in asynchronous manner and *might* not be present when your activator gets called >i rewrote the EmbeddedServletActivator to use a ServiceTracker The way you are using the tracker would not work. If you immediately call the getService in activator you are effectively having the same logic which does not used tracker. Instead you should use tracker as mentioned in [1]. Below is your code modified to use tracker (sort of example). The main change here is that you register the servlet in 'addingService' callback in tracker. public class EmbeddedServletActivator implements BundleActivator{ public static final String ALIAS =3D "/hello"; private HttpTracker tracker; public void start(BundleContext context) throws Exception { ServiceReference sRef =3D context.getServiceReference(HttpService.class.getName()); if (sRef !=3D null) { HttpService service =3D (HttpService)context.getService(sRef); service.registerServlet("/hello", new HelloWorldServlet(), null, null); } else { System.out.println("no HttpService found to register Servlet for /hello"); } tracker =3D new HttpTracker(context); tracker.open(); } public void stop(BundleContext context) throws Exception { ServiceReference sRef =3D context.getServiceReference(HttpService.class.getName()); if (sRef !=3D null) { HttpService service =3D (HttpService)context.getService(sRef); try { service.unregister("/hello"); } catch (IllegalArgumentException e) { System.out.println("/hello wasn't registered in HttpService"); } } else { System.out.println("not HttpService found to unregister Servlet for /hello"); } if(tracker !=3D null){ tracker.close(); } } private class HttpTracker extends ServiceTracker { public HttpTracker(BundleContext context) { super(context, HttpService.class.getName(), null); } public Object addingService(ServiceReference reference) { HttpService service =3D (HttpService) super.addingService(reference); try { service.registerServlet("/hello", new HelloWorldServlet(), null, null); } catch (ServletException e) { e.printStackTrace(); } catch (NamespaceException e) { e.printStackTrace(); } System.out.println("Registered Servlet for /hello"); return service; } public void remove(ServiceReference reference) { ((HttpService)getService()).unregister("/hello"); super.remove(reference); } } } regards Chetan [1] http://www.aqute.biz/Snippets/Tracker Chetan Mehrotra On Thu, Mar 14, 2013 at 7:34 PM, Felix Meschberger wrot= e: > Hi > > Could it be that the Http Service API exists twice in your framework ? An= d > thus your sample bundle and the Web Console and bridge bundles use > different API wirings ? > > You can cross check in the web console to which bundle a specific package > is wired by looking at the details of a bundle and checking the imports > (which contains the wire sources) > > Regards > Felix > > Am 14.03.2013 um 14:35 schrieb Stephan Schr=F6der: > > >> Can you verify the HttpService is available at all in the framework ? > >> (You might try to access the web console) > > The web console seems to be available. Requesting " > http://localhost:8080/system/console/bundles" leads to: > > 'A username and password are being requested by http://localhost:8080. > The site says: "OSGi Management Console"' > > So i assume the HttpService is available. > > > > i rewrote the EmbeddedServletActivator to use a ServiceTracker > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > > @Override > > public void start(BundleContext context) throws Exception > > { > > httpServiceTracker =3D new ServiceTracker(context, > HttpService.class.getName(), null); > > httpServiceTracker.open(); > > > > System.out.println("Looking for HttpService"); > > final HttpService httpService =3D > (HttpService)httpServiceTracker.getService(); > > > > if(httpService!=3Dnull) { > > System.out.println("Found HttpSerice"); > > httpService.registerServlet(ALIAS, new HelloWorldServlet(), > null, null); > > System.out.println("registered "+ALIAS+" with HttpService"); > > }else{ > > System.out.println("httpServiceTracker.getService() returned > null"); > > } > > } > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > which lead to > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > > Starting bundle [com.mobenga.HelloWorldServletEmbedded] > > Looking for HttpService > > httpServiceTracker.getService() returned null > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > so no change there. > > > > /Stephan > > > > > > Gesendet: Donnerstag, 14. M=E4rz 2013 um 13:46 Uhr > > Von: "Felix Meschberger" > > An: "users@felix.apache.org" > > Betreff: Re: No HttpService available > > Hi > > > > Can you verify the HttpService is available at all in the framework ? > (You might try to access the web console) > > > > If not, you might have an issue to not properly setup the Http Service > bridge: This requires wiring from the servlet which is actually deployed = in > the servlet container. See [1] and the linked examples for details. > > > > Regards > > Felix > > > > [1] > http://felix.apache.org/documentation/subprojects/apache-felix-http-servi= ce.html#using-the-servlet-bridge > > > > Am 14.03.2013 um 12:50 schrieb Stephan Schr=F6der: > > > >> 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 =3D > context.getServiceReference(HttpService.class.getName()); > >> if (sRef !=3D null) > >> { > >> HttpService service =3D (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.j= ar] > >> 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.ja= r] > >> 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=3Dsh= aring[https://docs.google.com/file/d/0BwYlZDH_xJugamxJQ2QzaWJULVU/edit?usp= =3Dsharing] > >> > >> Regards, > >> Stephan > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org > >> For additional commands, e-mail: users-help@felix.apache.org > >> > > > > > > -- > > Felix Meschberger | Principal Scientist | Adobe > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org > > For additional commands, e-mail: users-help@felix.apache.org > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org > > For additional commands, e-mail: users-help@felix.apache.org > > > > > -- > Felix Meschberger | Principal Scientist | Adobe > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org > For additional commands, e-mail: users-help@felix.apache.org > > --e89a8f83aa33cf07f804d7e35e07--