I was trying to use the camel-hl7 component to create a hl7 listener in camel. when i used the same in camel-spring, it was working. But when I try to use the same in Java DSL as follows,
HL7MLLPCodec hl7codec = new HL7MLLPCodec();
hl7codec.setCharset("iso-8859-1");
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("mina:tcp://localhost:4444?sync=true&codec=hl7codec").to("file://test");
}
});
It throws the exception,
java.lang.IllegalArgumentException: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value hl7codec ! at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:588) ! at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:616) ! at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:473) ! at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:483) ! at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:255) ! at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:257) ! at org.apache.camel.component.mina.MinaComponent.createEndpoint(MinaComponent.java:92) ! at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114) ! at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:568) ! ... 33 common frames omitted ! Causing: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: mina://tcp://localhost:4444?codec=hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value hl7codec ! at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:588) ! at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:79)
I had to register the hl7codec to the registry for the camel route to use it.
final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry();
final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry();
compositeRegistry.addRegistry(camelContext.getRegistry());
compositeRegistry.addRegistry(registry);
((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
registry.put("hl7codec", hl7codec);
And now the routes started.