Apache camel 骆驼JAXB编组返回XML对象类型?
我将一个Java对象发送到producer端点,并等待封送的XML对象。我尝试将其更改为Apache camel 骆驼JAXB编组返回XML对象类型?,apache-camel,Apache Camel,我将一个Java对象发送到producer端点,并等待封送的XML对象。我尝试将其更改为节点对象/文件对象,但它给出了ClassCastException 因此,在对象类类型中使用xmlObj。捕获响应的正确类应该是什么 public class ClientEight { @Produce(uri = "direct:invoice") ProducerTemplate template; public static void main(String args[])
节点
对象/文件对象,但它给出了ClassCastException
因此,在对象类类型中使用xmlObj。捕获响应的正确类应该是什么
public class ClientEight {
@Produce(uri = "direct:invoice")
ProducerTemplate template;
public static void main(String args[]) throws InterruptedException {
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("resources/camel-configTen.xml");
InvoiceXml invoice = new InvoiceXml("fdf3443", 3454, 435345.44 f, "hfhfddfdg"); //any java object we are passing
ClientEight client = (ClientEight) ctx.getBean("client");
Object xmlObj = client.template.requestBody(invoice);
System.out.println(xmlObj);
}
}
上面是用于将Java对象发送到生产者端点的客户机代码,由于您使用的是template.requestBody
,因此您将返回该对象
<camel:camelContext>
<camel:dataFormats>
<!-- path to jaxb annotated class -->
<camel:jaxb id="invoiceJaxb" contextPath="com.java.bean"
prettyPrint="true" />
</camel:dataFormats>
<camel:route>
<camel:from uri="direct:invoice" />
<camel:marshal ref="invoiceJaxb" />
<camel:log message=" ${body}" />
<camel:to uri="file://src/resources?fileName=One.xml"/>
</camel:route>
</camel:camelContext>
处理器将
解组
返回一个流,而不是单个对象。在camel中,更一般地说,如果您想要一个特定的类型,您不应该直接获取一个实体作为对象,而是使用各种方法将实体转换为该类型
尝试:
unmarshall
处理器返回一个流,而不是单个对象。在camel中,更一般地说,如果您想要一个特定的类型,您不应该直接获取一个实体作为对象,而是使用各种方法将实体转换为该类型
尝试:
我们将如何将其转换为xml类型?我们将如何将其转换为xml类型?
Document document = client.template.requestBody(invoice, org.w3c.dom.Document.class);