简体   繁体   English

JMS消息解析异常

[英]JMS Message Parse Exception

My java code is taking XML messages from my local ActiveMQ queue. 我的Java代码从本地ActiveMQ队列中获取XML消息。 Now it can successfully consume messages from the queue, but it seems fails to parse it? 现在它可以成功使用队列中的消息,但是似乎无法解析它? My xml data looks like this: 我的xml数据如下所示:

 #---------- #1 :  ----------#
 <MSG_INFO>
    <message type="TextMessage" messageSelector="" originationTimestamp="" receiveTime="" jmsServerTimestamp="" jmsMsgExpiration="">
     <header JMSDestination="Asurion.SYD02.Q.Business.NonPersistent.Policy.PublishTelstraAMAEnrollments" JMSDestinationType="Queue" JMSDeliveryMode="1" />
        <properties>
        <property name="Client" type="String">Telstra</property>
       </properties>
    </message>
 </MSG_INFO>
 BodyLength=850
 <?xml version="1.0" encoding="UTF-8"?>
 <ns0:PublishEnrollmentRequest xmlns:ns0="http://services.asurion.com/schemas/PolicyAdministration/PublishEnrollmentRequest/1.0">
  <ns0:Parameters>
    <ns0:Enrollments>
        <ns0:MDN>9890667692</ns0:MDN>
        <ns0:FeatureCode>MBBPHPMPS</ns0:FeatureCode>
        <ns0:ProductName>MTS-SA</ns0:ProductName>
        <ns0:Status>Active</ns0:Status>
        <ns0:Active>Y</ns0:Active>
        <ns0:EffectiveDate>2013-07-02T19:36:51-04:00</ns0:EffectiveDate>
        <ns0:EnrollmentType>Customer</ns0:EnrollmentType>
        <ns0:Make>UnKnown</ns0:Make>
        <ns0:Model>UnKnown</ns0:Model>
        <ns0:ActivationDate>2013-07-02T19:36:51-04:00</ns0:ActivationDate>
        <ns0:ESN />
        <ns0:IMEI />
        <ns0:SubID>281474977839805</ns0:SubID>
        <ns0:Operation>Enrollment Added</ns0:Operation>
    </ns0:Enrollments>
</ns0:Parameters>

The exception I am getting now is: 我现在得到的例外是:

  Caused by: org.xml.sax.SAXParseException: Unexpected element: CDATA

I understand it might be the BodyLength tne that may cause this problem, but if I got rid of them, my code will not be able to extrat client information from it. 我知道可能是BodyLength引起了此问题,但是如果我摆脱了它们,我的代码将无法从中提取客户信息。

Is this something configurable in the code? 这可以在代码中配置吗? Thanks. 谢谢。

Your data is not well-formed XML and cannot be parsed with an XML parser as-is. 您的数据不是格式正确的XML ,因此无法按原样使用XML解析器进行解析。 You'll have to find a way to separate the XML data before and after the BodyLength=850 line and parse them separately. 您将必须找到一种方法,以在BodyLength=850行之前和之后将XML数据分离并分别解析它们。

try to change your xml to the following if you can: 如果可以,请尝试将xml更改为以下内容:

<?xml version="1.0" encoding="UTF-8"?>
 <ns0:PublishEnrollmentRequest xmlns:ns0="http://services.asurion.com/schemas/PolicyAdministration/PublishEnrollmentRequest/1.0">
  <ns0:Parameters>
    <ns0:Enrollments>
        <ns0:MDN>9890667692</ns0:MDN>
        <ns0:FeatureCode>MBBPHPMPS</ns0:FeatureCode>
        <ns0:ProductName>MTS-SA</ns0:ProductName>
        <ns0:Status>Active</ns0:Status>
        <ns0:Active>Y</ns0:Active>
        <ns0:EffectiveDate>2013-07-02T19:36:51-04:00</ns0:EffectiveDate>
        <ns0:EnrollmentType>Customer</ns0:EnrollmentType>
        <ns0:Make>UnKnown</ns0:Make>
        <ns0:Model>UnKnown</ns0:Model>
        <ns0:ActivationDate>2013-07-02T19:36:51-04:00</ns0:ActivationDate>
        <ns0:ESN />
        <ns0:IMEI />
        <ns0:SubID>281474977839805</ns0:SubID>
        <ns0:Operation>Enrollment Added</ns0:Operation>
    </ns0:Enrollments>
</ns0:Parameters>
 <MSG_INFO>
    <message type="TextMessage" messageSelector="" originationTimestamp="" receiveTime="" jmsServerTimestamp="" jmsMsgExpiration="">
     <header JMSDestination="Asurion.SYD02.Q.Business.NonPersistent.Policy.PublishTelstraAMAEnrollments" JMSDestinationType="Queue" JMSDeliveryMode="1" />
        <properties>
        <property name="Client" type="String">Telstra</property>
       </properties>
    </message>
 </MSG_INFO>
 <body  BodyLength="850" />
</ns0:PublishEnrollmentRequest>

If you don't want to change your xml try separating you xml above and beneath BodyLength=850 . 如果您不想更改xml,请尝试在BodyLength=850上方和下方分隔xml。 and use <?xml version="1.0" encoding=utf-8"?> in the beginning of the file 并在文件开头使用<?xml version="1.0" encoding=utf-8"?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM