java ee - Servlet registration in OSGi fails with custom org.osgi.service.http.HttpContext object -
i working on servlet registration in osgi bundle.to support mime mapping want write custom implementation of httpcontext , want httpservice call 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 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 not getting called when try hit correct url. however,it works if pass null third parameter in registerservlet() in case httpservice internally uses default httpcontext.
what can wrong custom implementation? missing in getresource() method?
see javadoc of handlesecurity function:
returns true if request should serviced, false if request should not serviced , http service send response client.
Comments
Post a Comment