org.clazzes.util.http.osgi
Class BasicHttpContext

java.lang.Object
  extended by org.clazzes.util.http.osgi.BasicHttpContext
All Implemented Interfaces:
org.osgi.service.http.HttpContext

public class BasicHttpContext
extends Object
implements org.osgi.service.http.HttpContext

A HttpContext implementation with an extension to MIME type mapping and resources received from a specified bundle, which is usually injected using blueprint.

The behavior of the HttpContext methods is defined as follows:

It is recommended to set up this bean inside a blueprint container like in the following example:

  <bean id="httpContext" class="org.clazzes.util.http.osgi.BasicHttpContext">
    <property name="resourceBundle" ref="blueprintBundle"/>
    <property name="extensionMimeTypes">
      <map>
        <entry key="html" value="text/html"/>       
        <entry key="xml"  value="text/xml"/>       
        <entry key="js"   value="application/javascript"/>       
        <entry key="json" value="application/json"/>       
        <entry key="css"  value="text/css"/>       
        <entry key="png"  value="image/png"/>       
        <entry key="jpg"  value="image/jpeg"/>       
        <entry key="jpeg" value="image/jpeg"/>       
        <entry key="gif"  value="image/gif"/>       
        <entry key="tif"  value="image/tiff"/>       
      </map>
    </property>
  </bean>
 

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


Field Summary
 
Fields inherited from interface org.osgi.service.http.HttpContext
AUTHENTICATION_TYPE, AUTHORIZATION, REMOTE_USER
 
Constructor Summary
BasicHttpContext()
           
 
Method Summary
 Map<String,String> getExtensionMimeTypes()
           
 String getMimeType(String name)
           
 URL getResource(String name)
           
 org.osgi.framework.Bundle getResourceBundle()
           
 String getResourcePrefix()
           
 boolean handleSecurity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void setExtensionMimeTypes(Map<String,String> extensionMimeTypes)
           
 void setResourceBundle(org.osgi.framework.Bundle resourceBundle)
           
 void setResourcePrefix(String resourcePrefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicHttpContext

public BasicHttpContext()
Method Detail

handleSecurity

public boolean handleSecurity(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws IOException
Specified by:
handleSecurity in interface org.osgi.service.http.HttpContext
Throws:
IOException

getResource

public URL getResource(String name)
Specified by:
getResource in interface org.osgi.service.http.HttpContext

getMimeType

public String getMimeType(String name)
Specified by:
getMimeType in interface org.osgi.service.http.HttpContext

getResourceBundle

public org.osgi.framework.Bundle getResourceBundle()
Returns:
the bundle used to resolve resources.

setResourceBundle

public void setResourceBundle(org.osgi.framework.Bundle resourceBundle)
Parameters:
resourceBundle - the bundle used to resolve resources to set.

getExtensionMimeTypes

public Map<String,String> getExtensionMimeTypes()
Returns:
A map containing file extension as keys and MIME types as values.

setExtensionMimeTypes

public void setExtensionMimeTypes(Map<String,String> extensionMimeTypes)
Parameters:
extensionMimeTypes - A map containing file extension as keys and MIME types as values to set. The extensions are not case-sensitive, please supply supply the file extension in lower case.

getResourcePrefix

public String getResourcePrefix()
Returns:
the prefix to attach when searching resource paths in getResource(String).

setResourcePrefix

public void setResourcePrefix(String resourcePrefix)
Parameters:
resourcePrefix - the prefix to attach when searching resource paths in getResource(String) to set. If you set this property to WEB-INF/, all resources are searched inside the WEB-INF folder of your OSGi bundle, which is the recommended approach.


Copyright © 2012. All Rights Reserved.