Netty4 HTTP Component

Available as of Camel 2.14

This camel component supports both producer and consumer endpoints.


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 will need to add the following dependency to their pom.xml for this component:

URI format

The URI scheme for a netty component is as follows

You can append query options to the URI in the following format, ?option=value&option=value&...

Query parameters vs endpoint options

You may be wondering how Camel recognizes URI query parameters and endpoint options. For example you might create endpoint URI as follows - netty4-http:http// . In this example myParam is the HTTP parameter, while compression is the Camel endpoint option. The strategy used by Camel in such situations is to resolve available endpoint options and remove them from the URI. It means that for the discussed example, the HTTP request sent by Netty HTTP producer to the endpoint will look as follows - http// , because compression endpoint option will be resolved and removed from the target URL.

Keep also in mind that you cannot specify endpoint options using dynamic headers (like CamelHttpQuery). Endpoint options can be specified only at the endpoint URI definition level (like to or from DSL elements).

HTTP Options

A lot more options


Default Value




Value in bytes the max content length per chunked frame received on the Netty HTTP server.



Allow using gzip/deflate for compression on the Netty HTTP server if the client supports it from the HTTP headers.



To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter headers.



To disable HTTP methods on the Netty HTTP consumer. You can specify multiple separated by comma.



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.netty4.http.NettyHttpMessage message with the method getHttpRequest() that returns the Netty HTTP request io.netty.handler.codec.http.HttpRequest instance.



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.



To use a custom org.apache.camel.component.netty4.http.NettyHttpBinding for binding to/from Netty and Camel Message API.



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.



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.



Specifies whether to enable HTTP TRACE for this Netty HTTP consumer. By default TRACE is turned off.



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.



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.netty4.http.NettyHttpBinding and therefore if you implement a custom org.apache.camel.component.netty4.http.NettyHttpBinding then you would need to decode the headers accordingly to this option. Notice: This option is default false.



To use a shared Netty4 HTTP server. See Netty HTTP Server Example for more details.



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.



Consumer only. Refers to a org.apache.camel.component.netty4.http.NettyHttpSecurityConfiguration for configuring secure web resources.



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 anymore.

maxHeaderSize8192Camel 2.15.3: Consumer only. The maximum length of all headers. If the sum of the length of each header exceeds this value, a io.netty.handler.codec.TooLongFrameException will be raised.
okStatusCodeRange200-299Camel 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.
useRelativePathfalseCamel 2.16: Producer only: Whether to use a path (/myapp) in the request line or an absolute URI (, which is default.

The NettyHttpSecurityConfiguration has the following options:


Default Value




Whether authentication is enabled. Can be used to quickly turn this off.



The constraint supported. Currently only Basic is implemented and supported.



The name of the JAAS security realm. This option is mandatory.



Allows to plugin a security constraint mapper where you can define ACL to web resources.



Allows to plugin a authenticator that performs the authentication. If none has been configured then the org.apache.camel.component.netty4.http.JAASSecurityAuthenticator is used by default.



Logging level used when a login attempt failed, which allows to see more details why the login failed.



To specify FQN class names of Principal implementations that contains user roles. If none has been specified, then the Netty4 HTTP component will by default assume a Principal is role based if its FQN classname has the lower-case word role in its classname. You can specify multiple class names separated by comma.

Message Headers

The following headers can be used on the producer to control the HTTP request.






Allow to control what HTTP method to use such as GET, POST, TRACE etc. The type can also be a io.netty.handler.codec.http.HttpMethod instance.



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.



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.



To set the content-type of the HTTP body. For example: text/plain; charset="UTF-8".

CamelHttpResponseCodeintAllows 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 Netty4 HTTP endpoint:

The description in the table takes offset in a route having: from("netty4-http:http:")...






The HTTP method used, such as GET, POST, TRACE etc.



The URL including protocol, host and port, etc:



The URI without protocol, host and port, etc:



Any query parameters, such as foo=bar&beer=yes



Any query parameters, such as foo=bar&beer=yes. Stored in the raw form, as they arrived to the consumer (i.e. before URL decoding).



Additional context-path. This value is empty if the client called the context-path /myapp. If the client calls /myapp/mystuff, then this header value is /mystuff. In other words its the value after the context-path configured on the route endpoint.



The charset from the content-type header.



If the user was authenticated using HTTP Basic then this header is added with the value Basic.



The content type if provided. For example: text/plain; charset="UTF-8".

Access to Netty types

This component uses the org.apache.camel.component.netty4.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.


In the route below we use Netty4 HTTP as a HTTP server, which returns back a hardcoded "Bye World" message.

And we can call this HTTP server using Camel also, with the ProducerTemplate as shown below:

And we get back "Bye World" as the output.

How do I let Netty match wildcards

In the route above Netty4 HTTP will only match if the uri is an exact match, so it will match if you enter but not match if you do

So if you want to enable wildcard matching you do as follows:

So now Netty matches any endpoints with starts with foo.

To match any endpoint you can do:

Using multiple routes with same port

The options the routes must be identical configured is all the options defined in the org.apache.camel.component.netty4.NettyServerBootstrapConfiguration configuration class. If you have configured another route with different options, Camel will throw an exception on startup, indicating the options is not identical. To mitigate this ensure all options is identical.

Here is an example with two routes that share the same port.

Two routes sharing the same port

And here is an example of a mis configured 2nd route that do not have identical org.apache.camel.component.netty4.NettyServerBootstrapConfiguration option as the 1st route. This will cause Camel to fail on startup.

Two routes sharing the same port, but the 2nd route is misconfigured and will fail on starting

Reusing same server bootstrap configuration with multiple routes

By configuring the common server bootstrap option in an single instance of a org.apache.camel.component.netty4.NettyServerBootstrapConfiguration type, we can use the bootstrapConfiguration option on the Netty4 HTTP consumers to refer and reuse the same options across all consumers.

And in the routes you refer to this option as shown below

Reusing same server bootstrap configuration with multiple routes across multiple bundles in OSGi container

See the Netty HTTP Server Example for more details and example how to do that.

Using HTTP Basic Authentication

The realm name is mandatory to enable basic authentication. By default the JAAS based authenticator is used, which will use the realm name specified (karaf in the example above) and use the JAAS realm and the JAAS {{LoginModule}}s of this realm for authentication.

End user of Apache Karaf / ServiceMix has a karaf realm out of the box, and hence why the example above would work out of the box in these containers.

Specifying ACL on web resources

The org.apache.camel.component.netty4.http.SecurityConstraint allows to define constrains on web resources. And the org.apache.camel.component.netty.http.SecurityConstraintMapping is provided out of the box, allowing to easily define inclusions and exclusions with roles.

For example as shown below in the XML DSL, we define the constraint bean:

The constraint above is define so that

  • access to /* is restricted and any roles is accepted (also if user has no roles)
  • access to /admin/* requires the admin role
  • access to /guest/* requires the admin or guest role
  • access to /public/* is an exclusion which means no authentication is needed, and is therefore public for everyone without logging in

To use this constraint we just need to refer to the bean id as shown below:

See Also

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram