Camel Components

Mina

Since Camel 2.10

Both producer and consumer are supported

The Mina component is a transport mechanism for working with Apache MINA 2.x

Favor using Netty as Netty is a much more active maintained and popular project than Apache Mina currently is.

With sync=false the endpoint is one-way: the consumer does not write a reply back to the client, and the producer does not wait for a reply and leaves the message of the exchange as it was. Use sync=true (the default) for request-reply.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-mina</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

mina:tcp://hostname[:port][?options]
mina:udp://hostname[:port][?options]
mina:vm://hostname[:port][?options]

You can specify a codec in the Registry using the codec option. If you are using TCP and no codec is specified then the textline flag is used to determine if text-line-based codec or object serialization should be used instead. By default, the object serialization is used.

For UDP if no codec is specified the default uses a basic ByteBuffer based codec.

The VM protocol is used as a direct forwarding mechanism in the same JVM.

A Mina producer has a default timeout value of 30 seconds, while it waits for a response from the remote server.

In normal use, camel-mina only supports marshalling the body content—message headers and exchange properties are not sent.
However, the option, transferExchange, does allow you to transfer the exchange itself over the wire. See options below.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Mina component supports the following options which are listed below.

Name Description Default Type

disconnect (common)

Whether to close the session after each message: the consumer closes it after it writes the reply, and the producer after the exchange is done. The CamelMinaCloseSessionWhenComplete header overrides it.

false

boolean

minaLogger (common)

Whether to add the Apache MINA LoggingFilter to the filter chain, which logs the session events and the messages sent and received with SLF4J at INFO level (exceptions at WARN level).

false

boolean

sync (common)

Whether the endpoint is request-reply (true) or one-way (false). With true the producer waits for the reply of the server and the consumer writes the result of the route back to the client; with false the producer does not wait and the consumer writes nothing back.

true

boolean

timeout (common)

The time in milliseconds the producer waits for a reply when sync is enabled. It is also the connect timeout of the producer and of a consumer in client mode.

30000

long

writeTimeout (common)

The maximum time in milliseconds to wait until a message is written to the session. The exchange fails if the write does not complete in time.

10000

long

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

clientMode (consumer)

Whether the consumer connects as a TCP client to the server at host and port, and receives the messages the server sends, instead of listening for connections. Only used by the tcp protocol.

false

boolean

muteException (consumer)

If enabled and an Exchange failed processing on the consumer side the response written back to the remote peer won’t contain the exception’s class, message or stack trace.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

cachedAddress (producer (advanced))

Whether the producer resolves the host name once and reuses the address. Set to false to resolve it again each time the producer opens a new connection, to pick up DNS changes.

true

boolean

lazySessionCreation (producer (advanced))

Whether the producer connects to the server on the first message instead of when it starts, so the producer can start while the server is not up yet.

true

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

configuration (advanced)

The shared configuration that the endpoints of this component start from. The options in the endpoint URI override it.

MinaConfiguration

disconnectOnNoReply (advanced)

Whether a synchronous consumer closes the session when the route ends with no body, so there is no reply to send back. Set to false to keep the session open. The producer always closes its session on a reply timeout.

true

boolean

maximumPoolSize (advanced)

The maximum number of threads of the worker pool that processes the I/O events of the sessions. Used by the tcp and udp protocols.

16

int

noReplyLogLevel (advanced)

The logging level to use when there is nothing to send: on the consumer (if sync is enabled) when there is no reply to send back, and on the producer when the message has no body.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

WARN

LoggingLevel

orderedThreadPoolExecutor (advanced)

Whether the worker pool processes the events of a session in order, one at a time (Apache MINA OrderedThreadPoolExecutor). When false, an UnorderedThreadPoolExecutor processes them concurrently and in any order.

true

boolean

transferExchange (advanced)

Deprecated Only used by the tcp and vm protocols. Transfers the exchange over the wire instead of just the body: the in and out body, the in and out headers, the exchange properties and variables, and the exception. The objects must be serializable; Camel leaves out the ones that are not and logs it at WARN level. The classes of the transferred objects must be allowed in objectCodecPattern.

false

boolean

allowDefaultCodec (codec)

Whether to install a default codec when codec is not set: the text line codec with textline=true, otherwise the object serialization codec. Set to false to install no codec, so the route receives and sends Apache MINA IoBuffer objects. Not used by the udp protocol, which installs its own byte array codec when codec is not set.

true

boolean

codec (codec)

A custom Apache MINA ProtocolCodecFactory to encode and decode the messages, used instead of the default codec of the protocol.

ProtocolCodecFactory

decoderMaxLineLength (codec)

The maximum length of a line that the text line decoder reads. If 0 or less, the default of Apache MINA is used, which is 1024.

1024

int

encoderMaxLineLength (codec)

The maximum length of a line that the text line encoder writes. If 0 or less, the default of Apache MINA is used, which is Integer.MAX_VALUE.

-1

int

encoding (codec)

The charset name used by the text line codec, and by the udp protocol to convert text to and from bytes. If not set, the default charset of the JVM is used.

String

filters (codec)

A list of Apache MINA IoFilter beans to add to the filter chain, given as bean references separated by comma.

List

objectCodecPattern (codec)

Accept the wildcard specified classes for Object deserialization, unless they are otherwise rejected. Multiple patterns can be separated by comma. This widens the codec’s deserialization allow-list, so keep it as narrow as the route actually needs. Avoid *: it accepts every class the classpath can load from an untrusted peer, including Camel’s own org.apache.camel types. Leaving the option unset is the safest choice - the codec then accepts only the small built-in set and refuses anything else.

String

textline (codec)

Whether to use the text line codec, which reads and writes one line of text per message, when codec is not set. When false, the object serialization codec is used. Only used by the tcp and vm protocols.

false

boolean

textlineDelimiter (codec)

The line delimiter of the text line codec: DEFAULT (the line separator of the platform), AUTO (reads a line that ends with LF or CRLF, writes LF), UNIX (LF), WINDOWS (CRLF) or MAC (CR). If not set, DEFAULT is used. Only used with textline=true.

Enum values:

  • DEFAULT

  • AUTO

  • UNIX

  • WINDOWS

  • MAC

MinaTextLineDelimiter

hostnameVerification (security)

Whether to check that the certificate of the server matches the host Camel connects to, when SSL is used by the producer, or by the consumer in client mode. When disabled, any certificate accepted by the trust store is accepted, whatever host it was issued for.

true

boolean

sslContextParameters (security)

The SSL/TLS configuration (key store, trust store, protocols and cipher suites). Only used by the tcp protocol.

SSLContextParameters

useGlobalSslContextParameters (security)

Whether to use the global SSL context parameters of the CamelContext when an endpoint does not set sslContextParameters.

false

boolean

Endpoint Options

The Mina endpoint is configured using URI syntax:

mina:protocol:host:port

With the following path and query parameters:

Path Parameters

Name Description Default Type

protocol (common)

Required The transport protocol: tcp, udp or vm (a pipe within the same JVM).

String

host (common)

Required The host name or IP address. A consumer listens on this address (use 0.0.0.0 for all network interfaces); a producer, or a consumer in client mode, connects to the server at this address. Not used by the vm protocol.

String

port (common)

Required The port number. With the vm protocol the port identifies the pipe within the JVM.

int

Query Parameters

Name Description Default Type

disconnect (common)

Whether to close the session after each message: the consumer closes it after it writes the reply, and the producer after the exchange is done. The CamelMinaCloseSessionWhenComplete header overrides it.

false

boolean

minaLogger (common)

Whether to add the Apache MINA LoggingFilter to the filter chain, which logs the session events and the messages sent and received with SLF4J at INFO level (exceptions at WARN level).

false

boolean

sync (common)

Whether the endpoint is request-reply (true) or one-way (false). With true the producer waits for the reply of the server and the consumer writes the result of the route back to the client; with false the producer does not wait and the consumer writes nothing back.

true

boolean

timeout (common)

The time in milliseconds the producer waits for a reply when sync is enabled. It is also the connect timeout of the producer and of a consumer in client mode.

30000

long

writeTimeout (common)

The maximum time in milliseconds to wait until a message is written to the session. The exchange fails if the write does not complete in time.

10000

long

clientMode (consumer)

Whether the consumer connects as a TCP client to the server at host and port, and receives the messages the server sends, instead of listening for connections. Only used by the tcp protocol.

false

boolean

muteException (consumer)

If enabled and an Exchange failed processing on the consumer side the response written back to the remote peer won’t contain the exception’s class, message or stack trace.

true

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

