Simple jPOS Server Example in Java: The point of sale (POS)  is the time and place where a retail transaction is done. At the point of sale, the merchant calculates the amount owed by the Customer, indicates that amount, may prepare an invoice for the customer (which may be a cash register printout), and indicates the options for the customer to make payment.

It is also the point at which a customer makes a payment to the merchant in exchange for goods or after the provision of a service.

After receiving payment, the merchant may issue a receipt for the transaction, which is usually printed but can also be dispensed with or sent electronically.

Simple jPOS Server Example in Java

JPOS Technology is the point of sale framework that is designed in Java programming language and also for universal messaging format for financial transactions with card vendors using ISO 8583 standards. this framework involves in acquires details from customers & passing data to respective card/bank vendors.

It holds sensitive data required for payment like

  • Card Number
  • PIN
  • Password
  • PAN Number
  • Card’s Expiry Date
  • CVV
  • Name of the Customer, etc.,

How is the POS framework communicated?

It will send & receive messages using the base protocol which is TCP. when a customer starts payment in the POS machine request data will be sent in binary or hex decimal as we choose while developing the pos machine software.

To ensure security pos machine will encrypt sensitive data using a private key that is only readable by the machine and Server. During the first handshake between servers from the POS machine, it will share key information with the server to use for further transactions.


Now we will see how to create a simple Java POS server to accept messages from the client

  • Create a maven project and below dependency
 <dependency>
   <groupId>org.jpos</groupId>
   <artifactId>jpos</artifactId>
   <version>2.1.7</version>
</dependency> 

By adding the JPOS jar file we can add all required JPOS classes to our project

  • Next, we need to create a package and create a Class as Below

package com.taskincomplete.jpos;
import java.io.IOException;

import org.jpos.iso.BaseChannel;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOPackager;
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;

public class MockISO8583Server implements ISORequestListener {

public static void main(String[] args) throws ISOException {
String hostname = "localhost";
int portNumber = 5000;

ISOPackager packager = new GenericPackager("CustomConfig.xml");
ServerChannel channel = new ASCIIChannel(hostname, portNumber, packager);

ISOServer server = new ISOServer(portNumber, channel, null);

server.addISORequestListener(new MockISO8583Server());

System.out.println("ISO8583 server started...");
new Thread(server).start();

}

public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
try {
System.out.println("ISO8583 incoming message on host ["
+ ((BaseChannel) isoSrc).getSocket().getInetAddress()
.getHostAddress() + "]");
receiveMessage(isoSrc, isoMsg);
logISOMsg(isoMsg);
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}

private void receiveMessage(ISOSource isoSrc, ISOMsg isoMsg)
throws ISOException, IOException {
System.out.println("ISO8583 Message received...");
ISOMsg reply = (ISOMsg) isoMsg.clone();

reply.setMTI("0210");
reply.set(39, "00");

isoSrc.send(reply);
}

private static void logISOMsg(ISOMsg msg) {
System.out.println("----ISO MESSAGE-----");
try {
System.out.println(" MTI : " + msg.getMTI());
for (int i = 1; i &lt;= msg.getMaxField(); i++) {
if (msg.hasField(i)) {
System.out.println(" Field-" + i + " : "
+ msg.getString(i));
}
}
} catch (ISOException e) {
e.printStackTrace();
} finally {
System.out.println("--------------------");
}

}

}

String hostname = "localhost";
int portNumber = 5000;

above two lines of code, we are setting host &port to start the server

In the below code we declare the ISO packager with fields configurations in the config file called “CustomConfig.xml”

 ISOPackager packager = new GenericPackager("CustomConfig.xml");

below code will assign server config details to ServerChannel

ServerChannel channel = new ASCIIChannel(hostname, portNumber, packager);

we have multiple channel objects ASCII, BCDChannel, NACC Channel, etc

Below code is used to initialize the Server object with the channel, port

ISOServer server = new ISOServer(portNumber, channel, null);
new Thread(server).start();

The above code will start the actual server & whenever a new message is received it will enter into the process method

Now we have added below config file content with the name “CustomConfig.xml” to the root folder of your project

</pre>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE isopackager SYSTEM "genericpackager.dtd">

<!-- ISO 8583:1987 (BINARY) field descriptions for GenericPackager -->

