问题
What are the steps which should be done? What should be present in the driver class? How should I create the POJO with which to map the XML to? How should I configure the transformer?
回答1:
you can use a driver class like Xpp3driver
eg.
the flow would look something like
<flow name="mulexmlvalFlow2" doc:name="mulexmlvalFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="XmlToObj"/>
<mulexml:xml-to-object-transformer doc:name="XML to Object" driverClass="com.thoughtworks.xstream.io.xml.Xpp3Driver">
<mulexml:alias name="Abc" class="a.b.c.Abc" />
</mulexml:xml-to-object-transformer>
<component class="Test1" doc:name="Java"/>
</flow>
http request
http://localhost:8082/XmlToObj
headers Content-Type application/xml post data
<Abc><def>ggggg</def><ghi>hhhhh</ghi></Abc>
ABC class
package a.b.c.Abc;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Abc")
public class Abc{
private String def;
private String ghi;
public Abc() {
}
public String getDef() {
return def;
}
public void setDef(String def) {
this.def = def;
}
public String getGhi() {
return ghi;
}
public void setGhi(String ghi) {
this.ghi = ghi;
}
}
Class Test1 (component)
public class Test1 {
public Object receive(Abc abc) throws Exception {
System.out.println(abc);
return "Success";
}
}
来源:https://stackoverflow.com/questions/26607661/how-to-use-mules-xml-to-object-transformer