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]  
>  
>  

Reply via email to