Question

So im sending a message to WebSphere and its successfully putting it on a queue. However I have having an issue getting it off another queue. But what I have noticed it when im sending me message using the line :

inputMessage.writeUTF(message); with the message being:

basket/argos/1001?authToken=fgTSdfs&trustToken=gdf43FsfSFefs33&apiKey=ahjd9234imnmdfnwi&sig=abcde&currency=GBP

which is store in an xml file, it is appending a "n" to the front of the message. Can anyone tell me why? the code is below:

  MQQueueConnectionFactory cf = new MQQueueConnectionFactory();

    // Config
    cf.setHostName(hostname);
    cf.setPort(portNumber);
    cf.setQueueManager(queueManager);
    cf.setChannel(channel);

    //MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
    //MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    //MQQueue queue = (MQQueue) session.createQueue(inputQueue);
    //MQQueue queue = (MQQueue)session.
    //MQQueueSender sender =  (MQQueueSender) session.createSender(queue);
    //MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);    


    MQQueueManager qMgr = new MQQueueManager(queueManager);
    System.out.println("Queue manager created");

    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |  
    MQC.MQOO_OUTPUT ;  
    System.out.println("MQ Options created");

    MQQueue mqInputQueue =  
        qMgr.accessQueue(inputQueue,  
                openOptions);

    System.out.println("Queue created");

    MQMessage inputMessage = new MQMessage();
    inputMessage.writeUTF(message);
    System.out.println("message created and sent");

    MQPutMessageOptions pmo = new MQPutMessageOptions();  // accept the defaults,  
    // same as  
    // MQPMO_DEFAULT  
    // constant  
    System.out.println("Queue options created");

    // put the message on the queue  
    mqInputQueue.put(inputMessage,pmo);
    System.out.println("Message put on queue");
    mqInputQueue.close();  
Était-ce utile?

La solution

It appears that MQMessage derives from DataInput and DataOutput. I am guessing that writeUTF is doing the same thing as in DataOutputStream.

You can reference this Answer for help Why does DataOutputStream.writeUTF() add additional 2 bytes at the beginning?

You have a few options:

inputMessage.write(message.getBytes("UTF-8"));

or probably

inputMessage.writeString(message);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top