简体   繁体   English

如何在jpos中为ascii channel和iso93ascii packager构建ISO8583消息头?

[英]how to construct ISO8583 message header for ascii channel and iso93ascii packager in jpos?

I am trying to create an ISO8583 message using JPOS in java using the ASCII channel to send the message and iso93ascii packager to pack the ISO message. 我试图在java中使用JPOS创建ISO8583消息,使用ASCII通道发送消息,使用iso93ascii打包程序打包ISO消息。

But after sending the message I am getting invalid header error from the server. 但是在发送消息后,我从服务器收到无效的头错误。

So my question is what is the header made up of exactly and how do I frame my header for MTI value 1200. 所以我的问题是什么是由完全组成的标题,以及如何为MTI值1200构建标题。

ISOMsg.setHeader("HEADER".getBytes());

How should I frame up my HEADER? 我应该如何构建我的HEADER?

New Development : 新发展:

After taking a look at the server configuration I need to send the header prepended by the length of the ISO8583 message(2 byte length in hex converted to bytes). 在查看服务器配置之后,我需要发送前面加上ISO8583消息长度的标头(以十六进制转换为字节的2字节长度)。 How can I do this using JPOS? 我怎么能用JPOS做到这一点? Also am not able to set anything using channel.setHeader("xxx").getBytes()) . 也无法使用channel.setHeader("xxx").getBytes())设置任何内容。

How do I see what raw message is being sent from my terminal to the server. 如何查看从终端向服务器发送的原始邮件。

Here are some of the excerpts from the code 以下是代码中的一些摘录

Deploy files 部署文件

filename : 10_clientsimualtor_channel.xml

<?xml version="1.0" ?>
<channel-adaptor name='jpos-client-adaptor'
    class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel class="org.jpos.iso.channel.ASCIIChannel" logger="Q2"
          packager="org.jpos.iso.packager.ISO93APackager" header= "ISO026000075">

  <property name="host" value="xxx.xx.xx.xx" />
  <property name="port" value="xxxxx" />
</channel>
<in>jpos-client-send</in>
<out>jpos-client-receive</out>
<reconnect-delay>10000</reconnect-delay>
</channel-adaptor>

Code : 代码:

packager = new ISO93APackager();

            ISOMsg m = new ISOMsg();
            m.setPackager(packager);
            System.out.println(packager);

            m.setHeader("ISO026000075".getBytes());
             System.out.println("Head err..........."+newString(m.getHeader()));

            Date now = new Date();

            m.setMTI("1200");
            m.set(2,"xx");
            m.set(3,"xxxxx");
            m.set(4,"000000010000");
            m.set(11,"214491");
            m.set(12,"160203");

            m.set(123, "xxxxxx");
            m.set(125, "xxxx");

           byte b[] = m.pack();
           System.out.println("\n\n\n\nPACKAGER =====------"+m.getPackager());
           System.out.printf("\n\n\n\nMessage ===== %s",new String(b));

            System.out.println("\n\n\n"+ISOUtil.hexdump(b));return m;

You can set your header at the channel level (ie channel.setHeader("xxx").getBytes()) or set it on a per-message level (ie m.setHeader("xxx".getBytes()) ). 您可以在通道级别设置标头(即channel.setHeader("xxx").getBytes())或在每个消息级别设置它(即m.setHeader("xxx".getBytes()) )。

It is important that the channel knows the header length at receive time, so even if you use per message header, you should set a dummy header at the channel level as well. 重要的是,通道在接收时知道标头长度,因此即使您使用每个消息标头,也应该在通道级别设置一个虚拟标头。

Using Q2 and the ChannelAdaptor or QServer components will make your life really easier. 使用Q2和ChannelAdaptor或QServer组件将使您的生活变得更加轻松。 Take a look at http://jpos.org/doc/proguide-draft.pdf 看看http://jpos.org/doc/proguide-draft.pdf

How do I see what raw message is being sent from my terminal to the server? 如何查看从终端向服务器发送的原始邮件?

The simplest way is to extend your channel and do an hexdump from its send and receive methods. 最简单的方法是扩展您的频道并从其发送和接收方法执行hexdump。

Here is a simple test code that will create a client and server, send and receive a message with a header. 这是一个简单的测试代码,它将创建一个客户端和服务器,发送和接收带有标头的消息。 You will see the output contains the header definition that was sent. 您将看到输出包含已发送的标头定义。 Once you get it this, moving it to the Q2 way of doing things via deploy should work. 一旦你明白这一点,通过部署将其转移到第二季度的工作方式应该有效。

Replace the packager to what you are using in the code. 将打包器替换为您在代码中使用的内容。 Make sure there is no header attribute in your packager xml. 确保packager xml中没有header属性。 Add the header to your client channel adapter deploy. 将标头添加到客户端通道适配器部署。

import java.io.IOException;

import org.jpos.iso.ISOChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISORequestListener;
import org.jpos.iso.ISOServer;
import org.jpos.iso.ISOSource;
import org.jpos.iso.ServerChannel;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.packager.GenericPackager;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;
import org.jpos.util.ThreadPool;

public class Test {

    public static void main(String[] args) throws IOException, ISOException {

        Logger l = new Logger();
        l.addListener(new SimpleLogListener());
        GenericPackager serverPkg = new GenericPackager(
                "C:\\temp\\iso93asciiB-custom.xml");
        serverPkg.setLogger(l, "Server"); // So that the output can be differentiated based on realm

        GenericPackager clientPkg = new GenericPackager(
                "C:\\temp\\iso93asciiB-custom.xml");
        clientPkg.setLogger(l, "Client");// So that the output can be differentiated based on realm
        // Simulate a server and listen on a port
        ISOChannel serverChannel = new ASCIIChannel(serverPkg);
        ((ASCIIChannel) serverChannel).setHeader("ISO70100000");
        // AN equivalent in your channel adaptor deploy file would be
        // <channel class="org.jpos.iso.channel.ASCIIChannel"
        // packager="org.jpos.iso.packager.GenericPackager"
        // header="ISO70100000"> .....
        // This is evident from the ChanelAdaptor code
        // QFactory.invoke (channel, "setHeader", e.getAttributeValue ("header"));
        ((ASCIIChannel) serverChannel).setLogger(l, "server");
        ISOServer server = new ISOServer(7654, (ServerChannel) serverChannel,
                new ThreadPool(10, 100, "serverListeningThread"));

        server.addISORequestListener(new ISORequestListener() {
            // If the client sends a message, the server will respond with and approval if its a request message
            @Override
            public boolean process(ISOSource source, ISOMsg msg) {
                try {
                    if (!msg.isRequest()) {
                        msg.setResponseMTI();
                        msg.set(39, "000");
                        source.send(msg);
                    }
                }
                catch (ISOException | IOException ex) {

                }

                return true;
            }
        });
        Thread serverThread = new Thread(server);
        serverThread.start(); // beyond this point the server is listening for a client connection

        ASCIIChannel clientChannel = new ASCIIChannel("127.0.0.1", 7654, clientPkg);
        clientChannel.setHeader("ISO70100000");​ //Similar to server, you can configure the constant in your deploy file​
        clientChannel.setLogger(l, "client");
        clientChannel.connect(); // connect to server, it will be seen in the output console
        ISOChannel connectChannel = server.getLastConnectedISOChannel();// Since server can have multiple connections,
                                                                        // we get the last one that connected to it.
        ISOMsg serverInitiatedRequest = new ISOMsg();

        serverInitiatedRequest.set(0, "1804");
        serverInitiatedRequest.set(7, "1607161705");
        serverInitiatedRequest.set(11, "888402");
        serverInitiatedRequest.set(12, "160716170549");
        serverInitiatedRequest.set(24, "803");
        serverInitiatedRequest.set(25, "0000");
        serverInitiatedRequest.set(33, "101010");
        serverInitiatedRequest.set(37, "619817888402");

        connectChannel.send(serverInitiatedRequest); // use the last one connected to send a request message to the client.
        ISOMsg receivedRequest = clientChannel.receive();// receive the serers request message at the client

        ISOMsg clientResponse = (ISOMsg) receivedRequest.clone();
        clientResponse.setResponseMTI();
        clientResponse.set(39, "000");
        clientChannel.send(clientResponse); // send the response to server

    }

}

Your output should look like 你的输出应该是这样的

<log realm="client/127.0.0.1:7654" at="Sun Jul 17 12:31:55 IST 2016.764" lifespan="33ms">
  <connect>
    127.0.0.1:7654
  </connect>
</log>
<log realm="Server" at="Sun Jul 17 12:31:55 IST 2016.784" lifespan="4ms">
  <pack>
    31383034023001808800000031363037313631373035383838343032313630373136313730353439383033303030303036313031303130363139383137383838343032
  </pack>
</log>
<log realm="server/127.0.0.1:10614" at="Sun Jul 17 12:31:55 IST 2016.785" lifespan="7ms">
  <send>
    <isomsg direction="outgoing">
      <!-- org.jpos.iso.packager.GenericPackager[C:\temp\iso93asciiB-custom.xml] -->
      <field id="0" value="1804"/>
      <field id="7" value="1607161705"/>
      <field id="11" value="888402"/>
      <field id="12" value="160716170549"/>
      <field id="24" value="803"/>
      <field id="25" value="0000"/>
      <field id="33" value="101010"/>
      <field id="37" value="619817888402"/>
    </isomsg>
  </send>