<isopackager>
<isofield
id="0"
length="4"
name="MESSAGE TYPE INDICATOR"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="1"
length="16"
name="BIT MAP"
class="org.jpos.iso.IFB_BITMAP"/>
<isofield
id="2"
length="18"
name="PAN - PRIMARY ACCOUNT NUMBER"
pad="false"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="3"
length="6"
name="PROCESSING CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="4"
length="12"
name="AMOUNT, TRANSACTION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="5"
length="12"
name="AMOUNT, SETTLEMENT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="6"
length="12"
name="AMOUNT, CARDHOLDER BILLING"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="7"
length="10"
name="TRANSMISSION DATE AND TIME"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="8"
length="8"
name="AMOUNT, CARDHOLDER BILLING FEE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="9"
length="8"
name="CONVERSION RATE, SETTLEMENT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="10"
length="8"
name="CONVERSION RATE, CARDHOLDER BILLING"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="11"
length="6"
name="SYSTEM TRACE AUDIT NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="12"
length="6"
name="TIME, LOCAL TRANSACTION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="13"
length="4"
name="DATE, LOCAL TRANSACTION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="14"
length="4"
name="DATE, EXPIRATION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="15"
length="4"
name="DATE, SETTLEMENT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="16"
length="4"
name="DATE, CONVERSION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="17"
length="4"
name="DATE, CAPTURE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="18"
length="4"
name="MERCHANTS TYPE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="19"
length="3"
name="ACQUIRING INSTITUTION COUNTRY CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="20"
length="3"
name="PAN EXTENDED COUNTRY CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="21"
length="3"
name="FORWARDING INSTITUTION COUNTRY CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="22"

length="4"
name="POINT OF SERVICE ENTRY MODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>

<isofield
id="23"
length="3"
name="CARD SEQUENCE NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="24"
length="4"
name="NETWORK INTERNATIONAL IDENTIFIEER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>

<isofield
id="25"
length="2"
name="POINT OF SERVICE CONDITION CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="26"
length="2"
name="POINT OF SERVICE PIN CAPTURE CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="27"
length="1"
name="AUTHORIZATION IDENTIFICATION RESP LEN"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="28"
length="9"
name="AMOUNT, TRANSACTION FEE"
pad="true"
class="org.jpos.iso.IFB_AMOUNT"/>
<isofield
id="29"
length="9"
name="AMOUNT, SETTLEMENT FEE"
pad="true"
class="org.jpos.iso.IFB_AMOUNT"/>
<isofield
id="30"
length="9"
name="AMOUNT, TRANSACTION PROCESSING FEE"
pad="true"
class="org.jpos.iso.IFB_AMOUNT"/>
<isofield
id="31"
length="9"
name="AMOUNT, SETTLEMENT PROCESSING FEE"
pad="true"
class="org.jpos.iso.IFB_AMOUNT"/>
<isofield
id="32"
length="11"
name="ACQUIRING INSTITUTION IDENT CODE"
pad="false"
class="org.jpos.iso.IFB_LLNUM"/>
<isofield
id="33"
length="11"
name="FORWARDING INSTITUTION IDENT CODE"
pad="false"
class="org.jpos.iso.IFB_LLNUM"/>
<isofield
id="34"
length="28"
name="PAN EXTENDED"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="35"

length="40"
name="TRACK 2 DATA"
pad="true"
class="org.jpos.iso.IFB_LLNUM"/>

<isofield
id="36"
length="104"
name="TRACK 3 DATA"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="37"
length="12"

name="RETRIEVAL REFERENCE NUMBER"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="38"
length="6"
name="AUTHORIZATION IDENTIFICATION RESPONSE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="39"
length="2"
name="RESPONSE CODE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="40"
length="3"
name="SERVICE RESTRICTION CODE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="41"
length="8"
name="CARD ACCEPTOR TERMINAL IDENTIFICACION"
class="org.jpos.iso.IFA_NUMERIC"/>
<isofield
id="42"
length="15"
name="CARD ACCEPTOR IDENTIFICATION CODE"
pad="false"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="43"
length="40"
name="CARD ACCEPTOR NAME/LOCATION"
class="org.jpos.iso.IF_CHAR"/>