cachedAddress (producer (advanced))

Whether the producer resolves the host name once and reuses the address. Set to false to resolve it again each time the producer opens a new connection, to pick up DNS changes.

true

boolean

lazySessionCreation (producer (advanced))

Whether the producer connects to the server on the first message instead of when it starts, so the producer can start while the server is not up yet.

true

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

disconnectOnNoReply (advanced)

Whether a synchronous consumer closes the session when the route ends with no body, so there is no reply to send back. Set to false to keep the session open. The producer always closes its session on a reply timeout.

true

boolean

maximumPoolSize (advanced)

The maximum number of threads of the worker pool that processes the I/O events of the sessions. Used by the tcp and udp protocols.

16

int

noReplyLogLevel (advanced)

The logging level to use when there is nothing to send: on the consumer (if sync is enabled) when there is no reply to send back, and on the producer when the message has no body.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

WARN

LoggingLevel

orderedThreadPoolExecutor (advanced)

Whether the worker pool processes the events of a session in order, one at a time (Apache MINA OrderedThreadPoolExecutor). When false, an UnorderedThreadPoolExecutor processes them concurrently and in any order.

true

boolean

transferExchange (advanced)

Deprecated Only used by the tcp and vm protocols. Transfers the exchange over the wire instead of just the body: the in and out body, the in and out headers, the exchange properties and variables, and the exception. The objects must be serializable; Camel leaves out the ones that are not and logs it at WARN level. The classes of the transferred objects must be allowed in objectCodecPattern.

false

boolean

allowDefaultCodec (codec)

Whether to install a default codec when codec is not set: the text line codec with textline=true, otherwise the object serialization codec. Set to false to install no codec, so the route receives and sends Apache MINA IoBuffer objects. Not used by the udp protocol, which installs its own byte array codec when codec is not set.

true

boolean

codec (codec)

A custom Apache MINA ProtocolCodecFactory to encode and decode the messages, used instead of the default codec of the protocol.

ProtocolCodecFactory

decoderMaxLineLength (codec)

The maximum length of a line that the text line decoder reads. If 0 or less, the default of Apache MINA is used, which is 1024.

1024

int

encoderMaxLineLength (codec)

The maximum length of a line that the text line encoder writes. If 0 or less, the default of Apache MINA is used, which is Integer.MAX_VALUE.

-1

int

encoding (codec)

The charset name used by the text line codec, and by the udp protocol to convert text to and from bytes. If not set, the default charset of the JVM is used.

String

filters (codec)

A list of Apache MINA IoFilter beans to add to the filter chain, given as bean references separated by comma.

List

objectCodecPattern (codec)

Accept the wildcard specified classes for Object deserialization, unless they are otherwise rejected. Multiple patterns can be separated by comma. This widens the codec’s deserialization allow-list, so keep it as narrow as the route actually needs. Avoid *: it accepts every class the classpath can load from an untrusted peer, including Camel’s own org.apache.camel types. Leaving the option unset is the safest choice - the codec then accepts only the small built-in set and refuses anything else.

String

textline (codec)

Whether to use the text line codec, which reads and writes one line of text per message, when codec is not set. When false, the object serialization codec is used. Only used by the tcp and vm protocols.

false

boolean

textlineDelimiter (codec)

The line delimiter of the text line codec: DEFAULT (the line separator of the platform), AUTO (reads a line that ends with LF or CRLF, writes LF), UNIX (LF), WINDOWS (CRLF) or MAC (CR). If not set, DEFAULT is used. Only used with textline=true.

Enum values:

  • DEFAULT

  • AUTO

  • UNIX

  • WINDOWS

  • MAC

MinaTextLineDelimiter

hostnameVerification (security)

Whether to check that the certificate of the server matches the host Camel connects to, when SSL is used by the producer, or by the consumer in client mode. When disabled, any certificate accepted by the trust store is accepted, whatever host it was issued for.

true

boolean

sslContextParameters (security)

The SSL/TLS configuration (key store, trust store, protocols and cipher suites). Only used by the tcp protocol.

SSLContextParameters

Message Headers

The Mina component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelMinaCloseSessionWhenComplete (common)

Constant: MINA_CLOSE_SESSION_WHEN_COMPLETE

Whether to close the session when the exchange is complete, overriding the disconnect option. A consumer closes it after it writes the reply, a producer after the exchange is done.

Boolean

