2
在我的路線中,我試圖解組傳入的XML消息。但是,當我執行代碼時,它跳過執行.processor,我無法弄清楚實際的錯誤(因爲它沒有給出)。無法使用駱駝中的jaxb解組。不調用處理器
代碼:
package nl.hari.local.cust;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.dataformat.JaxbDataFormat;
public class XMLtoObject_Camel {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
JAXBContext con = JAXBContext.newInstance(Address.class);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://C:/Hari/TstFolder/"
+ "?noop=true" + "&autoCreate=false" + "&flatten=false" + "&delete=false"
+ "&bufferSize=128")
.unmarshal(jaxbDataFormat)
//Doesn't invoke processor - start
.process(new Processor(){
public void process(Exchange exchange) throws Exception {
Address add = (Address) exchange.getIn().getBody();
System.out.println("city is" + add.getCity());
}
});
//Doesn't invoke processor - End
}
});
}
}
這是我使用的架構。我用來測試的XML在Eclipse中生成,JAXB類也是如此。
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.hari.nl/Address"
xmlns:tns="http://www.cimt.nl/Address"
elementFormDefault="qualified">
<element name="address">
<complexType>
<sequence>
<element type="string" name="city"/>
<element type="string" name="country"/>
</sequence>
<attribute type="byte" name="id"/>
</complexType>
</element>
</schema>
下面的鏈接中包含的項目結構的屏幕抓取 http://i.stack.imgur.com/4IWhD.png
JAXB生成的類應該有ObjectFactory。我沒有看到你的項目結構! –
我已按照建議更新了圖像。包含片段之後,我仍然無法將其加入處理器。我已經通過建議更新了git倉庫中的代碼,以供參考。 https://github.com/navigator007/MyRepo.git –
你碰巧再試一次。它工作!? –