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 » Encoding problem when creating the MQMessage

Post new topic  Reply to topic
 Encoding problem when creating the MQMessage « View previous topic :: View next topic » 
Author Message
jazzu
PostPosted: Mon Oct 12, 2009 4:46 am    Post subject: Encoding problem when creating the MQMessage Reply with quote

Newbie

Joined: 12 Oct 2009
Posts: 5

Hi All,

I have a problem when I'm creating my MQMessage.

Code:
   public static void main(String[] args) {
      MQQueueManager qMgr;
      try {
         MQEnvironment.hostname = QMGR_HOSTNAME;
         MQEnvironment.port = QMGR_PORT;
         MQEnvironment.channel  = QMGR_CHANNEL;

         qMgr = new MQQueueManager(QMGR);
         System.out.println("Have connected to the queue manager: " + QMGR);
         try {
            int openOptions = MQC.MQOO_OUTPUT;
            MQQueue myQueue = qMgr.accessQueue(QUEUE, openOptions, null, null, null);
            System.out.println("Have got connection to the queue: " + QUEUE);

            try {
               MQMessage message = new MQMessage();

               String msgData = "Test ÅÄÖ";
               
               message.format = MQC.MQFMT_STRING;
               message.characterSet = 1208;
               message.writeString(msgData);

               MQPutMessageOptions pmo = new MQPutMessageOptions();
               pmo.options = MQC.MQPMO_NONE;

               myQueue.put(message, pmo);
               
               System.out.println("Message have been placed on the queue");
            } catch (MQException ex) {
               System.err.println("Error putting message onto queue " + ex.completionCode + " " + ex.reasonCode);
            } catch (IOException ex) {
               System.err.println("IOException");
            }
            myQueue.close();
            System.out.println("Have closed the queue");
         } catch (MQException ex) {
            System.err.println("Error opening queue " + ex.completionCode + " " + ex.reasonCode);
         }
         qMgr.disconnect();
         System.out.println("Have disconnected from the queue manager");
      } catch (MQException ex) {
         System.err.println("Error opening queue manager " + ex.completionCode + " " + ex.reasonCode);
      } catch (Exception e) {
         System.err.println("Generic error ");
         e.printStackTrace(System.err);
      }
   }



When I'm debuging the application I the value of msgData has the Unicodes after adding it to MQMessage and in watch look on _writeBytes value the unicodes are missing. When sending the information on Queue the wrong characters are saved.

Could you please help me and tell me where there can be a problem ?

I've also tried other methods to build message writeUTF, write etc.

Best Regards
Michal Sadowki
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Oct 12, 2009 12:32 pm    Post subject: Reply with quote

Grand High Poobah

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

OK,

Another one of the CCSID saga...

You are putting the message in ccsid 1208 (message text is UTF-8 yes?)

Verify the text on the message using RFHUtil(c)

Verify the message has 1208 as the ccsid on the MQMD.
Verify the characters in Hex.
Verify that you did not do a get with convert...
Verify that none of the channels it passes through does a conversion.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jazzu
PostPosted: Mon Oct 12, 2009 9:09 pm    Post subject: Reply with quote

Newbie

Joined: 12 Oct 2009
Posts: 5

Hi,

I've checked the MQEnvironment.CCSID and it's set to 819.

I'm waiting for the info about channel now but can it be the channel when the message is filled up with wrong chars before sending ?

My question is if I can set something to set the MQEnvironment.CCSID to 1208 automatically ?

Thank you for response.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 13, 2009 3:06 am    Post subject: Reply with quote

Grand High Poobah

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

jazzu wrote:
Hi,

I've checked the MQEnvironment.CCSID and it's set to 819.

I'm waiting for the info about channel now but can it be the channel when the message is filled up with wrong chars before sending ?

My question is if I can set something to set the MQEnvironment.CCSID to 1208 automatically ?

Thank you for response.

Assign that value in your code.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jazzu
PostPosted: Tue Oct 13, 2009 3:26 am    Post subject: Reply with quote

Newbie

Joined: 12 Oct 2009
Posts: 5

Unfortunately it doesn't work I still can't see UTF-8 characters when debugging.

As I found out the string I provide to writeString method is converted to character set that is defined. Now I have CCSID and characterSet set up to 1208 but it's still not working.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 13, 2009 3:36 am    Post subject: Reply with quote

Grand High Poobah

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

Shouldn't the CharSet be UTF-8 ?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jazzu
PostPosted: Tue Oct 13, 2009 4:10 am    Post subject: Reply with quote

Newbie

Joined: 12 Oct 2009
Posts: 5

1208 is utf-8 and still doesn't work. Maybe some settings are inherited from local environment settings.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 13, 2009 9:22 am    Post subject: Reply with quote

Grand High Poobah

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

jazzu wrote:
1208 is utf-8 and still doesn't work. Maybe some settings are inherited from local environment settings.

What I meant to say is:
CCSID is 1208 and that is UTF-8
CharSet=> (As a member of one of the java.nio subpackages) I don't know the 1208 value for this. But I do know java will understand a CharSet of "UTF-8" and give you the right translator for parse and write...

This would qualify for writing bytes.
However you use writeString.

Is your String in true UCS format? (String msgData = "Test ÅÄÖ")
I would suggest you verify this with a little standalone Java.
Transform the incoming bytes from UTF-8 to standard Java (UCS) (quite easy to do with java.nio.)
Then write that String to the message.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rekarm01
PostPosted: Tue Oct 13, 2009 9:24 pm    Post subject: Re: Encoding problem when creating the MQMessage Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

jazzu wrote:
When sending the information on Queue the wrong characters are saved.

It helps to be more specific. Which wrong characters were saved? What evidence supports that conclusion? How, exactly, does the expected result differ from the actual result?

jazzu wrote:
I've checked the MQEnvironment.CCSID and it's set to 819.

MQEnvironment.CCSID describes how the character fields in the MQMD header itself are encoded, and only when connecting to a QMgr in client mode. It has nothing to do with the message data.

The first thing to do is confirm that the source string is correct:

jazzu wrote:
Code:
String msgData = "Test ÅÄÖ";

Is that really what the source string is supposed to look like?

The second thing to do is to make sure the Java source code compiles correctly. Non-ASCII characters can cause problems; the Java compiler needs to use the same character encoding scheme to read the source file that the Java editor used to write the source file. The details for configuring the Java editor and compiler depend on the implementation.

A more portable approach is to restrict source code to the ASCII character set. Use Unicode Escapes to represent non-ASCII characters:

Code:
String msgData = "Test \u0102\u2026\u0102\u201e\u0102\u2013";

If that fixes the problem, then the Java compiler configuration was at fault.

The third thing to do is to examine the message on the put queue with rfhutil, or amqsbcg0, or comparable display tool. Some "debugging" tools might display non-ASCII characters incorrectly, making it difficult to determine whether a problem lies with the message, or the display. It helps to be able to examine the bytes directly in an unambiguous form (such as hexadecimal):

Code:
AMQSBCG0 - starts here
**********************
...
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0
  Encoding : 273  CodedCharSetId : 1208
  Format : 'MQSTR   '
...
****   Message      ****

 length - 20 bytes

00000000:  5465 7374 20C4 82E2 80A6 C482 E280 9EC4 'Test Ä.â.¦Ä.â..Ä'
00000010:  82E2 8093                               '.â..            '

Here, the displayed hex bytes are accurate, even if the displayed characters are not.

fjb_saper wrote:
CCSID is 1208 and that is UTF-8
CharSet=> (As a member of one of the java.nio subpackages) ... But I do know java will understand a CharSet of "UTF-8" and give you the right translator for parse and write...

java.nio.charset classes are probably unnecessary, except perhaps to compare WMQ conversion methods against J2SE conversion methods; otherwise, the WMQ MQMessage write methods are sufficient:

Code:
message.format = MQC.MQFMT_STRING;
message.characterSet = 1208;
message.writeString(msgData);

... although for WMQ v7, the MQC interface is deprecated; use the MQConstants class instead.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Encoding problem when creating the MQMessage
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.