public class DefaultHttpContext extends Object implements org.ops4j.pax.web.service.WebContainerContext
Default implementation of HttpContext that uses the bundle to lookup
resources (as specified in 102.10.2 "public interface HttpContext").
Note that OSGi CMPN "128.3.5 Static Content" chapter is the only place where "protected directories" are
mentioned, so only the implementation of HttpContext specific to pax-web-extender-war may contain
such protection. Besides Undertow's default servlet, Tomcat's StandardContextValve and Jetty's ContextHandler
provide such protection so we'll leverage those.
Actually we should not restrict access to the protected directories, because they usually contain important configuration files for e.g., JSF.
| Modifier and Type | Field and Description |
|---|---|
protected org.osgi.framework.Bundle |
bundle
Bundle using the
HttpService. |
protected String |
contextId
Name of the context - together with
Bundle it's part of context's identity |
| Modifier | Constructor and Description |
|---|---|
|
DefaultHttpContext(org.osgi.framework.Bundle bundle)
Constructor for bundle-scoped context
|
|
DefaultHttpContext(org.osgi.framework.Bundle bundle,
String contextId)
Constructor for bundle-scoped context with user-provided name
|
protected |
DefaultHttpContext(String contextId)
Constructor for bundle-agnostic contexts.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
void |
finishSecurity(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
org.osgi.framework.Bundle |
getBundle() |
String |
getContextId() |
String |
getMimeType(String name)
Allways returns null as there is no default way to find out the mime type.
|
protected URL |
getResource(org.osgi.framework.Bundle bundle,
String name)
This method supports
ServletContext.getResource(String) and in default implementation of
HttpContext interface, according to "102.10.2 public interface HttpContext", "The behavior of the
methods on the default HttpContext is defined as follows:[...] This method calls the
servlet bundle's Bundle.getResource method, and returns the appropriate URL to access the resource" |
URL |
getResource(String name) |
protected Set<String> |
getResourcePaths(org.osgi.framework.Bundle bundle,
String name)
This method is invoked by default when calling
ServletContext.getResourcePaths(String) in OSGi
context backed by HttpContext. |
Set<String> |
getResourcePaths(String name) |
boolean |
handleSecurity(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
There is no security by default, so always return "true".
|
int |
hashCode() |
boolean |
isShared() |
String |
toString() |
protected final org.osgi.framework.Bundle bundle
HttpService.protected final String contextId
Bundle it's part of context's identitypublic DefaultHttpContext(org.osgi.framework.Bundle bundle)
bundle - public DefaultHttpContext(org.osgi.framework.Bundle bundle,
String contextId)
bundle - contextId - protected DefaultHttpContext(String contextId)
contextId - public boolean isShared()
isShared in interface org.ops4j.pax.web.service.WebContainerContextpublic org.osgi.framework.Bundle getBundle()
getBundle in interface org.ops4j.pax.web.service.WebContainerContextpublic boolean handleSecurity(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws IOException
handleSecurity in interface org.osgi.service.http.HttpContextIOExceptionpublic void finishSecurity(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
finishSecurity in interface org.ops4j.pax.web.service.WebContainerContextpublic URL getResource(String name)
getResource in interface org.osgi.service.http.HttpContextpublic String getMimeType(String name)
getMimeType in interface org.osgi.service.http.HttpContextpublic Set<String> getResourcePaths(String name)
getResourcePaths in interface org.ops4j.pax.web.service.WebContainerContextpublic String getContextId()
getContextId in interface org.ops4j.pax.web.service.WebContainerContextprotected URL getResource(org.osgi.framework.Bundle bundle, String name)
ServletContext.getResource(String) and in default implementation of
HttpContext interface, according to "102.10.2 public interface HttpContext", "The behavior of the
methods on the default HttpContext is defined as follows:[...] This method calls the
servlet bundle's Bundle.getResource method, and returns the appropriate URL to access the resource"bundle - name - protected Set<String> getResourcePaths(org.osgi.framework.Bundle bundle, String name)
This method is invoked by default when calling ServletContext.getResourcePaths(String) in OSGi
context backed by HttpContext.
Just as the Servlet API method, here we list only one level of entries (no recursive searching).
Chapter 140.2.4 "Set
Default Behavior - Assumes the resources are in the bundle registering the Whiteboard service.
Its Bundle.findEntries method is called to obtain the listing.
Chapter 128.6.3 "Resource Lookup" says:
The getResourcePaths method must map to the Bundle getEntryPaths method, its return type is a Set and can
not handle multiples. However, the paths from the getEntryPaths method are relative while the methods of
the getResourcePaths must be absolute.
That's a bit contradictive... Bundle.findEntries(java.lang.String, java.lang.String, boolean) returns URLs (and checks fragments and lets us choose
recurse flag), while Bundle.getEntryPaths(java.lang.String) returns names (and doesn't check fragments).... In Felix:
findEntries: new EntryFilterEnumeration(revision, always-fragments, path, filePattern, recurse, url-values) and
(resolves a bundle if not resolved)getEntryPaths: new EntryFilterEnumeration(revision, no-fragments, path, "*", no-recurse, no-url-values)
The contradiction is resolved like this: DefaultHttpContext will implement this method based on
the Whiteboard behavior because Http Service specification doesn't mention this method at all and
Web Applications specification doesn't introduce any special support interface to be used under
ServletContext.
bundle - name - Copyright © 2006–2024 OPS4J - Open Participation Software for Java. All rights reserved.