1

我目前从队列中收到一条字符串消息,该字符串消息包含 XML。如何选择每个元素并转换为 POJO。这是我队列的内容

<MsgContent>
   <MsgHeader>
       <code>1010</code>
   </MsgHeader>
   <MsgBody>
        <value>fundstransfer</value>
   </MsgBody>
</MsgContent>

我希望能够获得两个键的值(代码和值)

这是我的骡子配置 xml

    <?xml version="1.0" encoding="UTF-8"?>

    <mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:data-        mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"          xmlns:xm="http://www.mulesoft.org/schema/mule/xml"  xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"   xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/xml  http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
    http://www.mulesoft.org/schema/mule/core  http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
    http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
   <jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>

<mulexml:jaxb-context name="myJaxb" doc:name="myJaxb" packageNames="com.test.jaxb" />
<flow name="JMSMessageFlow1" doc:name="JMSMessageFlow1">
    <jms:inbound-endpoint queue="StudioIns" connector-ref="Active_MQ" doc:name="JMS" />
    <custom-transformer class="org.mule.module.xml.transformer.XmlToXMLStreamReader" />
    <mulexml:jaxb-xml-to-object-transformer  jaxbContext-ref="myJaxb" returnClass="com.test.jaxb.MsgContent"/>
    <component class="com.test.HelloMessage" doc:name="Java"/>
    <file:outbound-endpoint path="D:\Documents\MuleStudio\workspace\jmsmessage\src\main\java\com\test" outputPattern="output.csv" responseTimeout="10000" doc:name="File"/>
</flow>

但仍然无法检索对象

4

3 回答 3

3

您不能xml为此使用命名空间,它是保留的。人们通常使用xmmulexml

例如:

xmlns:xm="http://www.mulesoft.org/schema/mule/xml"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd"

...

<xm:xml-to-object-transformer />
于 2013-08-05T16:35:47.910 回答
0

我现在已经解决了。主要问题是必须有一个有效且正确的 JAXB 绑定类。谢谢大家

于 2013-08-12T12:41:24.120 回答
0

在我的应用程序中,我有一个 xml 声明我需要使用的所有转换器,以便我在我的流程中引用它们。见下文。(您不需要使用 iso-8859-1)。这认为您打算使用 JAXB 将 XML 绑定到 POJO。

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mxml="http://www.mulesoft.org/schema/mule/xml"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.2/mule-xml.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<mxml:jaxb-context
name="jaxb-context"
packageNames="my.package.v1:my.package.v2:soap.package" />

<mxml:jaxb-xml-to-object-transformer
name="xml-to-object"
encoding="ISO-8859-1"
jaxbContext-ref="jaxb-context"
ignoreBadInput="true" />

<mxml:jaxb-object-to-xml-transformer
name="object-to-xml"
encoding="ISO-8859-1"
jaxbContext-ref="jaxb-context"
returnClass="java.lang.String"
ignoreBadInput="true" />

<byte-array-to-string-transformer
name="byte-array-to-string"
encoding="ISO-8859-1"
returnClass="java.lang.String" />

<string-to-byte-array-transformer
name="string-to-byte-array"
encoding="ISO-8859-1"
returnClass="byte[]" />

<custom-transformer
name="xml-to-xml-stream-reader"
class="org.mule.module.xml.transformer.XmlToXMLStreamReader" />

<object-to-string-transformer name="object-to-string" />

<flow name="ByteArrayToObjectXml">

<vm:inbound-endpoint
    path="myapp/conversor/byte-array-to-object-xml"
    exchange-pattern="request-response" />

<transformer ref="byte-array-to-string" />
<transformer ref="xml-to-object" />
</flow>
于 2013-08-07T13:39:49.080 回答