...
As a result of the service.registerResources("/static", "/etc/www", null)
code, all the files available under /etc/www
will be exposed under /static
(f.i. http://localhost:8080/static/001.jpg will render the /etc/www/001.jpg). However, the example above can be simplistic in practice; the HttpContext object is the solution to customize the resource handling.
...
- Deploy
org.apache.felix.http.proxy
jar file inside the web applicaiton (WEB-INF/lib). - In a startup listener (like ServletContextListener) set the BundleContext as a servlet context attribute (see example).
- Define
org.apache.felix.http.proxy.ProxyServlet
inside yourweb.xml
and register it to serve on all requests/*
(see example). - Define
org.apache.felix.http.proxy.ProxyListener
as a<listener>
in yourweb.xml
to allow HTTP Session related events to be forwarded (see the section of Servlet API Event forwarding below and example). - Be sure to add
javax.servlet;javax.servlet.http;version=2.5
to OSGi system packages ((org.osgi.framework.system.packages
). - Deploy
org.apache.felix.http.bridge
(ororg.apache.felix.http.bundle
) inside the OSGi framework.
...
org.osgi.service.http.port
- The port used for servlets and resources available via HTTP. The default is80
. A negative port number has the same effect as settingorg.osgiapache.servicefelix.http.enable
tofalse
.org.osgi.service.http.port.secure
- The port used for servlets and resources available via HTTPS. The default is443
. A negative port number has the same effect as settingorg.apache.felix.https.enable
tofalse
.org.apache.felix.http.nio
- Flag to enable the use of NIO instead of traditional IO for HTTP. One consequence of using NIO with HTTPS HTTP is that the bundle needs at least a Java 5 runtime. The default istrue
.org.apache.felix.httphttps.enablenio
- Flag to enable the use of NIO instead of traditional IO for HTTPS. One consequence of using NIO with HTTPS is that the bundle needs at least a Java 5 runtime. If this property is not set the (default) value of theorg.apache.felix.http.nio
property is used.org.apache.felix.http.enable
- Flag to enable the use of HTTP. The default istrue
. HTTP. The default istrue
.org.apache.felix.https.enable
- Flag to enable the user of HTTPS. The default isfalse
.org.apache.felix.https.keystore
- The name of the file containing the keystore.org.apache.felix.https.keystore.password
- The password for the keystore.org.apache.felix.https.keystore.key.password
- The password for the key in the keystore.org.apache.felix.https.truststore
- The name of the file containing the truststore.org.apache.felix.https.truststore.password
- The password for the truststore.org.apache.felix.https.clientcertificate
- Flag to determine if the HTTPS protocol requires, wants or does not use client certificates. Legal values areneeds
,wants
andnone
. The default isnone
.org.apache.felix.http.debug
- Flag to enable debugging for this service implementation. The default isfalse
.
...
org.apache.felix.http.jettyEnabled
- True to enable jetty as the http container. The default isfalse
.false
.org.apache.felix.http.whiteboardEnabled
- True to enable the whiteboard implementation. The default isfalse
.
The Jetty based implementation supports the following Jetty specific configuration as of Http Service Jetty Bundle 2.4:
org.apache.felix.http.host
- Host name or IP Address of the interface to listen on. The default isnull
causing Jetty to listen on all interfaces.org.apache.felix.http.context_path
- The Servlet Context Path to use for the Http Service. If this property is not configured it defaults to "/". This must be a valid path starting with a slash and not ending with a slash (unless it is the root context).org.apache.felix.http.timeout
- Connection timeout in milliseconds. The default is 60000 (60 seconds).org.apache.felix.http.session.timeout
- Allows for the specification of the Session life time as a number of minutes. This property serves the same purpose as thesession-timeout
element in a Web Application descriptor. The default is zero for no timeout at all.org.mortbay.jetty.servlet.SessionCookie
- Name of the cookie used to transport the Session ID. The default isJSESSIONID
.org.mortbay.jetty.servlet.SessionURL
- Name of the request parameter to transport the Session ID. The default isjsessionid
.org.mortbay.jetty.servlet.SessionDomain
- Domain to set on the session cookie. The default isnull
.org.mortbay.jetty.servlet.SessionPath
- The path to set on the session cookie. The default is the configured session context path (/
).org.mortbay.jetty.servlet.MaxAge
- The maximum age value to set on the cookie. The default is-1
.org.apache.felix.http.jetty.headerBufferSize
- Size of the buffer for request and response headers. Default is 16KB.org.apache.felix.http.jetty.requestBufferSize
- Size of the buffer for requests not fitting the header buffer. Default is 8KB.org.apache.felix.http.jetty.responseBufferSize
- Size of the buffer for responses. Default is 24KB.
Servlet API Events
The Servlet API defines a number of EventListener
interfaces to catch Servlet API related events. As of HTTP Service 2.1.0 most events generated by the servlet container are forwarded to interested service. To be registered to receive events services must be registered with the respective EventListener
interface:
Interface | Description |
---|---|
| Events on servlet context attribute addition, change and removal. |
| Events on request attribute addition, change and removal. |
| Events on request start and end. |
| Events on session attribute addition, change and removal. To receive such events in a bridged environment, the |
| Events on session creation and destroyal. To receive such events in a bridged environment, the |
Of the defined EventListener
interfaces in the Servlet API, the javax.servlet.ServletContextListener
events are actually not support. For one thing they do not make much sense in an OSGi environment. On the other hand they are hard to capture and propagate. For example in a bridged environment the contextInitialized
event may be sent before the framework and any of the contained bundles are actually ready to act. Likewise the contextDestroyed
event may come to late.
Servlet Context Notes
ServletContext
instances are managed internally by the Http Service implementation. For each HttpContext
instance used to register one or more servlets and/or resources a corresponding ServletContext
instance is created. These ServletContext
instances is partly based on the single ServletContext
instance received from the Servlet Container — either embedded Jetty or some external Servlet Container when using the Http Service Bridge — and partly based on the provided HttpContext
instance:
Method(s) | Based on ... |
| Servlet Containers |
| |
| |
| |
| Always return |
| Always returns empty |
| By default maintained for each |
...
|
Examples
A set of simple examples illustrating the various features are available.
- Filter registration sample: http://svn.apache.org/repos/asf/felix/trunk/http/samples/filter/
- Servlet bridge sample: http://svn.apache.org/repos/asf/felix/trunk/http/samples/bridge/
- Whiteboard sample: http://svn.apache.org/repos/asf/felix/trunk/http/samples/whiteboard/
Maven Artifacts
...