0
我正在向生產者端點發送Java對象並等待編組的XML對象。我試圖將其更改爲Node
對象/文件對象,但它給出ClassCastException
。駱駝JAXB編組返回XML對象類型?
所以把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>
會如何,我們將它轉換爲XML類型? –