• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Creating a JMS TextMessage From XML

 
Ranch Hand
Posts: 644
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 644
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 644
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic