该应用程序基于OSGI。 我有一个自定义注释转换器:
package com.domain.bundle1.web.camel.converters;
import ...;
@Converter
public class FooTransferObjectConverter {
public FooTransferObjectConverter() {
}
@Converter
public static FooTransferObject toFooTransferObject(Foo foo, Exchange exchange) throws Exception {
// some magic
return fooTransferObject;
}
}
我还在TypeConverter文件中声明了它所包含的包:
http://i.stack.imgur.com/U3QQH.png
包含:
com.domain.bundle1.web.camel.converters
camel-context文件包含下一个代码:
<log loggingLevel="INFO" message="Converting to FooTransferObject" />
<convertBodyTo type="com.domain.bundle2.model.FooTransferObject" />
<log loggingLevel="INFO" message="Converted!" />
在转换之前,消息正文是Foo对象。
但是当进程转换时,会引发异常:
Failed delivery for (MessageId: ID-EPUALVIW0567-55536-1401106375216-26-5 on ExchangeId: ID-EPUALVIW0567-55536-1401106375216-26-6).
Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: com.domain.bundle2.model.FooTransferObject but has value: Foo{97, Wall, null, null} of type: com.domain.bundle3.model.Foo on: Message: Foo{97, Wall, null, null}.
Caused by: Error during type conversion from type: com.domain.bundle3.model.Foo to the required type: com.domain.bundle2.model.FooTransferObject with value Foo{97, Wall, null, null} due 6 counts of IllegalAnnotationExceptions. Exchange[Message: Foo{97, Wall, null, null}]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: Foo{97, Wall, null, null} to the required type: com.domain.bundle2.model.FooTransferObjec with value....
然后由自定义处理程序缓存异常, 然后我发现了这个:
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: freebaseball SpeedKick -> fr????f????tb??ll Sp????dK??ck -> free
football SpeedKick ]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)[:1.7.0_40]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)[:1.7.0_40]
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
at org.apache.camel.converter.jaxb.FallbackTypeConverter.marshall(FallbackTypeConverter.java:238)
at org.apache.camel.converter.jaxb.FallbackTypeConverter.convertTo(FallbackTypeConverter.java:95)
... 163 more
Caused by: com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: freebaseball SpeedKick -> fr????f????tb??ll Sp????dK??c
k -> freebaseball SpeedKick
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:237)[:1.7.0_40]
您如何看待问题是什么?如何在TypeConverterRegistry中看到加载的转换器?
答案 0 :(得分:0)
我已经解决了我的问题。 FallbackTypeConverter开始工作,因为camel没有加载我的自定义常规类型转换器。 我在调试模式下检查了TypeConverterRegister中的转换器映射,但没找到我的FooTransferObjectConverter。
问题出在文件TypeConverter
中。我只是将转换器类的名称添加到路径,然后将其加载到注册表。
com.domain.bundle1.web.camel.converters.FooTransferObjectConverter
应用程序中的Camel版本 - 2.11.1。在下面写的camel docs中:
在Camel 2.8中,我们改进了类型转换器加载器以支持 指定转换器类的FQN类名称。这有 避免必须扫描@Converter类的包的优点。 相反,它直接加载@Converter类。这是一个很高的 建议使用前进的方法。
但我尝试运行application from chapter 3 (from 'Camel in action' book) with custom converter。文件TypeConverter
仅包含在包路径中。