2

I'm able to send messages from Java to Websphere MQ on AS400. If I send messages from WinXP, there is no difference if I use any accessible Locale, including full Language Localization; nor is there a problem with English Locale. Important for correct encoding is only this code line:

msgId.characterSet = 1208;

Infortunately, it's not valid. There are differences in the case that I want to take the message from MQ Queue.

  • In the case that I get message from MQ Queue from Windows OS (English without any of Language Pack), I'm able to take message from MQ Queue in String form.

  • In the case that Windows OS is Full Localized with some of Language Pack, I am receiving an exception

Exception occured while to message buffer :
    java.io.UnsupportedEncodingException: Cp870 

from code (removed balast from try - catch - finally block)

try {
    Class.forName("com.ibm.mq.MQEnvironment");
    MQEnvironment.hostname = hostname;
    MQEnvironment.port = port1;
    MQEnvironment.channel = channel;
    MQEnvironment.userID = userID;
    MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
    try {
        qmgr1 = new MQQueueManager(qmanager);
        MQGetMessageOptions gmo = new MQGetMessageOptions();
        int openOptions2 = MQC.MQOO_INPUT_SHARED;
        gmo.options = MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
        gmo.options = MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
        gmo.options = MQC.MQGMO_WAIT; //Wait until message arrives
        gmo.waitInterval = 3000;
        getq = qmgr1.accessQueue(responseQueue, openOptions2);
        while (true) {
            try {
                responseFromQUEUE = "";
                MQMessage msgId = new MQMessage();
                //putmsg.characterSet = 437;// Set code page to ASCII
                //putmsg.characterSet = 1200;// Set code page to UNICODE
                msgId.characterSet = 1208;
                getq.get(msgId, gmo);
                String str = msgId.readLine();
                //responseFromQUEUE = CpConv.tf870to1250(msgId.readLine());
                //own EncodePage doesn't works too
                if (responseFromQUEUE.length() == 0) {
                    break;
                }
            } catch (MQException mqx) {
                if (mqx.reasonCode == EMPTY_QUEUE) {
                } else {
                }
            }
        }
    } catch (MQException mqx) {
    } finally {
    }
} catch (IOException ex) {
} catch (ClassNotFoundException e) {
}

please

  • is there some parameter(s), something that I miss there for take String from MQMessage#readLine()

  • my question here is only about String conversion,

  • I haven't any issue with Encode from MQMessage#getBytes

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1
    Any help [here](http://www-304.ibm.com/support/docview.wss?uid=swg1IZ86625)? – trashgod Jun 16 '12 at 13:45
  • thanks for link, but looks like [I have this issue](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4296969), no idea how is possible that one of end user PC haven't any problem another got UnsupportedEncodingException, no idea now – mKorbel Jun 16 '12 at 15:43
  • As @J-16 SDiZ noted, you are overwriting your Get Message Options so are not actually requesting conversion of the message payload. However, the message headers are always converted and that's where your error is coming from. That conversion is based on the CCSID setting of the QMgr, not the API call. What are the QMgrs CCSID's set to? – T.Rob Jul 01 '12 at 17:15
  • @T.Rob I haven't the RDP to AS400 :-), cant to check that, equivalent to the Windows cp1250 encode page :-) – mKorbel Jul 01 '12 at 17:53

2 Answers2

2

CP870 is EBCDIC host code page. To what locale are you changing the Windows to when the exception occurs? Do you still use msgId.characterSet = 1208; after the local is changed? It looks like Java libraries are unable to convert the incoming message that is in CP870 to your current locale.

Check what is the Windows code page when you change the locale and see if 1208 is correct for msgId.characterSet.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Shashi
  • 14,980
  • 2
  • 33
  • 52
  • +1 for answer, Locale haven't any issue, Language Pack (full language localization), please my question is where I found EBCDIC euqivalent to Windows Charsets (see my comment to @trashgod) – mKorbel Jun 17 '12 at 15:01
2
 gmo.options = MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
 gmo.options = MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
 gmo.options = MQC.MQGMO_WAIT; //Wait until message arrives

this code is wrong, you are overwriting the option, you need | them.

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
  • +1 for answer, please see my comments in this question, are you meaning `gmo.options = MQC.MQGMO_NO_SYNCPOINT | MQC.MQGMO_CONVERT | MQC.MQGMO_WAIT;` ???, my bad I'm using examples came from IBM package and docs – mKorbel Jun 17 '12 at 15:04
  • 1
    @mKorbel Which IBM package or docs have the errors above? And @J-16 SDiZ is correct about the syncpoint - you should ALWAYS use syncpoint when executing JMS API calls over the network. If you `GET` a message and the connection drops before it is delivered, then that message is irretrievably lost if not under syncpoint. If you do use syncpoint the worst you can get is message dupes. (The JMS spec calls messages that are redelivered due to session handling "functional duplicates" and it's because result of session failure on a `COMMIT` call is ambiguous.) Please use syncpoint and `COMMIT`! – T.Rob Jul 01 '12 at 17:10