50% found this document useful (2 votes)
424 views7 pages

ISO 8583 with JPOS and Log4J in Java

This document provides an overview and instructions for setting up a Java application that uses ISO 8583, JPOS, Log4J, and socket programming. It includes the following key points: 1. It introduces ISO 8583, JPOS, and Log4J libraries that will be used in the application. 2. It provides code examples for setting up message handling classes using these libraries, including a PackagerFactory, MessageHandler, and unpacking/packing ISO messages. 3. It describes setting up socket programming components like a ServerConfig, SocketServerHandlerFactory, SocketServerHandler, and SocketConnectionServer to handle client connections. 4. It mentions using Spring framework for dependency injection and using

Uploaded by

mittumithun050
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
424 views7 pages

ISO 8583 with JPOS and Log4J in Java

This document provides an overview and instructions for setting up a Java application that uses ISO 8583, JPOS, Log4J, and socket programming. It includes the following key points: 1. It introduces ISO 8583, JPOS, and Log4J libraries that will be used in the application. 2. It provides code examples for setting up message handling classes using these libraries, including a PackagerFactory, MessageHandler, and unpacking/packing ISO messages. 3. It describes setting up socket programming components like a ServerConfig, SocketServerHandlerFactory, SocketServerHandler, and SocketConnectionServer to handle client connections. 4. It mentions using Spring framework for dependency injection and using

Uploaded by

mittumithun050
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Introduction
  • Logging Framework with Log4j
  • Java Socket Programming

(ISO 8583 + JPOS + Log4J) in Java Socket Programming Oct 7, '08 2:10 PM

for everyone
SECTION 1. INTRODUCTION
Chapter 1.1. ISO 8583
You can read it's explanation first in Wikipedia.
Chapter 1.2. JPOS
JPOS is opensource framework for ISO 8583. Source code and library are free but
documentation is comercial. We can download it here.
Chapter 1.3. Log4J
Log4J is opensource logging library. We can download it's library here and read
it's mini e-book first written by Mr. Endy in here.
Chapter 1.4. Java Socket Programming
There's no explanation. Just need the basic knowledge of Java network programmin
g and Java Thread Programming and let's coding.
SECTION 2. CODING
First we prepare that all we need. In this time, we will use NetBeans as IDE. Be
sides JPOS framework and Log4J library that I have mentioned above, we still nee
d:
1. Xerces-Java XML parser library ([Link])
2. Spring framework
3. Jakarta Apache Commons Logging library
Chapter 2.1. ISO 8583 + JPOS + Log4J
In NetBeans, create a new Java application named MyApp. Create a package named c
[Link].iso8583. JPOS framework need a packager to set which ISO 8583 version t
hat will be used. In this time we will use ISO 8583 version 1987. Download first
[Link] and place it in that package. Create a class as packager factory
named [Link].

package [Link].iso8583;
import [Link];
import [Link];
import [Link];
import [Link];
public class PackagerFactory {
public static ISOPackager getPackager() {
ISOPackager packager = null;
try {
String filename = "[Link]";
InputStream is = [Link](filename)
;
packager = new GenericPackager(is);
}
catch (ISOException e) {
[Link]();
}
return packager;
}
}

And then create a class named [Link] that will be used to handle re
ceived message. Download first [Link] that will be used to tra
nslate bits of ISO message to become a String message that can be read easily.
package [Link].iso8583;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MessageHandler {
private static ISOPackager packager = [Link]();
private Logger logger = [Link]( getClass() );
public String process(ISOMsg isomsg) throws Exception {
[Link]("ISO Message MTI is "+[Link]());
[Link]("Is ISO message a incoming message? "+[Link]());
[Link]("Is ISO message a outgoing message? "+[Link]());
[Link]("Is ISO message a request message? "+[Link]());
[Link]("Is ISO message a response message? "+[Link]());
String message = "";
for (int i=0;i<128;i++){
if ([Link](i)){
message += loadXMLProperties().getProperty([Link](i))+
"="+
[Link](i)+"\n";
}
}
[Link](message);
return message;
}
public ISOMsg unpackRequest(String message) throws ISOException, Exception {
ISOMsg isoMsg = new ISOMsg();
[Link](packager);
[Link]([Link]());
[Link]([Link], " ");
return isoMsg ;
}
public String packResponse(ISOMsg message) throws ISOException, Exception {
[Link]([Link], " ");
return new String( [Link]() ) ;
}
public Properties loadXMLProperties(){
Properties prop = new Properties();
try{
FileInputStream input=new FileInputStream("[Link]"
);
[Link](input);
[Link]();
}
catch(IOException e){
[Link]();
}
return prop;
}
}
Chapter 2.2. Java Socket Programming + Log4J
Create a package named [Link] and then create four classes named Serve
[Link], [Link], [Link], SocketC
onnectionServer. Before that create [Link] as logging configuration in
default package.

# Category Configuration
[Link]=INFO,Konsole,Roll
# Console Appender Configuration
[Link]=[Link]
[Link]=[Link]
# Date Format based on ISO8601 : %d
[Link]=%d [%t] %5p %c  %m%n
# Roll Appender Configuration
[Link]=[Link]
[Link]=/home/ndung/NetBeansProjects/MyApp/log/[Link]
[Link]=10KB
[Link]=2
[Link]=[Link]
# Date Format based on ISO8601 : %d
[Link]=%d [%t] %p (%F:%L)  %m%n

package [Link];
public class ServerConfig {
private int port;
public int getPort() {
return port;
}
public void setPort(int port) {
[Link] = port;
}
}

