Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Servlet registration in OSGi fails with custom org.osgi.service.http.HttpContext object
icon5.gif  Servlet registration in OSGi fails with custom org.osgi.service.http.HttpContext object [message #1389320] Fri, 27 June 2014 16:31 Go to next message
Amey Borkar is currently offline Amey BorkarFriend
Messages: 5
Registered: June 2014
Junior Member
Hi Everyone,

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 {

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

@Override
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";
    else
        return "text/html";

}

@Override
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?
Re: Servlet registration in OSGi fails with custom org.osgi.service.http.HttpContext object [message #1389460 is a reply to message #1389320] Fri, 27 June 2014 21:25 Go to previous message
BJ Hargrave is currently offline BJ HargraveFriend
Messages: 60
Registered: July 2009
Member
Your handleSecurity method returns false which means reject the request.

	 * @return {@code true} if the request should be serviced, {@code false} if
	 *         the request should not be serviced and Http Service will send the
	 *         response back to the client.
Previous Topic:servlet-listener and MIME type support for equinox
Next Topic:[Cancelled] Eclipse Luna: problem with patch fragments
Goto Forum:
  


Current Time: Tue Apr 16 03:49:57 GMT 2024

Powered by FUDForum. Page generated in 0.13249 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top