org.clazzes.util.http.osgi
Class BasicHttpContext
java.lang.Object
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:
getMimeType
Returns a MIME type based on the file extension of
the given path, if an extensionMimeTypes map has been supplied. Otherwise
null
is returned.
handleSecurity
Always return true
.
getResource
Assumes the named resource is in the
context bundle; this method calls the context bundle's
Bundle.getResource
method using the supplied resource prefix,
and returns the appropriate URL to
access the resource. On a Java runtime environment that supports
permissions, the Http Service needs to be granted
org.osgi.framework.AdminPermission[*,RESOURCE]
.
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 ClassNotFoundException
s.
Fields inherited from interface org.osgi.service.http.HttpContext |
AUTHENTICATION_TYPE, AUTHORIZATION, REMOTE_USER |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BasicHttpContext
public BasicHttpContext()
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.