package [Link];
import [Link];
import [Link];
import [Link];
public class SocketServerHandlerFactory {
private MessageHandler messageHandler;
public SocketServerHandlerFactory(MessageHandler messageHandler) {
[Link] = messageHandler;
}
public SocketServerHandler createHandler(Socket socket) throws IOException {
return new SocketServerHandler(socket, messageHandler);
}
}

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SocketServerHandler extends Thread{
private Logger logger = [Link]( getClass() );
private Socket serverSocket ;
private BufferedReader inFromClient;
private DataOutputStream outToClient;
private MessageHandler messageHandler;
private String datafromClient;
public SocketServerHandler(Socket socket, MessageHandler messageHandler) thr
ows IOException {
super("SocketHandler (" + [Link]().getHostAddress() + ")"
);
[Link] = socket ;
[Link] = messageHandler;
[Link] = new BufferedReader(new InputStreamReader(serverSocke
[Link]()));
[Link] = new DataOutputStream([Link]());
}
@Override
public void run() {
try {
[Link]("Server is ready...");
while (true) {
[Link]("There is a client connected...");
[Link]("InfoServer version 0.1\n");
datafromClient = [Link]();
[Link]("Data From Client : "+datafromClient);
ISOMsg isomsg = [Link](datafromClient);
[Link]([Link](isomsg));
}
}
catch (IOException ioe) {
[Link]("error: " + ioe);
}
catch (Exception e) {
[Link]("error: " + e);
}
finally {
try {
if (inFromClient != null) [Link]();
if (outToClient != null) [Link]();
if (serverSocket != null) [Link]();
} catch (IOException e) {
[Link]();
}
}
}
}

package [Link];
import [Link];
import [Link];
public class SocketConnectionServer {
private ServerConfig config;
private SocketServerHandlerFactory handlerFactory;
private boolean stop;
public SocketConnectionServer(ServerConfig config, SocketServerHandlerFactor
y handlerFactory) {
[Link] = config;
[Link] = handlerFactory;
}
public void start() throws IOException {
stop = false;
final ServerSocket serverSocket = new ServerSocket([Link]());
new Thread(new Runnable() {
public void run() {
while (!stop) {
try {
[Link]([Link]()).sta
rt();
}
catch (IOException e) {
[Link]();
}
}
}
}).start();
}
public void stop() {
stop = true;
}
}

Create a socket server class named [Link]. This class also as a main clas
s for our application. And then we will create a socket client class named MyCli
[Link]. Before that create [Link] in default package as Spring
configuration injection for our main class.

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"[Link]
<beans>
<bean id="socketConnectionServer" class="[Link]
nServer">
<constructor-arg>
<ref local="config" />
</constructor-arg>
<constructor-arg>
<ref local="socketServerHandlerFactory" />
</constructor-arg>
</bean>
<bean id="config" class="[Link]">
<property name="port">
<value>50000</value>
</property>
</bean>
<bean id="socketServerHandlerFactory" class="[Link]
rHandlerFactory">
<constructor-arg>
<ref local="messageHandler" />
</constructor-arg>
</bean>
<bean id="messageHandler" class="[Link]">
</bean>
</beans>

package [Link];
import [Link];
import [Link];
public class MyServer {
public static void main(String[] args) throws IOException {
ApplicationContext ctx = new ClassPathXmlApplicationContext("application
[Link]");
SocketConnectionServer server = (SocketConnectionServer) [Link]("so
cketConnectionServer");
[Link]();
}
}

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MyClient {
private final int MY_PORT=50000;
private final String TargetHost = "localhost";
private final String QUIT = "QUIT";
private Logger logger = [Link]( getClass() );
public MyClient() {
try {
BufferedReader inFromUser = new BufferedReader(new InputStreamReader
([Link]));
Socket clientSocket = new Socket(TargetHost, MY_PORT);
DataOutputStream outToServer = new DataOutputStream([Link]
OutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamRead
er([Link]()));
[Link]([Link]());
boolean isQuit = false;
while (!isQuit) {
[Link]("Your data : ");
String cmd = [Link]();
cmd = [Link]();
if ([Link](QUIT)) {
isQuit = true;
}
[Link](cmd + "\n");
String message = [Link]();
while (message!=null){
[Link]("From Server: " + message);
message = [Link]();
}
}
[Link]();
[Link]();
[Link]();
}
catch (IOException ioe) {
[Link]("Error:" + ioe);
}
catch (Exception e) {
[Link]("Error:" + e);
}
}
public static void main(String[] args) {
new MyClient();
}
}

Run our application first. It means our main class ([Link]) will be run f
irst. And then run client as much that we want. It means [Link] will be r
un twice or more. And then in one of our client application console enter an inp
ut data. It means a String of ISO message. As example:
0210723A00010A808400185936001410010999990110000000100000001007021533000001191533
10061007065656561006090102240000000901360020100236C0102240000000
Look in both of our application console either MyServer or MyClient. What do you
see?
Btw, Happy Eid Mubarak...

(ISO 8583 + JPOS + Log4J) in Java Socket Programming
Oct 7, '08 2:10 PM
for everyone
SECTION 1. INTRODUCTION
Chapter 1.1. ISO
package com.ndung.iso8583;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import or
Chapter 2.2. Java Socket Programming + Log4J
Create a package named com.ndung.socket and then create four classes named Serve
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.ServerSocket;
public class SocketConnectionServer {
    private ServerConfig conf
</property>
    </bean>
    <bean id="socketServerHandlerFactory" class="com.ndung.socket.SocketServe
while (!isQuit) {
                System.out.print("Your data : ");
                String cmd = inFromUser.readL

You might also like