ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » How to extract the text from a TextMessage?

Post new topic  Reply to topic Goto page 1, 2  Next
 How to extract the text from a TextMessage? « View previous topic :: View next topic » 
Author Message
fredand44
PostPosted: Tue Feb 21, 2006 5:06 am    Post subject: How to extract the text from a TextMessage? Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!

We have some problem with sending a message from WAS to MQ and forward to WAS again.

We can not extract the text from an TextMessage.

Sent message from WAS (the text=1140526528099):
[2006-02-21 13:55:33:958 CET] 00000037 SystemOut O The message

JMSMessage class: jms_text
JMSType: JMSC.MQJMS_CLIENT_NONJMS_MQ
JMSDeliveryMode: 1
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:1ce2eb5f73c2db81fbf26591110a134f0000000000000001
JMSTimestamp: 1140526533943
JMSCorrelationID: null
JMSDestination: queue://DToQ?busName=WSBus&readAhead=AlwaysOn
JMSReplyTo: null
JMSRedelivered: false
JMSXUserID:
JMSXAppID: Service Integration Bus
1140526528099

Received message from MQ:
[2006-02-21 13:55:47:973 CET] 00000051 SystemOut O The message:

JMSMessage class: jms_text
JMSType: null
JMSDeliveryMode: 1
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:1ce2eb5f73c2db81fbf26591110a134f0000000000000001
JMSTimestamp: 1140526533094
JMSCorrelationID: null
JMSDestination: queue://QTOD?busName=WSBus&readAhead=AlwaysOn
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_Encoding: 273
JMS_IBM_System_MessageID: BC73EA21F0444ABE_10000016
JMS_IBM_MsgType: 0
JMSXUserID:
JMS_IBM_PutTime: 12553394
JMS_IBM_PutApplType: 31
JMS_IBM_Format: MQSTR
JMS_IBM_PutDate: 20060221
JMSXAppID: Service Integration Bus
JMS_IBM_Character_Set: 1208


It looks like the message gets encoded or something. We have tried 2 different types of the TextMessage before we send it:
outMessage.setJMSType("JMSC.MQJMS_CLIENT_NONJMS_MQ");
or
outMessage.setJMSType("package_received");

So if any one know how to be able to extract the text please let us know. Any explantion is also welcome!

Best regards
Fredrik
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Feb 21, 2006 5:39 am    Post subject: Re: How to extract the text from a TextMessage? Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

fredand44 wrote:
We can not extract the text from an TextMessage.

Have you tried javax.jms.TextMessage.getText() ?
Back to top
View user's profile Send private message
fredand44
PostPosted: Tue Feb 21, 2006 5:47 am    Post subject: This is our code... Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!
Thanks for your reply.

This is our code:

Receiving:
try
{
String JMSCF_JNDI_NAME = "jms/WSFactory";
String JMSQ_JNDI_NAME = "jms/WSQueue2";

InitialContext initCtx = new InitialContext();
javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup(JMSCF_JNDI_NAME);
Destination q = (Destination) initCtx.lookup(JMSQ_JNDI_NAME);
Connection connection = qcf.createConnection();
Session ssession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer queueReceiver = ssession.createConsumer(q);

connection.start();
Message message = queueReceiver.receiveNoWait();

if (message != null)
{
message.setJMSType("JMSC.MQJMS_CLIENT_NONJMS_MQ");
if (message instanceof ObjectMessage)
{
System.out.println("ObjectMessage");
messageText = (String) ((ObjectMessage)message).getObject();
}

else if (message instanceof MapMessage)
{
System.out.println("MapMessage");
messageText = (String) ((MapMessage)message).getObject("messageString");
}
else if (message instanceof BytesMessage)
{
System.out.println("BytesMessage");
byte[] bytes = new byte[2000];
((BytesMessage)message).readBytes(bytes);
messageText = new String(bytes);
}
else if (message instanceof StreamMessage)
{
System.out.println("StreamMessage");
messageText = ((StreamMessage)message).readString();
}
else if (message instanceof TextMessage)
{
System.out.println("TextMessage");
messageText = ((TextMessage)message).getText();
}
else
{
System.out.println("Something else: " + message.getClass().getName());
}
}
else
{
System.out.println("The message is null!!");
}

System.out.println("The message:\n" + message);
System.out.println("The text:\n" + messageText);

queueReceiver.close();
ssession.close();
connection.close();
System.out.println("Recv completed");
}
catch(Exception e)
{
e.printStackTrace();
}

Sending:
try
{
String JMSCF_JNDI_NAME = "jms/WSFactory";
String JMSQ_JNDI_NAME = "jms/WSQueue";

InitialContext initCtx = new InitialContext();
javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup(JMSCF_JNDI_NAME);

Destination q = (Destination) initCtx.lookup(JMSQ_JNDI_NAME);

Connection connection = qcf.createConnection();
Session ssession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer queueSender = ssession.createProducer(q);

TextMessage outMessage = ssession.createTextMessage();
outMessage.setText(messageText);
outMessage.setJMSType("JMSC.MQJMS_CLIENT_NONJMS_MQ");
outMessage.setJMSDestination(q);

System.out.println("The properties:\n");
for (Enumeration e = outMessage.getPropertyNames() ; e.hasMoreElements() ;)
{
System.out.println(e.nextElement());
}


queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(outMessage);

connection.close();

System.out.println("The message\n" + outMessage);
System.out.println("Send completed");


}
catch(Exception e)
{
e.printStackTrace();
}

Do you see anything stupid?

Best regards
Fredrik
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Feb 21, 2006 6:00 am    Post subject: Re: This is our code... Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

OK one note first:
Code:
MessageConsumer queueReceiver = ssession.createConsumer(q)

javax.jms.QueueReceiver and javax.jms.MessageConsumer are separate classes, with different purposes. Just wanted to point that out in case it helps.

Now, the problem. I can't see from the code snippet exactly what type of message is being received. What is the line in SystemOut before:
Code:
[2006-02-21 13:55:33:958 CET] 00000037 SystemOut O The message
Back to top
View user's profile Send private message
fredand44
PostPosted: Tue Feb 21, 2006 6:09 am    Post subject: Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!

Thanks for your reply, the output for a receive is:

[2006-02-21 15:08:18:508 CET] 00000050 ConnectionFac W J2CA0294W: Deprecated usage of direct JNDI lookup of resource jms/WSFactory. The following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O Class name: com.ibm.ws.sib.api.jms.impl.JmsTextMessageImpl
[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O TextMessage
[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O The message:

JMSMessage class: jms_text
JMSType: JMSC.MQJMS_CLIENT_NONJMS_MQ
JMSDeliveryMode: 1
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:dd0bcbeb704067c21b6c6d4f110a134f0000000000000001
JMSTimestamp: 1140530897017
JMSCorrelationID: null
JMSDestination: queue://QTOD?busName=WSBus&readAhead=AlwaysOn
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_Encoding: 273
JMS_IBM_System_MessageID: BC73EA21F0444ABE_10000033
JMS_IBM_MsgType: 0
JMSXUserID:
JMS_IBM_PutTime: 14081717
JMS_IBM_PutApplType: 31
JMS_IBM_Format: MQSTR
JMS_IBM_PutDate: 20060221
JMSXAppID: Service Integration Bus
JMS_IBM_Character_Set: 1208

[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O The text:

[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O Recv completed
[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O Exception For input string: ""

We will take a look at the classes you mentioned:
javax.jms.QueueReceiver and javax.jms.MessageConsumer

Best regards
Fredrik
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Feb 21, 2006 6:31 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

The text of the text message appears to be empty. This is (part of) the code
Code:
System.out.println("The text:\n" + messageText);
...
System.out.println("Recv completed");

This is the output from that code
Code:
[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O The text:

[2006-02-21 15:08:18:633 CET] 00000050 SystemOut O Recv completed

This appears to be a successful receive of a text message with no text. Did I misunderstand the problem?
Back to top
View user's profile Send private message
BenR
PostPosted: Tue Feb 21, 2006 6:45 am    Post subject: Reply with quote

Acolyte

Joined: 31 Jan 2006
Posts: 60
Location: Hursley, UK

Quote:
outMessage.setJMSType("JMSC.MQJMS_CLIENT_NONJMS_MQ");


It's worth noting that JMSType won't do anything with this
Back to top
View user's profile Send private message Visit poster's website
fredand44
PostPosted: Tue Feb 21, 2006 6:47 am    Post subject: We guess you understod correct... Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!
Actually that is what we think as well. The strange thing is where does the text go???

We send a message with a text, but when we receive it the text is gone?

Strange?

/Fredrik
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Feb 21, 2006 6:52 am    Post subject: Re: We guess you understod correct... Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

fredand44 wrote:
We send a message with a text, but when we receive it the text is gone?

Sounds like a reason to call Support. But, this is a very simple situation you are describing, and I would expect it to have been tested. So, if you decide to call and ask for defect support, perhaps first ensure you can recreate this with latest CSD on MQ and latest fixpack etc. on WAS?
Back to top
View user's profile Send private message
vennela
PostPosted: Tue Feb 21, 2006 9:31 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

What is the message format.
MQMD's format should be MQSTR if you can use the TextMessage kind of things.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
eosterm
PostPosted: Tue Feb 21, 2006 12:28 pm    Post subject: Reply with quote

Novice

Joined: 09 Feb 2006
Posts: 24

What MQ type (not JMS type) should it be if you want a BytesMessage?

Thanks,

--Erik
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Tue Feb 21, 2006 12:52 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

eosterm wrote:
What MQ type (not JMS type) should it be if you want a BytesMessage?

Leave it blank.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Feb 21, 2006 12:53 pm    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

eosterm wrote:
What MQ type (not JMS type) should it be if you want a BytesMessage?

The short answer is MQFMT_NONE. But are you sure this is the information you really need?

It should be necessary to concern yourself with MQMD.Format only if your JMS client app is consuming messages produced by a native MQI (ie. non-JMS) app.

If you do need to mix JMS and non-JMS apps, documentation for the message formats can be found at http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzaw.doc/csqzaw1381.htm
Back to top
View user's profile Send private message
eosterm
PostPosted: Tue Feb 21, 2006 1:00 pm    Post subject: Reply with quote

Novice

Joined: 09 Feb 2006
Posts: 24

Thanks, that is very helpful. Yep, we're stuck with this until someone comes out with JMS for COBOL. <grin>

We have a long-standing java class library of value objects. The getters locate EBCDIC data in fixed-position byte arrays and return standard java unicode.

--Erik
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Feb 21, 2006 5:35 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

BenR wrote:
Quote:
outMessage.setJMSType("JMSC.MQJMS_CLIENT_NONJMS_MQ");


It's worth noting that JMSType won't do anything with this


Leave the JMSType alone. Don't touch it.

If you want to send to a non JMS client you should set that on the queue:
Code:
Session.createQueue("queue://MYQMGR/MYQUEUE?targetClient=1");

You may leave the target qmgr blank so that it looks for the queue on the qmgr you are connected to: queue:///myqueue

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » How to extract the text from a TextMessage?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.