Servlet
JVM since0.2.0 Native since0.0.2
Serve HTTP requests by a Servlet.
What’s inside
-
Servlet component, URI syntax:
servlet:contextPath
Please refer to the above link for usage and configuration details.
Maven coordinates
Or add the coordinates to your existing project:
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-servlet</artifactId>
</dependency>
Check the User guide for more information about writing Camel Quarkus applications.
Usage
Configuring CamelHttpTransportServlet
Minimal configuration
The simplest way to configure CamelHttpTransportServlet
is with configuration properties. The most minimal setup requires that you define one or more URL patterns for the Servlet with quarkus.camel.servlet.url-patterns
.
For example with configuration like the following.
quarkus.camel.servlet.url-patterns = /*
And a Camel route.
from("servlet://greet")
.setBody().constant("Hello World");
Produces the message Hello World
.
Advanced configuration
Servlet name
To give a specific name to the Servlet you can use the quarkus.camel.servlet.servlet-name
configuration option.
quarkus.camel.servlet.servlet-name = My Custom Name
Servlet class
You may use a custom Servlet class (E.g one that extends CamelHttpTransportServlet
) in your Camel routes.
quarkus.camel.servlet.servlet-class = org.acme.MyCustomServlet
Multiple named Servlets
For more advanced use cases you can configure multiple 'named' Servlets.
quarkus.camel.servlet.my-servlet-a.servlet-name = my-custom-a
quarkus.camel.servlet.my-servlet-a.url-patterns = /custom/a/*
quarkus.camel.servlet.my-servlet-b.servlet-name = my-custom-b
quarkus.camel.servlet.my-servlet-b.servlet-class = org.acme.CustomServletB
quarkus.camel.servlet.my-servlet-b.url-patterns = /custom/b/*
from("servlet://greet?servletName=my-custom-a")
.setBody().constant("Hello World");
from("servlet://goodbye?servletName=my-custom-b")
.setBody().constant("Goodbye World");
Finer control of Servlet configuration
If you need more control of the Servlet configuration, for example to configure custom init parameters, then you can do this with a custom Servlet class through the jakarta.servlet.annotation.WebServlet
annotation options.
import jakarta.servlet.annotation.WebServlet;
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
@WebServlet(
urlPatterns = {"/*"},
initParams = {
@WebInitParam(name = "myParam", value = "myValue")
}
)
public class MyCustomServlet extends CamelHttpTransportServlet {
}
Or you can configure the CamelHttpTransportServlet
using a web-app
descriptor placed into src/main/resources/META-INF/web.xml
.
<web-app>
<servlet>
<servlet-name>CamelServlet</servlet-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CamelServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
transferException option in native mode
To use the transferException
option in native mode, you must enable support for object serialization. Refer to the native mode user guide for more information.
You will also need to enable serialization for the exception classes that you intend to serialize. For example.
@RegisterForReflection(targets = { IllegalStateException.class, MyCustomException.class }, serialization = true)
Additional Camel Quarkus configuration
Configuration property | Type | Default |
---|---|---|
A comma separated list of path patterns under which the CamelServlet should be accessible. Example path patterns: |
| |
A fully qualified name of a servlet class to serve paths that match |
|
|
A servletName as it would be defined in a |
|
|
Sets the loadOnStartup priority on the Servlet. A loadOnStartup is a value greater than or equal to zero, indicates to the container the initialization priority of the Servlet. If loadOnStartup is a negative integer, the Servlet is initialized lazily. |
|
|
Enables Camel to benefit from asynchronous Servlet support. |
|
|
When set to |
|
|
The name of a bean to configure an optional custom thread pool for handling Camel Servlet processing. |
| |
An absolute path to a directory on the file system to store files temporarily while the parts are processed or when the size of the file exceeds the specified file-size-threshold configuration value. |
|
|
The maximum size allowed in bytes for uploaded files. The default size (-1) allows an unlimited size. |
|
|
The maximum size allowed in bytes for a multipart/form-data request. The default size (-1) allows an unlimited size. |
|
|
The file size in bytes after which the file will be temporarily stored on disk. |
|
|
A comma separated list of path patterns under which the CamelServlet should be accessible. Example path patterns: |
| |
A fully qualified name of a servlet class to serve paths that match |
|
|
A servletName as it would be defined in a |
|
|
Sets the loadOnStartup priority on the Servlet. A loadOnStartup is a value greater than or equal to zero, indicates to the container the initialization priority of the Servlet. If loadOnStartup is a negative integer, the Servlet is initialized lazily. |
|
|
Enables Camel to benefit from asynchronous Servlet support. |
|
|
When set to |
|
|
The name of a bean to configure an optional custom thread pool for handling Camel Servlet processing. |
| |
An absolute path to a directory on the file system to store files temporarily while the parts are processed or when the size of the file exceeds the specified file-size-threshold configuration value. |
|
|
The maximum size allowed in bytes for uploaded files. The default size (-1) allows an unlimited size. |
|
|
The maximum size allowed in bytes for a multipart/form-data request. The default size (-1) allows an unlimited size. |
|
|
The file size in bytes after which the file will be temporarily stored on disk. |
|
|
Configuration property fixed at build time. All other configuration properties are overridable at runtime.