使用JAXB数据格式异常生成的Camel POJO

时间:2013-04-29 01:21:18

标签: jaxb apache-camel jaxb2

我正在使用Camel 2.10.3

这是我的骆驼背景:

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

此代码(在http://camel.apache.org/pojo-producing.html之后的“使用@Produce隐藏代码中的Camel API”部分之后)不会:

@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生成的一个简单用例。

1 个答案:

答案 0 :(得分:-2)

通常,当您收到此错误时,表示您尚未在JAXB上下文中设置类列表。

你会用JAVA DSL做的 -

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

然后使用您的自定义数据格式'jaxb'作为您的编组/解组参考。

谢谢!