</log>
<log realm="Client" at="Sun Jul 17 12:31:55 IST 2016.787" lifespan="1ms">
  <unpack>
    31383034023001808800000031363037313631373035383838343032313630373136313730353439383033303030303036313031303130363139383137383838343032
    <bitmap>{7, 11, 12, 24, 25, 33, 37}</bitmap>
    <unpack fld="7" packager="org.jpos.iso.IFA_NUMERIC">
      <value>1607161705</value>
    </unpack>
    <unpack fld="11" packager="org.jpos.iso.IFA_NUMERIC">
      <value>888402</value>
    </unpack>
    <unpack fld="12" packager="org.jpos.iso.IFA_NUMERIC">
      <value>160716170549</value>
    </unpack>
    <unpack fld="24" packager="org.jpos.iso.IFA_NUMERIC">
      <value>803</value>
    </unpack>
    <unpack fld="25" packager="org.jpos.iso.IFA_NUMERIC">
      <value>0000</value>
    </unpack>
    <unpack fld="33" packager="org.jpos.iso.IFA_LLNUM">
      <value>101010</value>
    </unpack>
    <unpack fld="37" packager="org.jpos.iso.IF_CHAR">
      <value>619817888402</value>
    </unpack>
  </unpack>
</log>
<log realm="client/127.0.0.1:7654" at="Sun Jul 17 12:31:55 IST 2016.789" lifespan="4ms">
  <receive>
    <isomsg direction="incoming">
      <!-- org.jpos.iso.packager.GenericPackager[C:\temp\iso93asciiB-custom.xml] -->
      <header>49534F3730313030303030</header>
      <field id="0" value="1804"/>
      <field id="7" value="1607161705"/>
      <field id="11" value="888402"/>
      <field id="12" value="160716170549"/>
      <field id="24" value="803"/>
      <field id="25" value="0000"/>
      <field id="33" value="101010"/>
      <field id="37" value="619817888402"/>
    </isomsg>
  </receive>
</log>
<log realm="Client" at="Sun Jul 17 12:31:55 IST 2016.791">
  <pack>
    31383134023001808A00000031363037313631373035383838343032313630373136313730353439383033303030303036313031303130363139383137383838343032303030
  </pack>
</log>
<log realm="Server" at="Sun Jul 17 12:31:55 IST 2016.791">
  <unpack>
    31383134023001808A00000031363037313631373035383838343032313630373136313730353439383033303030303036313031303130363139383137383838343032303030
    <bitmap>{7, 11, 12, 24, 25, 33, 37, 39}</bitmap>
    <unpack fld="7" packager="org.jpos.iso.IFA_NUMERIC">
      <value>1607161705</value>
    </unpack>
    <unpack fld="11" packager="org.jpos.iso.IFA_NUMERIC">
      <value>888402</value>
    </unpack>
    <unpack fld="12" packager="org.jpos.iso.IFA_NUMERIC">
      <value>160716170549</value>
    </unpack>
    <unpack fld="24" packager="org.jpos.iso.IFA_NUMERIC">
      <value>803</value>
    </unpack>
    <unpack fld="25" packager="org.jpos.iso.IFA_NUMERIC">
      <value>0000</value>
    </unpack>
    <unpack fld="33" packager="org.jpos.iso.IFA_LLNUM">
      <value>101010</value>
    </unpack>
    <unpack fld="37" packager="org.jpos.iso.IF_CHAR">
      <value>619817888402</value>
    </unpack>
    <unpack fld="39" packager="org.jpos.iso.IFA_NUMERIC">
      <value>000</value>
    </unpack>
  </unpack>
</log>
<log realm="server/127.0.0.1:10614" at="Sun Jul 17 12:31:55 IST 2016.792" lifespan="26ms">
  <receive>
    <isomsg direction="incoming">
      <!-- org.jpos.iso.packager.GenericPackager[C:\temp\iso93asciiB-custom.xml] -->
      <header>49534F3730313030303030</header>
      <field id="0" value="1814"/>
      <field id="7" value="1607161705"/>
      <field id="11" value="888402"/>
      <field id="12" value="160716170549"/>
      <field id="24" value="803"/>
      <field id="25" value="0000"/>
      <field id="33" value="101010"/>
      <field id="37" value="619817888402"/>
      <field id="39" value="000"/>
    </isomsg>
  </receive>
</log>
<log realm="client/127.0.0.1:7654" at="Sun Jul 17 12:31:55 IST 2016.793" lifespan="3ms">
  <send>
    <isomsg direction="outgoing">
      <!-- org.jpos.iso.packager.GenericPackager[C:\temp\iso93asciiB-custom.xml] -->
      <header>49534F3730313030303030</header>
      <field id="0" value="1814"/>
      <field id="7" value="1607161705"/>
      <field id="11" value="888402"/>
      <field id="12" value="160716170549"/>
      <field id="24" value="803"/>
      <field id="25" value="0000"/>
      <field id="33" value="101010"/>
      <field id="37" value="619817888402"/>
      <field id="39" value="000"/>
    </isomsg>
  </send>
</log>

from jpos you will get only hexdump of header.in order to send ascii93 version you need to convert hexdump to bytes and then bits. 从jpos你只会获得headerdu的hexdump。为了发送ascii93版本你需要将hexdump转换为字节然后位。

https://github.com/vikrantlabde/iso8583-Java/blob/master/src/ISO/iso8583.java https://github.com/vikrantlabde/iso8583-Java/blob/master/src/ISO/iso8583.java

you can use this program to pack and send isoascii93 message 您可以使用此程序打包并发送isoascii93消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM