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?
--
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: [email protected]
For additional commands, e-mail: [email protected]