felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amey_borkar <ameyborka...@gmail.com>
Subject Servlet registration in OSGi fails with custom org.osgi.service.http.HttpContext object
Date Fri, 27 Jun 2014 17:29:31 GMT
I am working on servlet registration in osgi bundle.To support MIME mapping I
want to write custom implementation of HttpContext and want HttpService to
call it instead of default HttpContext.

/public final class Activator implements BundleActivator{
   public void start( BundleContext bc ){

   private ServiceReference httpServiceRef;
   httpServiceRef = bc.getServiceReference( HttpService.class.getName());
   final HttpService httpService = (HttpService) bc.getService(
httpServiceRef );

   httpService.registerServlet("/hi",new MyServlet(),new MyHttpContext());}/

MyHttpContext looks like this:

/public class MyHttpContext implements HttpContext {

public URL getResource(String name) {
    // TODO Auto-generated method stub
    return null;

public String getMimeType(String name) {
    // TODO Auto-generated method stub
    System.out.println("Name: "+name);
    if (name.endsWith(".jpg"))
        return "image/jpeg";
    else if (name.endsWith(".pdf"))
        return "application/pdf";
    else if (name.endsWith(".txt"))
        return "text/plain";
        return "text/html";


public boolean handleSecurity(HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    // TODO Auto-generated method stub
    return false;

The servlet is not getting called when I try to hit the correct url.
However,it works if I pass null as a third parameter in registerServlet() in
which case httpservice internally uses default HttpContext.

What can probably be wrong with my custom implementation? Am I missing
something in getResource() method?

View this message in context: http://apache-felix.18485.x6.nabble.com/Servlet-registration-in-OSGi-fails-with-custom-org-osgi-service-http-HttpContext-object-tp5008835.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.

To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org

View raw message