File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a JMS TextMessage From XML

 
trupti nigam
Ranch Hand
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all.

I have to send a XML message as JMS TextMessage On the message queue.
I don't know how to create a TextMessage from the XML file.

Can someone please let me know the same.

Thanks,
Trupti
 
Mattias Arthursson
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Provided you know the basics of sending a JMS message (otherwise you should be able to find a good tutorial using google), you do as follows:

Basically you just read the XML from the file as you would any other file, create a TextMessage by calling createTextMessage() on the JMS Session, call setText() on the TextMessage and call send() with this message on your Queue instance.
 
trupti nigam
Ranch Hand
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello mattias,

Provided you know the basics of sending a JMS message (otherwise you should be able to find a good tutorial using google), you do as follows:

Basically you just read the XML from the file as you would any other file,
My problem is this...
Can you let me know how to do this. I have sent textMessage using JMS but have never created one from the existing .xsd file. could you please let me know the same

below is the schema of my file:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema jxb:version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<xs:element name="StatusChange">
<xs:complexType>
<xs:sequence>
<xs:element name="Req" type="Req" minOccurs="0"/>
<xs:element name="Res" type="Res" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Req">
<xs:sequence>
<xs:element name="carcode" type="xs:string"/>
<xs:element name="carNumeric" type="xs:string"/>
<xs:element name="comId" type="xs:string"/>
<xs:element name="docNumber" type="xs:string"/>
<xs:element name="docType" type="xs:string"/>
<xs:element name="nbrCon" type="xs:string"/>
<xs:element name="Acn" type="xs:string"/>
<xs:element name="docSeqNumber" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Res">
<xs:sequence>
<xs:element name="docNumber" type="xs:string"/>
<xs:element name="docType" type="xs:string"/>
<xs:element name="docSeqNumber" type="xs:string"/>
<xs:element name="bookNumber" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


thanks in advance,

Trupti
 
mohana konakanchi
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String message = //form string out of your xml message.

//create text message.
TextMessage textMessage = session.createTextMessage(message);

Then send the textMessage.
 
Mattias Arthursson
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if I understand you correctly, but it seems that your main problem is to create your XML document, am I right? For this you would use DOM, some utility XMLWriter class (there are some available on the net), or some custom tool to do it for you - I would recommend Castor (if the size of the data is not too big, but then again it wouldn't be a very good idea to send a whole lot of data using JMS anyway...).
 
trupti nigam
Ranch Hand
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All,

I could solve the problem..

I am using JAXB for converting the JAXB object to a string.
Before that I set the JAXB object with appropriate values.
and then storing it in the TextObject and sending it over JMS.

Thanks a lot for replying so promtly..

trupti
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic