aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Creating a JMS TextMessage From XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Creating a JMS TextMessage From XML " Watch "Creating a JMS TextMessage From XML " New topic
Author

Creating a JMS TextMessage From XML

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jul 26, 2004
Posts: 90
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.


Admit nothing. Blame everyone. Be bitter.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: May 16, 2001
Posts: 67
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

Joined: Jul 26, 2004
Posts: 90
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

Joined: Jun 21, 2001
Posts: 613
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a JMS TextMessage From XML