org.apache.felix.http.base.internal.service
Class HttpServiceImpl

java.lang.Object
  extended by org.apache.felix.http.base.internal.service.HttpServiceImpl
All Implemented Interfaces:
ExtHttpService, HttpService

public final class HttpServiceImpl
extends Object
implements ExtHttpService


Constructor Summary
HttpServiceImpl(Bundle bundle, ServletContext context, HandlerRegistry handlerRegistry, javax.servlet.ServletContextAttributeListener servletAttributeListener, boolean sharedContextAttributes)
           
 
Method Summary
 HttpContext createDefaultHttpContext()
          Creates a default HttpContext for registering servlets or resources with the HttpService, a new HttpContext object is created each time this method is called.
 void registerFilter(javax.servlet.Filter filter, String pattern, Dictionary initParams, int ranking, HttpContext context)
           
 void registerResources(String alias, String name, HttpContext context)
          Registers resources into the URI namespace.
 void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext context)
          Registers a servlet into the URI namespace.
 void unregister(String alias)
          Unregisters a previous registration done by registerServlet or registerResources methods.
 void unregisterAll()
           
 void unregisterFilter(javax.servlet.Filter filter)
           
 void unregisterServlet(Servlet servlet)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServiceImpl

public HttpServiceImpl(Bundle bundle,
                       ServletContext context,
                       HandlerRegistry handlerRegistry,
                       javax.servlet.ServletContextAttributeListener servletAttributeListener,
                       boolean sharedContextAttributes)
Method Detail

registerFilter

public void registerFilter(javax.servlet.Filter filter,
                           String pattern,
                           Dictionary initParams,
                           int ranking,
                           HttpContext context)
                    throws ServletException
Specified by:
registerFilter in interface ExtHttpService
Throws:
ServletException

unregisterFilter

public void unregisterFilter(javax.servlet.Filter filter)
Specified by:
unregisterFilter in interface ExtHttpService

unregisterServlet

public void unregisterServlet(Servlet servlet)
Specified by:
unregisterServlet in interface ExtHttpService

registerServlet

public void registerServlet(String alias,
                            Servlet servlet,
                            Dictionary initParams,
                            HttpContext context)
                     throws ServletException,
                            NamespaceException
Description copied from interface: HttpService
Registers a servlet into the URI namespace.

The alias is the name in the URI namespace of the Http Service at which the registration will be mapped.

An alias must begin with slash ('/') and must not end with slash ('/'), with the exception that an alias of the form "/" is used to denote the root alias. See the specification text for details on how HTTP requests are mapped to servlet and resource registrations.

The Http Service will call the servlet's init method before returning.

 httpService.registerServlet("/myservlet", servlet, initparams, context);
 

Servlets registered with the same HttpContext object will share the same ServletContext. The Http Service will call the context argument to support the ServletContext methods getResource,getResourceAsStream and getMimeType, and to handle security for requests. If the context argument is null, a default HttpContext object is used (see HttpService.createDefaultHttpContext()).

Specified by:
registerServlet in interface HttpService
Parameters:
alias - name in the URI namespace at which the servlet is registered
servlet - the servlet object to register
initParams - initialization arguments for the servlet or null if there are none. This argument is used by the servlet's ServletConfig object.
context - the HttpContext object for the registered servlet, or null if a default HttpContext is to be created and used.
Throws:
ServletException - if the servlet's init method throws an exception, or the given servlet object has already been registered at a different alias.
NamespaceException - if the registration fails because the alias is already in use.

registerResources

public void registerResources(String alias,
                              String name,
                              HttpContext context)
                       throws NamespaceException
Description copied from interface: HttpService
Registers resources into the URI namespace.

The alias is the name in the URI namespace of the Http Service at which the registration will be mapped. An alias must begin with slash ('/') and must not end with slash ('/'), with the exception that an alias of the form "/" is used to denote the root alias. The name parameter must also not end with slash ('/') with the exception that a name of the form "/" is used to denote the root of the bundle. See the specification text for details on how HTTP requests are mapped to servlet and resource registrations.

For example, suppose the resource name /tmp is registered to the alias /files. A request for /files/foo.txt will map to the resource name /tmp/foo.txt.

 httpservice.registerResources("/files", "/tmp", context);
 
The Http Service will call the HttpContext argument to map resource names to URLs and MIME types and to handle security for requests. If the HttpContext argument is null, a default HttpContext is used (see HttpService.createDefaultHttpContext()).

Specified by:
registerResources in interface HttpService
Parameters:
alias - name in the URI namespace at which the resources are registered
name - the base name of the resources that will be registered
context - the HttpContext object for the registered resources, or null if a default HttpContext is to be created and used.
Throws:
NamespaceException - if the registration fails because the alias is already in use.

unregister

public void unregister(String alias)
Description copied from interface: HttpService
Unregisters a previous registration done by registerServlet or registerResources methods.

After this call, the registered alias in the URI name-space will no longer be available. If the registration was for a servlet, the Http Service must call the destroy method of the servlet before returning.

If the bundle which performed the registration is stopped or otherwise "unget"s the Http Service without calling HttpService.unregister(java.lang.String) then Http Service must automatically unregister the registration. However, if the registration was for a servlet, the destroy method of the servlet will not be called in this case since the bundle may be stopped. HttpService.unregister(java.lang.String) must be explicitly called to cause the destroy method of the servlet to be called. This can be done in the BundleActivator.stop method of the bundle registering the servlet.

Specified by:
unregister in interface HttpService
Parameters:
alias - name in the URI name-space of the registration to unregister

createDefaultHttpContext

public HttpContext createDefaultHttpContext()
Description copied from interface: HttpService
Creates a default HttpContext for registering servlets or resources with the HttpService, a new HttpContext object is created each time this method is called.

The behavior of the methods on the default HttpContext is defined as follows:

Specified by:
createDefaultHttpContext in interface HttpService
Returns:
a default HttpContext object.

unregisterAll

public void unregisterAll()


Copyright © 2011 Apache Software Foundation. All Rights Reserved.