Results 1 to 3 of 3

Thread: Need to convert incoming JMS messages from EBCDIC encoding to ASCII

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    16

    Default Need to convert incoming JMS messages from EBCDIC encoding to ASCII

    Hello,

    I am using Spring JMS to receive messages from a WebSphere MQ queue. The problem with these messages is that they are all being sent by an IBM mainframe which has encoded them all in EBCDIC format. How can I convert the incoming messages back into ASCII or some other encoding that I can read and use ? Can I leverage some kind of MessageConverter or is it more complicated?

    Thanks,

    Brad

  2. #2

    Default

    When you get a message in your MDB, a message from a distributed platform will be of type TextMessage. Messages sent from legacy platforms will most likely be of type BytesMessage. This is the code we use in production (change your codepage to suit):

    Code:
    	if (msg instanceof BytesMessage){
    		final String theMessage = MDBHelper.codepagePreProcess((BytesMessage)msg,MDBHelper.CP1047_CODEPAGE,MDBHelper.MESSAGE_BUFFER);
    		manager.process(theMessage);
    					
    										
    	}else if (msg instanceof TextMessage){
    		final TextMessage message = (TextMessage) msg;
    		manager.process(message.getText());
    					
    	}else {
    		//send SNMP error
            }
    }
    Code:
    public static String codepagePreProcess(BytesMessage bytesMsg, String codePage, int bufferSize) throws Exception{
    		byte[] buffer = new byte[bufferSize];
    		byte[] body = new byte[0];
    		while (true){
    			int numBytesRead = bytesMsg.readBytes(buffer);
    			if (numBytesRead == -1){
    				break;
    			}
    			byte[] tmp = new byte[body.length + numBytesRead];
    			System.arraycopy(body,0,tmp,0,body.length);
    			System.arraycopy(buffer,0,tmp,body.length,numBytesRead);
    			body = tmp;
    		} //end while    
    		return new String(body,codePage);
    
    	}
    Code:
    public final static String CP1047_CODEPAGE = "Cp1047";
    public final static int MESSAGE_BUFFER = 10000;
    Please be aware that IBM MQ itself has mechanisms to do this transformation, but for other reasons we prefer to do it in code.

  3. #3
    Join Date
    Jan 2012
    Posts
    1

    Default

    The code works really well...but I'm wondering what IBM MQ has to do the transformation. Does anyone know?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •