org.ow2.jonas.camel.component
Class CamelServlet
java.lang.Object
org.ow2.jonas.camel.component.CamelServlet
- All Implemented Interfaces:
- javax.servlet.Servlet
public class CamelServlet
- extends java.lang.Object
- implements javax.servlet.Servlet
Generic CAMEL servlet, that can be for example used for REST endpoints. It
will map all request parameters to the Camel exchange's in message headers.
Note that all servlet headers use ServletRequest.getParameterMap(),
therefore the keys in the parameter map are of type String and the values in
the parameter map are of type String array.
In order to use it:
- Decide of a servlet path (for example,
/myServlet) and an
endpoint name (for example, direct:myServlet).
- Register the servlet:
import org.osgi.service.http.HttpService;
...
HttpService httpService = getService(HttpService.class);
HttpContext httpContext = httpService.createDefaultHttpContext();
Dictionary initParams = new Hashtable();
initParams.put("matchOnUriPrefix", "false");
initParams.put("servlet-name", SERVLET_PATH);
httpService.registerServlet(SERVLET_PATH,
new CamelServlet(this.getContext(), ENDPOINT_NAME),
initParams, httpContext);
- Handle incoming messages, exactly as you would do with any other CAMEL
route:
this.from(ENDPOINT_NAME).process(new MyProcessor());
|
Constructor Summary |
CamelServlet(org.apache.camel.CamelContext camelContext,
java.lang.String camelDestination)
Creates a new CamelServlet instance. |
CamelServlet(org.apache.camel.CamelContext camelContext,
java.lang.String camelDestination,
java.lang.String defaultFileName)
Creates a new CamelServlet instance. |
|
Method Summary |
void |
destroy()
|
javax.servlet.ServletConfig |
getServletConfig()
|
java.lang.String |
getServletInfo()
|
void |
init(javax.servlet.ServletConfig servletConfig)
|
void |
service(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse rsp)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CamelServlet
public CamelServlet(org.apache.camel.CamelContext camelContext,
java.lang.String camelDestination,
java.lang.String defaultFileName)
- Creates a new CamelServlet instance.
- Parameters:
camelContext - CAMEL context to send messages to.camelDestination - Name of the CAMEL endpoint on the camelContextdefaultFileName - Default file name to use if the response has no
file name.
CamelServlet
public CamelServlet(org.apache.camel.CamelContext camelContext,
java.lang.String camelDestination)
- Creates a new CamelServlet instance.
- Parameters:
camelContext - CAMEL context to send messages to.camelDestination - Name of the CAMEL endpoint on the camelContext
init
public void init(javax.servlet.ServletConfig servletConfig)
throws javax.servlet.ServletException
- Specified by:
init in interface javax.servlet.Servlet
- Throws:
javax.servlet.ServletException
getServletConfig
public javax.servlet.ServletConfig getServletConfig()
- Specified by:
getServletConfig in interface javax.servlet.Servlet
service
public void service(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse rsp)
throws javax.servlet.ServletException,
java.io.IOException
- Specified by:
service in interface javax.servlet.Servlet
- Throws:
javax.servlet.ServletException
java.io.IOException
getServletInfo
public java.lang.String getServletInfo()
- Specified by:
getServletInfo in interface javax.servlet.Servlet
destroy
public void destroy()
- Specified by:
destroy in interface javax.servlet.Servlet
Copyright © 2010 OW2 Consortium. All Rights Reserved.
Apache Camel version 2.3.0, OW2 JOnAS version 5.2.0-M2-SR1