2013-04-29 33 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