2013-04-29 30 views
3

我使用骆驼2.10.3骆驼POJO与JAXB数据格式异常产生

这里是我的骆驼背景:

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring"> 

    <endpoint id="webserviceStart" uri="direct:webserviceStart"/> 

    <dataFormats> 
     <jaxb id="jaxb" prettyPrint="true" 
     contextPath="com.jaxbtest.package" /> 
    </dataFormats> 

    <route id="myRoute"> 
     <from ref="webserviceStart" /> 
     <marshal ref="jaxb" /> 
     <to uri="spring-ws:http://wshost:8010/service"/> 
     <unmarshal ref="jaxb" /> 
    </route> 

    </camelContext> 

此代码:

@Component 
public class WebserviceClient 
{ 
    @EndpointInject(ref = "webserviceStart") 
    ProducerTemplate _producer; 

    public Response invoke(Request input) 
    { 
     return (Response) _producer.sendBody(input).getOut().getBody(); 
    } 
} 

此代码(以下“使用@Produce隐藏您的代码中的骆驼API”部分http://camel.apache.org/pojo-producing.html)不包括:

@Component 
public class WebserviceClient 
{ 
    public static interface MyWebservice 
    { 
     Response invoke(@Body Request body); 
    } 

    @EndpointInject(ref = "webserviceStart") 
    MyWebservice _producer; 

    public Response invoke(Request input) 
    { 
     return (Response) _producer.invoke(input); 
    } 
} 

它抛出一个异常:

Caused by: java.io.IOException: javax.xml.bind.JAXBException: class org.apache.camel.component.bean.BeanInvocation nor any of its super class is known to this context. 
    at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:103) 
    at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:59) 
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) 
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) 

如果这是骆驼的已知错误,没有人知道有关它的问题?我应该为此创建一个新的JIRA吗?这似乎是POJO生产的一个简单用例。

回答

-2

通常,当你得到这个错误时,这意味着你没有在JAXB上下文中设置类的列表。

你会在JAVA DSL做 -

JAXBContext context = JAXBContext.newInstance('your classes'); 
      JaxbDataFormat jaxb = new JaxbDataFormat(); 
      jaxb.setContext(context); 

,然后使用您的自定义DATAFORMAT 'JAXB' 作为您的元帅/解组参考。

谢谢!

+0

你可以看到contextPath是在''元素中指定的。除了代码工作的第一个例子。 – Strelok 2013-04-29 05:46:06