3

我正在使用骆驼 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-produce.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 生产的简单用例。

4

1 回答 1

-2

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

你会在 JAVA DSL 中做 -

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

然后使用您的自定义数据格式“jaxb”作为您的元帅/解组员参考。

谢谢!

于 2013-04-29T05:16:21.657 回答