org.ow2.jonas.web.base.osgi.httpservice
Class DefaultHttpContextImpl

java.lang.Object
  extended by org.ow2.jonas.web.base.osgi.httpservice.DefaultHttpContextImpl
All Implemented Interfaces:
org.osgi.service.http.HttpContext

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

Default OSGI HttpContext returned by HttpServiceImpl#createDefaultHttpContext().

Author:
Guillaume Porcher

Field Summary
 
Fields inherited from interface org.osgi.service.http.HttpContext
AUTHENTICATION_TYPE, AUTHORIZATION, REMOTE_USER
 
Constructor Summary
DefaultHttpContextImpl(org.osgi.framework.Bundle bundle)
          Constructor.
 
Method Summary
 String getMimeType(String file)
          Maps a name to a MIME type.
 URL getResource(String name)
          Maps a resource name to a URL.
 boolean handleSecurity(HttpServletRequest request, HttpServletResponse response)
          Handles security for the specified request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultHttpContextImpl

public DefaultHttpContextImpl(org.osgi.framework.Bundle bundle)
Constructor.

Parameters:
bundle - the bundle that will be used to get resources.
Method Detail

getMimeType

public String getMimeType(String file)
Maps a name to a MIME type. Called by the Http Service to determine the MIME type for the name. For servlet registrations, the Http Service will call this method to support the ServletContext method getMimeType. For resource registrations, the Http Service will call this method to determine the MIME type for the Content-Type header in the response.

Specified by:
getMimeType in interface org.osgi.service.http.HttpContext
Parameters:
file - determine the MIME type for this name.
Returns:
null to indicate that the Http Service should determine the MIME type itself.

getResource

public URL getResource(String name)
Maps a resource name to a URL.

Called by the Http Service to map a resource name to a URL. For servlet registrations, Http Service will call this method to support the ServletContext methods getResource and getResourceAsStream. For resource registrations, Http Service will call this method to locate the named resource. The resource is mapped to a resource in the context's bundle via bundle.getResource(name)

Specified by:
getResource in interface org.osgi.service.http.HttpContext
Parameters:
name - the name of the requested resource
Returns:
URL that Http Service can use to read the resource or null if the resource does not exist.

handleSecurity

public boolean handleSecurity(HttpServletRequest request,
                              HttpServletResponse response)
                       throws IOException
Handles security for the specified request.

The Http Service calls this method prior to servicing the specified request. This method controls whether the request is processed in the normal manner or an error is returned.

Specified by:
handleSecurity in interface org.osgi.service.http.HttpContext
Parameters:
request - the HTTP request
response - the HTTP response
Returns:
true if the request should be serviced, false if the request should not be serviced and Http Service will send the response back to the client. This implementation always returns true.
Throws:
IOException - may be thrown by this method. If this occurs, the Http Service will terminate the request and close the socket.


Copyright © 2013 OW2 Consortium. All Rights Reserved.