Camel HL7codec 无法在 Java DSL 中工作

Camel HL7codec not working in Java DSL

我试图使用 camel-hl7 组件在 camel 中创建一个 hl7 侦听器。当我在 camel-spring 中使用相同的方法时,它正在工作。但是当我尝试在 Java DSL 中使用相同的内容时,

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");
            }
        });

它抛出异常,

java.lang.IllegalArgumentException: 无法为 属性 找到合适的 setter: 编解码器,因为没有相同类型的 setter 方法: java.lang.String 也无法进行类型转换:没有类型转换器可用于将类型:java.lang.String 转换为所需类型:org.apache.mina.filter.codec.ProtocolCodecFactory,值为 hl7codec !在 org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:588) !在 org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:616) !在 org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:473) !在 org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:483) !在 org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:255) !在 org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:257) !在 org.apache.camel.component.mina.MinaComponent.createEndpoint(MinaComponent.java:92) !在 org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114) !在 org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:568) ! ... 省略了 33 个常用框架 !原因:org.apache.camel.ResolveEndpointFailedException:无法解析端点:mina://tcp://localhost:4444?codec=hl7codec&sync=true 由于:无法为 属性 找到合适的 setter:编解码器,因为没有具有相同类型的 setter 方法:java.lang.String 也没有可能的类型转换:没有类型转换器可用于将类型:java.lang.String 转换为所需的类型: org.apache.mina.filter.codec.ProtocolCodecFactory 值为 hl7codec !在 org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:588) !在 org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:79)

我必须将 hl7codec 注册到注册表,以便 camel 路由使用它。

 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);

现在路线开始了。