That worked like a charm! Thank u so much !! On Mon, Feb 16, 2015 at 10:47 AM, clement escoffier < [email protected]> wrote:
> You should update the iPOJO Maven Plugin to latest version (1.12.1), the > one you are using is really (really) old. > > Cheers, > > Clement > > 2015-02-16 16:42 GMT+01:00 Ascharya Shetty <[email protected]>: > > > I tried but with no luck. I am just wondering if I have configured the > > maven files correctly. > > I get the following exception: > > createInstance -> The POJO constructor invocation failed : Expecting a > > stackmap frame at branch target 22 > > Exception Details: > > Location: > > > > > > > com/test/component/service/MyServlet.__doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V > > @8: aload_2 > > Reason: > > Expected stackmap frame at this location. > > Bytecode: > > 0000000: b200 8912 8bb6 0090 2cb9 0096 0100 1298 > > 0000010: b600 9ba7 0008 4e2d b600 9cb1 > > Exception Handler Table: > > bci [8, 19] => handler: 22 > > > > java.lang.VerifyError: Expecting a stackmap frame at branch target 22 > > Exception Details: > > Location: > > > > > > > com/test/component/service/MyServlet.__doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V > > @8: aload_2 > > Reason: > > Expected stackmap frame at this location. > > Bytecode: > > 0000000: b200 8912 8bb6 0090 2cb9 0096 0100 1298 > > 0000010: b600 9ba7 0008 4e2d b600 9cb1 > > Exception Handler Table: > > bci [8, 19] => handler: 22 > > > > at java.lang.Class.getDeclaredConstructors0(Native Method) > > at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585) > > at java.lang.Class.getConstructor0(Class.java:2885) > > at java.lang.Class.getDeclaredConstructor(Class.java:2058) > > at > > > > > org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:746) > > at > > > > > org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.java:963) > > at > > > > > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:156) > > at > > > > > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java) > > at > > org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560) > > at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440) > > at > > > > > org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179) > > at > > > > > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319) > > at > > > > > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240) > > at > > > > > org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312) > > at > > > > > org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306) > > at > > > > > org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114) > > at java.util.concurrent.FutureTask.run(FutureTask.java:262) > > at > > > > > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) > > at > > > > > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) > > at java.lang.Thread.run(Thread.java:745) > > [ERROR] com.test.component.service.MyServlet : Cannot create a POJO > > instance, the POJO constructor invocation has thrown an exception > > > > so this is how my servlet looks : > > import java.io.IOException; > > > > import javax.servlet.ServletException; > > import javax.servlet.http.HttpServlet; > > import javax.servlet.http.HttpServletRequest; > > import javax.servlet.http.HttpServletResponse; > > > > import org.apache.felix.ipojo.annotations.Bind; > > import org.apache.felix.ipojo.annotations.Component; > > import org.apache.felix.ipojo.annotations.Instantiate; > > import org.apache.felix.ipojo.annotations.ServiceProperty; > > import org.apache.felix.ipojo.annotations.Unbind; > > import org.osgi.service.http.HttpService; > > import org.osgi.service.http.NamespaceException; > > > > @Component(immediate = true) > > @Instantiate > > @Provides > > public class MyServlet extends HttpServlet { > > @ServiceProperty > > private String SERVLET_ALIAS = "/hello"; > > > > @Bind > > public void bindHttp(HttpService httpService) { > > try { > > httpService.registerServlet(SERVLET_ALIAS, this, null, null); > > } catch (ServletException | NamespaceException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } > > } > > > > @Unbind > > public void unbindHttp(HttpService httpService) { > > httpService.unregister(SERVLET_ALIAS); > > } > > > > @Override > > public void doGet(HttpServletRequest request, HttpServletResponse > response) > > { > > System.out.println("Hello"); > > try { > > response.getWriter().println("Hello World!"); > > } catch (IOException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } > > } > > > > } > > > > > > Maven file : > > Just the plugin portion: > > <plugin> > > <groupId>org.apache.maven.plugins</groupId> > > <artifactId>maven-compiler-plugin</artifactId> > > <version>3.1</version> > > <configuration> > > <source>1.7</source> > > <target>1.7</target> > > </configuration> > > </plugin> > > > > <plugin> > > <groupId>org.apache.felix</groupId> > > <artifactId>maven-ipojo-plugin</artifactId> > > <version>1.6.0</version> > > <executions> > > <execution> > > <goals> > > <goal>ipojo-bundle</goal> > > </goals> > > </execution> > > </executions> > > </plugin> > > <plugin> > > <groupId>org.apache.maven.plugins</groupId> > > <artifactId>maven-compiler-plugin</artifactId> > > <configuration> > > <source>1.7</source> > > <target>1.7</target> > > </configuration> > > </plugin> > > <plugin> > > <groupId>org.apache.felix</groupId> > > <artifactId>maven-bundle-plugin</artifactId> > > <extensions>true</extensions> > > <configuration> > > <instructions> > > <Import-Package> > > javax.crypto.*; javax.crypto.spec.*; javax.jms.*; > > javax.mail.*; > > javax.mail.internet.*; javax.naming.*; > > javax.naming.directory.*; > > javax.naming.ldap.*; javax.net.*; > > javax.net.ssl.*; > > javax.security.auth.x500.*; javax.servlet.*; > > javax.sql.*;javax.ws.rs.*;com.sun.jersey.api.core; > > com.sun.jersey.spi.container.servlet; > > org.osgi.*; resolution:=optional > > </Import-Package> > > <Embed-Dependency>httpclient; httpcore; gson; commons-logging; > > log4j;</Embed-Dependency> > > </instructions> > > </configuration> > > </plugin> > > > > > > > > > > On Sat, Feb 14, 2015 at 1:35 PM, Clement Escoffier < > > [email protected]> wrote: > > > > > Hi, > > > > > > Oh, you are not using the whiteboard pattern, so the code should be > > > something like: > > > > > > @Component(immediate=true) > > > @Instantiate > > > public class MyServlet extends HttpServlet { > > > > > > @Bind > > > public void bindHttp(HttpService svc) { > > > svc.registerServlet(alias, this, null, null); > > > } > > > > > > @Unbind > > > public void unbindHttp(HttpService svc) { > > > svc.unregisterServlet(alias); > > > } > > > > > > } > > > > > > Cheers, > > > > > > Clement > > > > > > > > > On 13 février 2015 at 17:04:53, Ascharya Shetty ([email protected]) > > > wrote: > > > > > > Thanks. I agree with David. There is something more than just the three > > > annotations which Clement has mentioned. > > > My servlet looks like this : > > > > > > package com.test.ipojo.example; > > > @Component(immediate=true) > > > //provides a service > > > @Instantiate > > > @Provides(specifications={HttpServlet.class}) > > > public class MyServlet extends HttpServlet{ > > > @ServiceProperty(name="alias", value="/hello") > > > private String alias ; > > > public MyServlet(@Requires HttpService httpService) throws > > > ServletException, NamespaceException{ > > > httpService.registerServlet(alias,this, null, null); > > > } > > > public void doGet(HttpServletRequest request, HttpServletResponse > > > response){ > > > System.out.println("Hello"); > > > try { > > > response.getWriter().println("Hello World!"); > > > } catch (IOException e) { > > > // TODO Auto-generated catch block > > > e.printStackTrace(); > > > } > > > } > > > } > > > Also, i am not very sure if I am configuring the maven build plugin the > > > right way:(ignore the other irrelevant packages.) > > > <plugin> > > > <groupId>org.apache.felix</groupId> > > > <artifactId>maven-bundle-plugin</artifactId> > > > <extensions>true</extensions> > > > <configuration> > > > <instructions> > > > <Export-Package> > > > com.test.ipojo.example > > > </Export-Package> > > > <Import-Package> > > > javax.crypto.*; javax.crypto.spec.*; javax.jms.*; > > > javax.mail.*; > > > javax.mail.internet.*; javax.naming.*; > > > javax.naming.directory.*; > > > javax.naming.ldap.*; javax.net.*; > > > javax.net.ssl.*; > > > javax.security.auth.x500.*; javax.servlet.*; > > > javax.sql.*; > > > org.osgi.*; resolution:=optional > > > </Import-Package> > > > <Embed-Dependency>httpclient; httpcore; gson; commons-logging; > > > log4j;</Embed-Dependency> > > > </instructions> > > > </configuration> > > > </plugin> > > > > > > > > > On Fri, Feb 13, 2015 at 10:06 AM, David Bosschaert < > > > [email protected]> wrote: > > > > > > > I guess if you want a servlet registered in the service registry this > > > > is typically to have it picked up by something like the Http > > > > Whiteboard implementation. For that you cannot register it under > > > > HttpServlet but it has to be registered as a javax.servlet.Servlet. > > > > I'm not familiar with the iPojo annotations, but I guess the above > > > > example would need to be tweaked in such a case... > > > > > > > > Cheers, > > > > > > > > David > > > > > > > > On 13 February 2015 at 15:58, clement escoffier > > > > <[email protected]> wrote: > > > > > Hi, > > > > > > > > > > If you just want to register your service just do this: > > > > > > > > > > @Component > > > > > @Provides > > > > > @Instantiate > > > > > public class MyServlet extends HttpServlet { > > > > > ... > > > > > } > > > > > > > > > > @Component declares a component type, @Provides tells to iPOJO that > > > your > > > > > component is providing a service, and @Instantiate create an > instance > > > of > > > > > this component. > > > > > > > > > > Cheers, > > > > > > > > > > Clement > > > > > > > > > > > > > > > 2015-02-13 15:43 GMT+01:00 Ascharya Shetty <[email protected]>: > > > > > > > > > >> I have been struggling to use the right brew of annotations to get > > the > > > > >> servlet registered as a service using iPojo.Please let me know how > > can > > > > I do > > > > >> this? > > > > >> Thanks > > > > >> Ascharya > > > > >> > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [email protected] > > > > For additional commands, e-mail: [email protected] > > > > > > > > > > > > > >

