org.apache.felix.httplite.osgi
Class HttpServiceImpl

java.lang.Object
  extended by org.apache.felix.httplite.osgi.HttpServiceImpl
All Implemented Interfaces:
ServiceRegistrationResolver, org.osgi.service.http.HttpService

public class HttpServiceImpl
extends java.lang.Object
implements org.osgi.service.http.HttpService, ServiceRegistrationResolver

The HTTP Service implementation that also implements RegistrationResolver to provide internal server classes with OSGi service registration data.


Constructor Summary
HttpServiceImpl(org.osgi.framework.Bundle bundle, Server server, Logger logger, java.util.Map servletMap)
           
 
Method Summary
 org.osgi.service.http.HttpContext createDefaultHttpContext()
           
 ServiceRegistrationHandler getProcessor(HttpServletRequestImpl request, HttpServletResponseImpl response, java.lang.String requestPath)
          For a request, response, and requestPath, return a ServiceRegistrationHandler.
 ServiceRegistration getServiceRegistration(java.lang.String requestPath)
          Iterate through all service registrations and return the registration which matches the longest alias, or null if no matches are found.
 HttpServletRequestImpl getServletRequest(java.net.Socket socket)
          Given a socket connection return a HttpServletRequestImpl.
 HttpServletResponseImpl getServletResponse(java.io.OutputStream output)
          Given a HttpRequest and an output stream, return a HttpServletResponseImpl.
 void registerResources(java.lang.String alias, java.lang.String name, org.osgi.service.http.HttpContext context)
           
 void registerServlet(java.lang.String alias, javax.servlet.Servlet servlet, java.util.Dictionary initparams, org.osgi.service.http.HttpContext context)
           
protected  void start()
          Start the HTTP server.
protected  void stop()
          Stop the HTTP server
 void unregister(java.lang.String alias)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServiceImpl

public HttpServiceImpl(org.osgi.framework.Bundle bundle,
                       Server server,
                       Logger logger,
                       java.util.Map servletMap)
                throws java.io.IOException
Parameters:
server - Map of of configuration properties for the HTTP server.
bundle - Bundle that registered with the service
logger - instance of Logger
servletMap - Map of servlet instances.
Throws:
java.io.IOException
Method Detail

registerResources

public void registerResources(java.lang.String alias,
                              java.lang.String name,
                              org.osgi.service.http.HttpContext context)
                       throws org.osgi.service.http.NamespaceException
Specified by:
registerResources in interface org.osgi.service.http.HttpService
Throws:
org.osgi.service.http.NamespaceException

unregister

public void unregister(java.lang.String alias)
Specified by:
unregister in interface org.osgi.service.http.HttpService

createDefaultHttpContext

public org.osgi.service.http.HttpContext createDefaultHttpContext()
Specified by:
createDefaultHttpContext in interface org.osgi.service.http.HttpService

registerServlet

public void registerServlet(java.lang.String alias,
                            javax.servlet.Servlet servlet,
                            java.util.Dictionary initparams,
                            org.osgi.service.http.HttpContext context)
                     throws javax.servlet.ServletException,
                            org.osgi.service.http.NamespaceException
Specified by:
registerServlet in interface org.osgi.service.http.HttpService
Throws:
javax.servlet.ServletException
org.osgi.service.http.NamespaceException

start

protected final void start()
                    throws java.io.IOException
Start the HTTP server.

Throws:
java.io.IOException - on I/O error

stop

protected final void stop()
                   throws java.lang.InterruptedException
Stop the HTTP server

Throws:
java.lang.InterruptedException - on thread interruption.

getServiceRegistration

public final ServiceRegistration getServiceRegistration(java.lang.String requestPath)
Iterate through all service registrations and return the registration which matches the longest alias, or null if no matches are found. TODO: consider caching if a lot of time is spent resolving registrations.

Specified by:
getServiceRegistration in interface ServiceRegistrationResolver
Parameters:
requestPath - the URI of the request
Returns:
the service registration with the deepest match to the request path.

getProcessor

public ServiceRegistrationHandler getProcessor(HttpServletRequestImpl request,
                                               HttpServletResponseImpl response,
                                               java.lang.String requestPath)
Description copied from interface: ServiceRegistrationResolver
For a request, response, and requestPath, return a ServiceRegistrationHandler.

Specified by:
getProcessor in interface ServiceRegistrationResolver
Parameters:
request - HttpRequest
response - HttpResponse
requestPath - The request URI
Returns:
A ServiceRegistrationHandler corresponding to the requestPath, or null if no match.

getServletRequest

public HttpServletRequestImpl getServletRequest(java.net.Socket socket)
Description copied from interface: ServiceRegistrationResolver
Given a socket connection return a HttpServletRequestImpl.

Specified by:
getServletRequest in interface ServiceRegistrationResolver
Parameters:
socket - socket connection to be associated with HTTP Request
Returns:
HttpServletRequestImpl instance

getServletResponse

public HttpServletResponseImpl getServletResponse(java.io.OutputStream output)
Description copied from interface: ServiceRegistrationResolver
Given a HttpRequest and an output stream, return a HttpServletResponseImpl.

Specified by:
getServletResponse in interface ServiceRegistrationResolver
Parameters:
output - output stream associated with socket connection.
Returns:
A HttpServletResponseImpl instance


Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved.