org.clazzes.util.http.osgi
Class HttpServiceRegistrationListener

java.lang.Object
  extended by org.clazzes.util.http.osgi.HttpServiceRegistrationListener

public class HttpServiceRegistrationListener
extends Object

This class acts as a registration listener for the OSGi HttpServer and is used to export resources and servlets on the supplied http service.

It is recommended to use this class in a blueprint container like in the following example:

  <bean id="listener" class="org.clazzes.util.http.osgi.HttpServiceRegistrationListener">
    <property name="httpContext" ref="httpContext"/>
    <property name="servlets">
       <map>
         <entry key="/foobar/servlet1" value-ref="servlet1"/>
         <entry key="/foobar/servlet2" value-ref="servlet3"/>
       </map>
    </property>
    <property name="resources">
      <map>
        <entry key="/foobar" value="/foobar-resources"/>
      </map>   
    </property>
  </bean>
 

This example make use of the previously defined BasicHttpContext bean, which you will find in the documentation of this class. If you like to export resources in compressed form, please register a ResourceServlet instance in the list of servlets instead of a resource.

Please do not forget to manually import the org.clazzes.util.http.osgi package in blueprint bundles, otherwise you will run into ClassNotFoundExceptions.


Constructor Summary
HttpServiceRegistrationListener()
           
 
Method Summary
 org.osgi.service.http.HttpContext getHttpContext()
           
 Dictionary<String,String> getInitparams()
           
 Map<String,String> getResources()
           
 Map<String,javax.servlet.Servlet> getServlets()
           
 void httpServiceBound(org.osgi.service.http.HttpService httpService)
          The registration callback, which is called when the HttpService becomes available.
 void httpServiceUnbound(org.osgi.service.http.HttpService httpService)
          The deregistration callback, which is called when the HttpService gets out of service.
 void setHttpContext(org.osgi.service.http.HttpContext httpContext)
           
 void setInitparams(Dictionary<String,String> initparams)
           
 void setResources(Map<String,String> resources)
           
 void setServlets(Map<String,javax.servlet.Servlet> servlets)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServiceRegistrationListener

public HttpServiceRegistrationListener()
Method Detail

httpServiceBound

public void httpServiceBound(org.osgi.service.http.HttpService httpService)
                      throws javax.servlet.ServletException,
                             org.osgi.service.http.NamespaceException
The registration callback, which is called when the HttpService becomes available.

Parameters:
httpService - The HttpService where to register the supplied servlets and resources.
Throws:
javax.servlet.ServletException - As thrown by HttpService.registerServlet(String, Servlet, Dictionary, HttpContext).
org.osgi.service.http.NamespaceException - As thrown by HttpService.registerServlet(String, Servlet, Dictionary, HttpContext) or HttpService.registerResources(String, String, HttpContext).

httpServiceUnbound

public void httpServiceUnbound(org.osgi.service.http.HttpService httpService)
The deregistration callback, which is called when the HttpService gets out of service.

Parameters:
httpService - The httpService, which is going to be unavailable.

getServlets

public Map<String,javax.servlet.Servlet> getServlets()
Returns:
the map of servlets to register with their aliases as keys.

setServlets

public void setServlets(Map<String,javax.servlet.Servlet> servlets)
Parameters:
servlets - the map of servlets to register with their aliases as keys to set.

getResources

public Map<String,String> getResources()
Returns:
the map of resource paths to register with their aliases as keys.

setResources

public void setResources(Map<String,String> resources)
Parameters:
resources - the map of resource paths to register with their aliases as keys to set. If you need to deliver resources in compressed form, consider registering a ResourceServlet as an ordinary servlet.

getInitparams

public Dictionary<String,String> getInitparams()
Returns:
the initialization parameters passed to HttpService.registerServlet(String, Servlet, Dictionary, HttpContext) when registering servlets.

setInitparams

public void setInitparams(Dictionary<String,String> initparams)
Parameters:
initparams - the optional initialization parameters passed to HttpService.registerServlet(String, Servlet, Dictionary, HttpContext) when registering servlets to set.

getHttpContext

public org.osgi.service.http.HttpContext getHttpContext()
Returns:
The HttpContext used to register servlets and resources.

setHttpContext

public void setHttpContext(org.osgi.service.http.HttpContext httpContext)
Parameters:
httpContext - The HttpContext used to register servlets and resources to set. If you need control over MIME types consider using a BasicHttpContext.


Copyright © 2011. All Rights Reserved.