&nbsp;

&nbsp;

&nbsp;

&nbsp;

<isofield
id="44"
length="25"
name="ADITIONAL RESPONSE DATA"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="45"
length="76"
name="TRACK 1 DATA"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="46"
length="999"
name="ADITIONAL DATA - ISO"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="47"
length="999"
name="ADITIONAL DATA - NATIONAL"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="48"
length="999"
name="ADITIONAL DATA - PRIVATE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="49"
length="3"
name="CURRENCY CODE, TRANSACTION"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="50"
length="3"
name="CURRENCY CODE, SETTLEMENT"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="51"
length="3"
name="CURRENCY CODE, CARDHOLDER BILLING"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="52"
length="8"
name="PIN DATA"
class="org.jpos.iso.IFB_LLNUM"/>
<isofield
id="53"
length="16"
name="SECURITY RELATED CONTROL INFORMATION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="54"
length="12"
name="ADDITIONAL AMOUNTS"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="55"
length="133"
name="RESERVED ISO"
class="org.jpos.iso.IFB_BINARY"/>
<isofield
id="56"
length="999"
name="RESERVED ISO"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="57"
length="999"
name="RESERVED NATIONAL"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="58"
length="999"
name="RESERVED NATIONAL"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="59"
length="999"
name="RESERVED NATIONAL"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="60"
length="12"
name="RESERVED PRIVATE"
pad="true"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="61"
length="999"
name="RESERVED PRIVATE"
class="org.jpos.iso.IFB_LLLCHAR"/>

<isofield
id="62"
length="6"
name="INVOICE NUMBER"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="63"
length="999"
name="RESERVED PRIVATE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="64"
length="8"
name="MESSAGE AUTHENTICATION CODE FIELD"
class="org.jpos.iso.IFB_BINARY"/>
<isofield
id="65"
length="1"
name="BITMAP, EXTENDED"
class="org.jpos.iso.IFB_BINARY"/>
<isofield
id="66"
length="1"
name="SETTLEMENT CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="67"
length="2"
name="EXTENDED PAYMENT CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="68"
length="3"
name="RECEIVING INSTITUTION COUNTRY CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="69"
length="3"
name="SETTLEMENT INSTITUTION COUNTRY CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="70"
length="3"
name="NETWORK MANAGEMENT INFORMATION CODE"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="71"
length="4"
name="MESSAGE NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="72"
length="4"
name="MESSAGE NUMBER LAST"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="73"
length="6"
name="DATE ACTION"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="74"
length="10"
name="CREDITS NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="75"
length="10"
name="CREDITS REVERSAL NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="76"
length="10"
name="DEBITS NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="77"
length="10"
name="DEBITS REVERSAL NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="78"
length="10"
name="TRANSFER NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="79"
length="10"
name="TRANSFER REVERSAL NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="80"
length="10"
name="INQUIRIES NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="81"
length="10"
name="AUTHORIZATION NUMBER"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="82"
length="12"
name="CREDITS, PROCESSING FEE AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="83"
length="12"
name="CREDITS, TRANSACTION FEE AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="84"
length="12"
name="DEBITS, PROCESSING FEE AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="85"
length="12"
name="DEBITS, TRANSACTION FEE AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="86"
length="16"
name="CREDITS, AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="87"
length="16"
name="CREDITS, REVERSAL AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="88"
length="16"
name="DEBITS, AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="89"
length="16"
name="DEBITS, REVERSAL AMOUNT"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="90"
length="42"
name="ORIGINAL DATA ELEMENTS"
pad="true"
class="org.jpos.iso.IFB_NUMERIC"/>
<isofield
id="91"
length="1"
name="FILE UPDATE CODE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="92"
length="2"
name="FILE SECURITY CODE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="93"
length="6"
name="RESPONSE INDICATOR"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="94"
length="7"
name="SERVICE INDICATOR"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="95"
length="42"
name="REPLACEMENT AMOUNTS"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="96"
length="16"
name="MESSAGE SECURITY CODE"
class="org.jpos.iso.IFB_BINARY"/>
<isofield
id="97"
length="17"
name="AMOUNT, NET SETTLEMENT"
pad="false"
class="org.jpos.iso.IFB_AMOUNT"/>
<isofield
id="98"
length="25"
name="PAYEE"
class="org.jpos.iso.IF_CHAR"/>
<isofield
id="99"
length="11"
name="SETTLEMENT INSTITUTION IDENT CODE"
pad="false"
class="org.jpos.iso.IFB_LLNUM"/>
<isofield
id="100"
length="11"
name="RECEIVING INSTITUTION IDENT CODE"
pad="false"
class="org.jpos.iso.IFB_LLNUM"/>
<isofield
id="101"
length="17"
name="FILE NAME"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="102"
length="28"
name="ACCOUNT IDENTIFICATION 1"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="103"
length="28"
name="ACCOUNT IDENTIFICATION 2"
class="org.jpos.iso.IFB_LLCHAR"/>
<isofield
id="104"
length="100"
name="TRANSACTION DESCRIPTION"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="105"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="106"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="107"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="108"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="109"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="110"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="111"
length="999"
name="RESERVED ISO USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="112"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="113"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="114"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="115"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="116"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="117"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="118"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="119"
length="999"
name="RESERVED NATIONAL USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="120"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="121"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="122"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="123"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="124"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="125"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="126"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="127"
length="999"
name="RESERVED PRIVATE USE"
class="org.jpos.iso.IFB_LLLCHAR"/>
<isofield
id="128"
length="8"
name="MAC 2"
class="org.jpos.iso.IFB_BINARY"/>
</isopackager>
<pre>

