我在解组数据时遇到了一个问题。
我输入:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<GetDeadlineOffset>
<deadlineCode>DC1</deadlineCode>
<parameters>
<parameter name="P1">Param 1</parameter>
<parameter name="P2">Param 2</parameter>
</parameters>
</GetDeadlineOffset>
我的映射:<?xml version="1.0" encoding="UTF-8"?>
<class name="com.evolvus.training.camel.domain.GetDeadlineOffset">
<map-to xml="GetDeadlineOffset"/>
<field name="DeadlineCode">
<bind-xml name="deadlineCode" />
</field>
<field name="parameters" type="com.evolvus.training.camel.domain.Parameter" collection="collection">
<bind-xml name="parameter" location="parameters">
<class name="com.evolvus.training.camel.domain.Parameter">
<field name="Name">
<bind-xml name="name" node="attribute" />
</field>
<field name="Value">
<bind-xml node="text"/>
</field>
</class>
</bind-xml>
</field>
</class>
我的类:Parameter.java
public class Parameter {
private String name = null;
private String value = null;
//setters and getters
}
GetDeadlineOffset.java
public class GetDeadlineOffset {
private String deadlineCode = null;
private Vector<Parameter> paramList = new Vector<Parameter>();
//setters and getters
}
ISO3166Processor.java
public class ISO3166Processor implements Processor {
public void process(Exchange arg0) throws Exception {
GetDeadlineOffset iso4217 = (GetDeadlineOffset) arg0.getIn().getBody();
System.out.println("Unmarshalled Object is: " + iso4217);
arg0.setOut(arg0.getIn());
arg0.getOut().setBody(gdo);
arg0.getOut().setHeaders(arg0.getIn().getHeaders());
}
}
路线:
<bean id="currencyProcessor" class="com.evolvus.training.camel.processor.ISO3166Processor" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<castor id="iso3166"
mappingFile="castor/castor-mapping.xml"
packages="com.evolvus.training.camel.domain"/>
</dataFormats>
<route>
<from uri="file:src/data/in?noop=true"/>
<unmarshal ref="iso3166"/>
<log message="unmarshall" />
<process ref="currencyProcessor" />
<log message="processed" />
<marshal ref="iso3166" />
<log message="reachng output2" />
<to uri="file:src/data/out?fileName=${id}" />
<stop></stop>
</route>
</camelContext>
例外:
Exhausted after delivery attempt: 1 caught:
java.lang.NullPointerException java.lang.NullPointerException
at org.exolab.castor.mapping.Mapping.loadMapping(Mapping.java:276)
[org.apache.servicemix.bundles.castor-1.3.1_2.jar:] –
The class for the root element 'GetDeadlineOffset' could not be found.
File: [not available]; line: 2; column: 20}
at org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:794)
[org.apache.servicemix.bundles.castor-1.3.1_2.jar:]
如果我marshal,它说考虑切换到使用Marshaller实例并调用marshal()
方法之一*。请给我解决这个问题。如何使用camel调用marshall的非静态方法?
这个例外:
java.lang.NullPointerException java.lang.NullPointerException
at org.exolab.castor.mapping.Mapping.loadMapping(Mapping.java:276)
[org.apache.servicemix.bundles.castor-1.3.1_2.jar:] –
表示castor找不到您的mapping.xml
。确保它包含在jar文件/classes目录中。