...
This camel component supports both producer and consumer endpoints.
Warning |
---|
Info |
---|
title | Upgrade to Netty 4.0 planned |
---|
|
This component is intended to be upgraded to use Netty 4.0 when camel-netty4 component has finished being upgraded. At the time being this component is still based on Netty 3.x. The upgrade is intended to be as backwards compatible as possible.deprecated. You should use Netty4 HTTP. |
Info |
---|
|
Netty is stream based, which means the input it receives is submitted to Camel as a stream. That means you will only be able to read the content of the stream once. If you find a situation where the message body appears to be empty or you need to access the data multiple times (eg: doing multicasting, or redelivery error handling) you should use Stream caching or convert the message body to a String which is safe to be re-read multiple times. Notice Netty4 HTTP reads the entire stream into memory using io.netty.handler.codec.http.HttpObjectAggregator to build the entire full http message. But the resulting message is still a stream based message which is readable once. |
Maven users Maven users will need to add the following dependency to their pom.xml
for this component:
...
Div |
---|
class | confluenceTableSmall |
---|
|
Name | Default Value | Description |
---|
chunkedMaxContentLength
| 1mb
| Value in bytes the max content length per chunked frame received on the Netty HTTP server. | compression
| false
| Allow using gzip/deflate for compression on the Netty HTTP server if the client supports it from the HTTP headers. | headerFilterStrategy
| | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter headers. | httpMethodRestrict
| | To disable HTTP methods on the Netty HTTP consumer. You can specify multiple separated by comma. | mapHeaders
| true
| If this option is enabled, then during binding from Netty to Camel Message then the headers will be mapped as well (eg added as header to the Camel Message as well). You can turn off this option to disable this. The headers can still be accessed from the org.apache.camel.component.netty.http.NettyHttpMessage message with the method getHttpRequest() that returns the Netty HTTP request org.jboss.netty.handler.codec.http.HttpRequest instance. | matchOnUriPrefix
| false
| Whether or not Camel should try to find a target consumer by matching the URI prefix if no exact match is found. See further below for more details. | nettyHttpBinding
| | To use a custom org.apache.camel.component.netty.http.NettyHttpBinding for binding to/from Netty and Camel Message API. | bridgeEndpoint
| false
| If the option is true , the producer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the throwExceptionOnFailure to be false to let the producer send all the fault response back. The consumer working in the bridge mode will skip the gzip compression and WWW URL form encoding (by adding the Exchange.SKIP_GZIP_ENCODING and Exchange.SKIP_WWW_FORM_URLENCODED headers to the consumed exchange). | throwExceptionOnFailure
| true
| Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code. | traceEnabled
| false
| Specifies whether to enable HTTP TRACE for this Netty HTTP consumer. By default TRACE is turned off. | transferException
| false
| If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type. On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException . The caused exception is required to be serialized. | urlDecodeHeaders
| | If this option is enabled, then during binding from Netty to Camel Message then the header values will be URL decoded (eg %20 will be a space character. Notice this option is used by the default org.apache.camel.component.netty.http.NettyHttpBinding and therefore if you implement a custom org.apache.camel.component.netty.http.NettyHttpBinding then you would need to decode the headers accordingly to this option. Notice: This option is default true for Camel 2.12.x, and default false from Camel 2.13 onwards. | nettySharedHttpServer
| null
| To use a shared Netty HTTP server. See Netty HTTP Server Example for more details. | disableStreamCache
| false
| Determines whether or not the raw input stream from Netty HttpRequest#getContent() is cached or not (Camel will read the stream into a in light-weight memory based Stream caching) cache. By default Camel will cache the Netty input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store. Mind that if you enable this option, then you cannot read the Netty stream multiple times out of the box, and you would need manually to reset the reader index on the Netty raw stream. Notice Netty4 HTTP reads the entire stream into memory using io.netty.handler.codec.http.HttpObjectAggregator to build the entire full http message. But the resulting message is still a stream based message which is readable once. | securityConfiguration
| null
| Consumer only. Refers to a org. | securityConfiguration
| null
| Consumer only. Refers to a org.apache.camel.component.netty.http.NettyHttpSecurityConfiguration for configuring secure web resources. | send503whenSuspended
| true
| Consumer only. Whether to send back HTTP status code 503 when the consumer has been suspended. If the option is false then the Netty Acceptor is unbound when the consumer is suspended, so clients cannot connect anymorewhen the consumer is suspended, so clients cannot connect anymore. | maxHeaderSize | 8192 | Camel 2.15.3: Consumer only. The maximum length of all headers. If the sum of the length of each header exceeds this value, a TooLongFrameException will be raised. | okStatusCodeRange | 200-299 | Camel 2.16: The status codes which is considered a success response. The values are inclusive. The range must be defined as from-to with the dash included. | useRelativePath | false | Camel 2.16: Producer only: Whether to use a path (/myapp) in the request line or an absolute URI (http://0.0.0.0:8080/myapp), which is default. |
|
The NettyHttpSecurityConfiguration
has the following options:
...
Div |
---|
class | confluenceTableSmall |
---|
|
Name | Type | Description |
---|
CamelHttpMethod
| String
| Allow to control what HTTP method to use such as GET, POST, TRACE etc. The type can also be a org.jboss.netty.handler.codec.http.HttpMethod instance. | CamelHttpQuery
| String
| Allows to provide URI query parameters as a String value that overrides the endpoint configuration. Separate multiple parameters using the & sign. For example: foo=bar&beer=yes . | CamelHttpPath
| String
| Camel 2.13.1/2.12.4: Allows to provide URI context-path and query parameters as a String value that overrides the endpoint configuration. This allows to reuse the same producer for calling same remote http server, but using a dynamic context-path and query parameters. | Content-Type
| String
| To set the content-type of the HTTP body. For example: text/plain; charset="UTF-8" . | CamelHttpResponseCode | int | Allows to set the HTTP Status code to use. By default 200 is used for success, and 500 for failure. |
|
The following headers is provided as meta-data when a route starts from an Netty HTTP endpoint:
...
This component uses the org.apache.camel.component.netty.http.NettyHttpMessage
as the message implementation on the Exchange. This allows end users to get access to the original Netty request/response instances if needed, as shown below:. Mind that the original response may not be accessible at all times.
Code Block |
---|
org.jboss.netty.handler.codec.http.HttpRequest request = exchange.getIn(NettyHttpMessage.class).getHttpRequest();
|
...
Here is an example with two routes that share the same port.
Code Block |
---|
| java |
---|
| java |
---|
title | Two routes sharing the same portjava |
---|
|
from("netty-http:http://0.0.0.0:{{port}}/foo")
.to("mock:foo")
.transform().constant("Bye World");
from("netty-http:http://0.0.0.0:{{port}}/bar")
.to("mock:bar")
.transform().constant("Bye Camel");
|
And here is an example of a mis configured 2nd route that do not have identical org.apache.camel.component.netty.NettyServerBootstrapConfiguration
option as the 1st route. This will cause Camel to fail on startup.
Code Block |
---|
| java |
---|
| java |
---|
title | Two routes sharing the same port, but the 2nd route is misconfigured and will fail on startingjava |
---|
|
from("netty-http:http://0.0.0.0:{{port}}/foo")
.to("mock:foo")
.transform().constant("Bye World");
// we cannot have a 2nd route on same port with SSL enabled, when the 1st route is NOT
from("netty-http:http://0.0.0.0:{{port}}/bar?ssl=true")
.to("mock:bar")
.transform().constant("Bye Camel");
|
...