and dependency genericpackager.dtd file to the same folder attached here

if we are sure that jar and dependencies files are added to your project we can run the server.

The server will start if you don’t see any errors.

to send a sample message we can use the below code to the server

package com.taskincomplete.jpos;
import java.io.IOException;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.channel.NACChannel;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.channel.BCDChannel;
import org.jpos.iso.packager.GenericPackager;
import org.jpos.iso.packager.PostPackager;

public class SampleRequest {

public static void main(String[] args) throws IOException, ISOException {
// Create Packager based on XML that contain DE type
GenericPackager packager = new GenericPackager("CustomConfig.xml");

// Create ISO Message
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
//isoMsg.setHeader("6003560000".getBytes());
isoMsg.setMTI("0200");
isoMsg.set(2, "327A1DE46B9F0C123");
isoMsg.set(3, "020000");
isoMsg.set(4, "000000056555");
isoMsg.set(11, "000005");
isoMsg.set(12, "112609");
isoMsg.set(13, "0202");
isoMsg.set(14, "1611");

isoMsg.set(22, "0051");
isoMsg.set(24, "0356");
isoMsg.set(25, "00");
isoMsg.set(37, "503305560001");
isoMsg.set(38, "509487");

isoMsg.set(41, "24312329");
isoMsg.set(42, "037022000042125");

isoMsg.set(54, "000000001000");
isoMsg.set(55, "013182027C00950500800480009A031502029C01005F2A0203565F3401009F02060000000555559F03060000000000009F0902008C9F100706010A03A020029F1A0203569F1E08534349464D5836359F260842D82C543F5CE2D39F2701809F3303E0F0C89F34030203009F3501229F3602002B9F3704DD87A06D9F4104000000059F530152");
isoMsg.set(60, "001200005555");
isoMsg.set(62, "000602");
ASCIIChannel c = new ASCIIChannel("localhost", 5000, packager);
logISOMsg(isoMsg);
System.out.println(ISOUtil.hexdump(isoMsg.pack()));
c.connect();
c.send(isoMsg);
ISOMsg response = c.receive();
System.out.println("****************Response *********************");
logISOMsg(response);
// Get and print the output result

}

private static void logISOMsg(ISOMsg msg) {
System.out.println("----ISO MESSAGE-----");
try {
System.out.println(" MTI : " + msg.getMTI());
for (int i = 1; i <= msg.getMaxField(); i++) {
if (msg.hasField(i)) {
System.out.println(" Field-" + i + " : "
+ msg.getString(i));
}
}
} catch (ISOException e) {
e.printStackTrace();
} finally {
System.out.println("--------------------");
}

}

}

Now both server and client code try to run and test in your local
for complete source code jposServer

Happy Learning

Simple jPOS Server Example in Java

Leave a Reply

Your email address will not be published. Required fields are marked *