JAVA到EBCIDIC的转换未发生 [英] JAVA to EBCIDIC Conversion is not happening

查看:116
本文介绍了JAVA到EBCIDIC的转换未发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一个应用程序中获取数据,并在处理完数据后将其发送到另一个(大型机).

假设我获取的数据为这是从另一个应用程序来的",处理方式和处理状态与此数据已处理".最终消息应结合使用两种编码(Cp1047)到大型机应用程序,以与

I am trying to get data from one application and send that to another(mainframe) after processing the data.

Lets assume I am getting data as "This is from another application", processed the same and processing status as "This data is processed". Final message should be combination of both using encoding(Cp1047) to mainframe application to read the same as

0024 这是来自另一个应用程序 001A 该数据已处理

0024This is from another application001AThis data is processed


0024的十进制值为36(消息长度+ 4,即十六进制值长度)
001A的十进制值为26(已处理消息长度+ 4)

我的应用程序在Java8上运行,并使用Websphere MQ.我需要将数据发送到从Mainframe MQ接收数据的应用程序. WebSphere MQ中的远程队列将消息放入大型机MQ的本地队列.我的以下代码用于转换数据并使用Cp1047进行编码,


decimal value of 0024 is 36 (message length + 4 which is hexa value length)
decimal value of 001A is 26 (processed message length + 4)

My application runs on Java8 and uses websphere MQ. I need to send data to application which receives data from Mainframe MQ. Remote queue in WebSphere MQ puts messge to Local Queue of Mainframe MQ. My code as below to convert data and encode using Cp1047,

String incomingData = "This is from another application";
String processingData = "This data is processed" 
public String outGoingData(String incomingData, String processingData) {  
  StringBuilder strBuilder = new StringBuilder();
  return stringbuilder.append(new String(convertToEbcidie(incomingData, "Cp1047")))
  .append(incomingData)
  .append(new String(convertToEbcidie(processingData, "Cp1047")))
  .append(processing data).toString(); //playing this string to queue
}
private byte[] convertToEbcidic(String s) {
  String hexStr = StringUtils.leftPad(s.length+4, 8, "0");
  byte[] byteAry = new byte[hexStr.length()/2];
  for (int i = 0; i < hexStr.length(); i+=2) {
    byteAry[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                   + Character.digit(s.charAt(i+1), 16)); 
  }  return byteAry;
}

接收器应用程序(大型机)确定哪个是原始消息,并基于状态(基于4个字符的六值)进行处理. 他们能够阅读大部分邮件,但不能全部阅读.例如,长度805的六进制值为325,但在大型机mq条目中为315.由于长度不匹配,它们无法处理.

Receiver application(mainframe) decide which is original message and processing status based hexavalue which is 4 characters. They are able to read most of the messages but not all. for ex, hexa value of length 805 is 325, but in mainframe mq entry is as 315. They are not able to process since the length mismatches.

另一个样本数据: OO25 这是来自源的原始数据 001A 已成功完成

ANOTHER SAMPLE DATA :- OO25THIS IS ORIGINAL DATA FROM SOURCE001APROCESSED SUCCESSFULLY


0025是组织msg长度(33)+ 4的十六进制值,而001A是已处理msg长度(22)+ 4的十六进制值.这里4是十六进制值的长度.


0025 is hexval of org msg length(33) + 4 and 001A is hexval of processed msg length (22) + 4. Here 4 is the length of hexa decimal value.
Am I missing any logic to convert to ebcidic?

推荐答案

您发布的代码有很多错误,我不知道从哪里开始.

There is so much wrong with the code you posted, I don't know where to begin.

首先,StackOverflow规则/策略是您应该复制&将您的 工作代码 从您的编辑器或IDE中粘贴到StackOverflow.显然,您没有这样做,而只是在StackOverflow编辑窗口中创建了新代码-这是错误的!!

First off, StackOverflow rules/policy is that you are supposed to copy & paste your working code from your editor or IDE to StackOverflow. Clearly, you did not do that but rather just created new code in the StackOverflow edit window - which is wrong!!!

return stringbuilder.append(new String(convertToEbcidie(incomingData, "Cp1047")))
  .append(incomingData)
  .append(new String(convertToEbcidie(processingData, "Cp1047")))
  .append(processing data).toString();

(1)convertToEbcidic方法使用一个参数而不是2.您的括号错误.

(1) The convertToEbcidic method takes ONE parameter and not 2. You have your bracketing wrong.

(2)方法名是convertToEbcidic而不是convertToEbcidie(最后一个字母是'c'而不是'e')

(2) The method name is convertToEbcidic and not convertToEbcidie (last letter is 'c' not 'e')

private byte[] convertToEbcidic(String s) {
  String hexStr = StringUtils.leftPad(s.length+4, 8, "0");
  byte[] byteAry = new byte[hexStr.length()/2];
  for (int i = 0; i < hexStr.length(); i+=2) {
    byteAry[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                   + Character.digit(s.charAt(i+1), 16)); 
  }  return byteAry;
}

(3)我不知道您想做什么,但是很明显,它没有做您想做的任何事情.您是否通过调试器逐步完成了代码?

(3) I have no clue what you are trying to do but clearly it is not doing anything you think it is. Did you step through the code with a debugger?

(3A)s变量的长度是方法而不是字段.应该是"s.length()",而不是"s.length".

(3A) The length for s variable is a method not a field. It should be "s.length()" and not "s.length".

(3B)StringUtils.leftPad方法的第一个参数必须是String而不是int.

(3B) StringUtils.leftPad method's first parameter must be a String and not an int.

(3C)hexStr将为"00000036"(32 + 4). hexStr的长度为8.

(3C) hexStr will be "00000036" (32 + 4). hexStr has a length of 8.

(3D)byteAry的大小为4 !!!您如何将36个字符装入4个字节?即4 + 26个字符这是来自另一个应用程序".

(3D) byteAry will have a size of 4!!! How are you suppose to fit 36 characters into 4 bytes? i.e. 4 + 26 characters "This is from another application".

(3E)您的循环在做什么?它运行了4次,我完全不知道您在想什么.

(3E) What is your loop doing?? It runs 4 times and I have absolutely no idea what you were thinking.

好的.现在解决您的问题.

Ok. Now to your problem.

ANOTHER SAMPLE DATA :- OO25THIS IS ORIGINAL DATA FROM SOURCE001APROCESSED SUCCESSFULLY

好的.因此,基于该示例,在我看来布局如下:

Ok. So based on that sample, it appears to me that the layout is as following:

{十六进制的字符数据1"的长度的字符串表示形式} {字符数据1} {十六进制的字符数据2"的长度的字符串表示形式} {字符数据2}

{string representation of length of "character data 1" in hex}{character data 1}{string representation of length of "character data 2" in hex}{character data 2}

因为,整个消息有效负载将是字符串,所以将字符串作为消息放入本地代码页(ASCII)中要好得多,将MQMD格式标记为字符串,然后让MQ进行转换.当大型机应用程序发出带有Convert的MQGET"调用时,将完成转换.

Since, the entire message payload will be string then it is far, far better to put the string as a message in the local codepage (ASCII), mark the MQMD format as string and let MQ do the conversion. The conversion will be done when the mainframe application issues an "MQGET with Convert" call.

以下是解决您问题的正确代码:

Here is the proper code to your problem:

String incomingData = "This is from another application";
String processingData = "This data is processed";
StringBuilder sb = new StringBuilder();
MQQueueManager qMgr = null;
MQQueue outQ = null;

String inHexLen = Integer.toHexString(incomingData.length()+4).toUpperCase();
inHexLen = StringUtils.leftPad(inHexLen, 4, '0');
sb.append(inHexLen);
sb.append(incomingData);

String outHexLen = Integer.toHexString(processingData.length()+4).toUpperCase();
outHexLen = StringUtils.leftPad(outHexLen, 4, '0');
sb.append(outHexLen);
sb.append(processingData);

System.out.println("sb="+sb.toString());

try
{
   qMgr = new MQQueueManager("MQA1");

   outQ = qMgr.accessQueue("TEST.Q1",
                           CMQC.MQOO_OUTPUT + CMQC.MQOO_FAIL_IF_QUIESCING);

   MQMessage sendmsg = new MQMessage();
   sendmsg.format = CMQC.MQFMT_STRING;
   sendmsg.writeString(sb.toString());
   outQ.put(sendmsg, new MQPutMessageOptions());
}
catch (MQException e)
{
   e.printStackTrace();
}
catch (IOException e)
{
   e.printStackTrace();
}
finally
{
   try
   {
      if (outQ != null)
         outQ.close();
   }
   catch (MQException e)
   {
      e.printStackTrace();
   }
   try
   {
      if (qMgr != null)
         qMgr.disconnect();
   }
   catch (MQException e)
   {
      e.printStackTrace();
   }
}

这篇关于JAVA到EBCIDIC的转换未发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