Kevin
Kevin

Reputation: 6833

JMS Message Parse Exception

My java code is taking XML messages from my local ActiveMQ queue. Now it can successfully consume messages from the queue, but it seems fails to parse it? My xml data looks like this:

 #---------- #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.

Is this something configurable in the code? Thanks.

Upvotes: 0

Views: 1180

Answers (2)

mega6382
mega6382

Reputation: 9396

try to change your xml to the following if you can:

<?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. and use <?xml version="1.0" encoding=utf-8"?> in the beginning of the file

Upvotes: 0

Joni
Joni

Reputation: 111229

Your data is not well-formed XML and cannot be parsed with an XML parser as-is. You'll have to find a way to separate the XML data before and after the BodyLength=850 line and parse them separately.

Upvotes: 1

Related Questions