How to use Mule's XML-to-Object transformer?

戏子无情 提交于 2019-12-23 05:09:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!