CamelMinaIoSession (consumer)

Constant: MINA_IOSESSION

The Apache MINA IoSession that received the message.

IoSession

CamelMinaLocalAddress (consumer)

Constant: MINA_LOCAL_ADDRESS

The local socket address of the session that received the message.

SocketAddress

CamelMinaRemoteAddress (consumer)

Constant: MINA_REMOTE_ADDRESS

The socket address of the remote peer that sent the message.

SocketAddress

Message Body

The message body at each side of the Mina component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

text (java.lang.String)

The data received as a String: one line with textline=true. The default object codec over TCP accepts only a String unless objectCodecPattern lists the classes to deserialize. Over UDP the datagram as a byte array.

  • With protocol=udp: bytes (byte[])

  • With allowDefaultCodec=false: pojo (org.apache.mina.core.buffer.IoBuffer)

Not known when codec or objectCodecPattern or transferExchange is set.

Consumer reply

null or text

With sync=true (the default) the body the route ends with is written back to the caller; with sync=false nothing is written. Send a String: textline=true converts any body to a line of text, and the object codec writes any Serializable object, which a Mina client accepts only when its objectCodecPattern lists the class (a byte array needs [B). No body sends nothing and closes the connection (disconnectOnNoReply).

  • With textline=true: any

  • With protocol=udp: null, text, bytes, stream or file

  • With allowDefaultCodec=false: null or pojo (org.apache.mina.core.buffer.IoBuffer)

Not known when codec or transferExchange is set.

Producer input

null or text

The data to send: a String. The default object codec over TCP serializes the body, but a Mina server accepts only a String unless its objectCodecPattern lists the class, and a stream fails; textline=true converts any body to a line of text. No body sends nothing.

  • With textline=true: any

  • With protocol=udp: null, text, bytes, stream or file

  • With allowDefaultCodec=false: null or pojo (org.apache.mina.core.buffer.IoBuffer)

Not known when codec or transferExchange is set.

Producer output

text or null (java.lang.String)

With sync=true (the default) the reply of the server as a String, or a byte array over UDP. The object codec accepts another reply only when objectCodecPattern lists its class (a byte array needs [B). No body is not sent and stays null. With sync=false the message is unchanged.

  • With sync=false: unchanged

  • With protocol=udp: bytes or null (byte[])

  • With allowDefaultCodec=false: pojo or null (org.apache.mina.core.buffer.IoBuffer)

Not known when codec or objectCodecPattern or transferExchange is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Using a custom codec

See the Mina how to write your own codec. To use your custom codec with camel-mina, you should register your codec in the Registry; for example, by creating a bean in the Spring XML file. Then use the codec option to specify the bean ID of your codec. See HL7 that has a custom codec.

The reply of the consumer

With sync=true (the default) the consumer writes the body the route ends with back to the client. With textline=true the body is converted to a String first, so a byte[] or a stream is written as its text.

The default object codec (no textline and no codec) only deserializes the classes that objectCodecPattern lists, and a String. This applies to the reply as well: a producer that should receive a byte[] reply needs objectCodecPattern=[B. Without it the producer fails to decode the reply with a StreamCorruptedException (such as invalid type code: 42). Keep objectCodecPattern as narrow as the replies need.

When the route ends with no body, the consumer writes nothing, logs it at noReplyLogLevel and closes the session, so the client does not wait for a reply. Set disconnectOnNoReply=false to keep the session open.

Get the IoSession for message

You can get the IoSession from the message header with this key CamelMinaIoSession, and also get the local host address with the key CamelMinaLocalAddress and remote host address with the key CamelMinaRemoteAddress.

Configuring Mina filters

Filters permit you to use some Mina Filters, such as SslFilter. You can also implement some customized filters. Please note that codec and logger are also implemented as Mina filters of the type, IoFilter. On a consumer that listens for connections, the filters you define are appended to the end of the filter chain; that is, after codec and logger. On the producer, and on a consumer with clientMode=true, they are added after logger and before codec, so they see the encoded data.

Using SSL/TLS

Set sslContextParameters on the endpoint, or useGlobalSslContextParameters on the component, to use SSL/TLS with the TCP protocol. The trust store, key store, protocols and cipher suites are configured with the Camel JSSE Configuration Utility.

When Camel opens the connection (the producer, or the consumer with clientMode=true), it checks that the certificate of the server matches the host of the endpoint, with the same rules as an HTTPS client. A connection to an IP address needs a certificate that lists that address as a subject alternative name. Set hostnameVerification=false to turn this check off; the certificate chain is still validated against the trust store.

MINA keeps a failed handshake in its SSL handler instead of passing the error on, so a certificate that does not match shows up as a timeout of the producer (after writeTimeout, or timeout while waiting for a reply) rather than as an SSL error. The handshake error is logged at ERROR level by org.apache.mina.filter.ssl.SslHandler: when a producer times out after you enable SSL, check that log and the subject alternative names of the certificate.

Examples

Example with sync=false

In this sample, Camel exposes a service that listens for TCP connections on port 6200. We use the textline codec. In our route, we create a Mina consumer endpoint that listens to on port 6200: .Java-only: Java string concatenation with port variable

from("mina:tcp://localhost:" + port1 + "?textline=true&sync=false").to("mock:result");

As the sample is part of a unit test, we test it by sending some data to it on port 6200.

Java-only: Java test API (MockEndpoint and ProducerTemplate)
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");

template.sendBody("mina:tcp://localhost:" + port1 + "?textline=true&sync=false", "Hello World");

MockEndpoint.assertIsSatisfied(context);

Example with sync=true

In the next sample, we have a more common use case where we expose a TCP service on port 6201 also use the textline codec. However, this time we want to return a response, so we set the sync option to true on the consumer.

  • Java

  • XML

  • YAML

from("mina:tcp://localhost:{{port}}?textline=true&sync=true")
    .setBody(simple("Bye ${body}"));
<route>
  <from uri="mina:tcp://localhost:{{port}}?textline=true&amp;sync=true"/>
  <setBody>
    <simple>Bye ${body}</simple>
  </setBody>
</route>
- route:
    from:
      uri: mina:tcp://localhost:{{port}}
      parameters:
        textline: true
        sync: true
      steps:
        - setBody:
            simple: "Bye ${body}"

Then we test the sample by sending some data and retrieving the response using the template.requestBody() method. As we know the response is a String, we cast it to String and can assert that the response is, in fact, something we have dynamically set in our processor code logic.

Java-only: Java test API (ProducerTemplate)
String response = (String)template.requestBody("mina:tcp://localhost:" + port2 + "?textline=true&sync=true", "World");
assertEquals("Bye World", response);

Example with Spring DSL

Spring DSL can also be used for MINA. In the sample below, we expose a TCP server on port 5555:

  • Java

  • XML

  • YAML

from("mina:tcp://localhost:5555?textline=true")
    .to("bean:myTCPOrderHandler");
<route>
  <from uri="mina:tcp://localhost:5555?textline=true"/>
  <to uri="bean:myTCPOrderHandler"/>
</route>
- route:
    from:
      uri: mina:tcp://localhost:5555
      parameters:
        textline: true
      steps:
        - to:
            uri: bean:myTCPOrderHandler

In the route above, we expose a TCP server on port 5555 using the textline codec. We let the Spring bean with ID, myTCPOrderHandler, handle the request and return a reply. For instance, the handler bean could be implemented as follows:

Java-only: Java handler class
    public String handleOrder(String payload) {
        ...
        return "Order: OK"
   }

Closing Session When Complete

When acting as a server, you sometimes want to close the session when, for example, a client conversion is finished. To instruct Camel to close the session, you should add a header with the key CamelMinaCloseSessionWhenComplete set to a boolean true value.

For instance, the example below will close the session after it has written the bye message back to the client:

  • Java

  • XML

  • YAML

from("mina:tcp://localhost:8080?sync=true&textline=true")
    .setBody(simple("Bye ${body}"))
    .setHeader("CamelMinaCloseSessionWhenComplete", constant(true));
<route>
  <from uri="mina:tcp://localhost:8080?sync=true&amp;textline=true"/>
  <setBody>
    <simple>Bye ${body}</simple>
  </setBody>
  <setHeader name="CamelMinaCloseSessionWhenComplete">
    <constant>true</constant>
  </setHeader>
</route>
- route:
    from:
      uri: mina:tcp://localhost:8080
      parameters:
        sync: true
        textline: true
      steps:
        - setBody:
            simple: "Bye ${body}"
        - setHeader:
            name: CamelMinaCloseSessionWhenComplete
            constant: "true"