jPOS Server Forward Message Simulator

Hi, Today i want to share my code about jPOS Server Forward Message Simulator. The simulator flow is described on my old post here: JPos Server Forward Request Message to Another Server. My old post is talk about the “front end” server that receive request from client and forward to “back end” server, so in this post we will talk about the client and backend server.

jPOS Server Forward Message Simulator
jPOS Server Forward Message Simulator

I have refactor my code from my old post, so maybe you’ll find different term.
We start with the backend server, or on my old post is Server B, first you need to create file named 11_server_B.xml containing this code.
[xml]

12201
100
10



[/xml]

And the Listener class is:

[java]
package com.didikhari.controller;

import java.io.IOException;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISORequestListener;
import org.jpos.iso.ISOSource;

/**
* Server B Listener
* Listener for Server A Request (Back end Server)
* @author Didik Hari
*
*/
public class ServerBListener implements ISORequestListener {

@Override
public boolean process(ISOSource requester, ISOMsg reqMsg) {
try {
ISOMsg respMsg = (ISOMsg) reqMsg.clone();
respMsg.set(124, “HI CLIENT, THIS IS DATA FROM ME! B”);
respMsg.set(39, “00”);
respMsg.setResponseMTI();
requester.send(respMsg);
} catch (ISOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}

}

[/java]

The ServerBListener is used for receive request from server A, and send response back.

Thats it the backend server, you can find about configuration front end server on my old post JPos Server Forward Request Message to Another Server

And the last thing we need to do is create a requester class, or called “Client”. For client implementation, we need to create two file configuration named 30_client_channel.xml and 40_client_mux.xml.
First, create 30_client_channel.xml file and give this code:
[xml]

client-send
client-receive
10000

[/xml]

and the 40_client_mux.xml is:
[xml]

client-receive
client-send

[/xml]
Client channel adaptor will send request message to Server A adress and wait response on it.

But How to start the jPOS Server Forward Message Simulator?? we need to create a class that will call Q2.start method, so the jPOS Library will deploy the configuration we have made.
[java]
package com.didikhari.requester;

import java.util.Date;

import org.jpos.iso.ISODate;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.MUX;
import org.jpos.q2.Q2;
import org.jpos.util.NameRegistrar;

/**
* Requester
* @author Didik Hari
*
*/
public class Client {

public static void startQ2(){
Q2 q2 = new Q2();
q2.start();
System.out.println(“Starting Deployment”);
}

public static void main(String[] args) {
startQ2();
// give some delay before sent req, cz q2 deployment is async
ISOUtil.sleep(5000);

// Process send and receive data
try {
MUX mux = (MUX) NameRegistrar.getIfExists(“mux.client-mux”);
ISOMsg reply = mux.request(createReqMsg(), 10 * 1000);
System.out.println(new String(reply.pack()));
} catch (ISOException e) {
e.printStackTrace();
}
}

public static ISOMsg createReqMsg(){
ISOMsg reqMsg = new ISOMsg();
reqMsg.setHeader(“ISO011000017”.getBytes());
try {
reqMsg.setMTI(“0200”);
reqMsg.set(3, “530020”);
reqMsg.set(7, ISODate.getDateTime(new Date()));
reqMsg.set(11, String.valueOf(System.currentTimeMillis() % 1000000));
reqMsg.set(12, ISODate.getTime(new Date()));
reqMsg.set(13, ISODate.getDate(new Date()));
reqMsg.set(14, “1502”);
reqMsg.set(17, ISODate.getDate(new Date()));
reqMsg.set(18, “6011”);
reqMsg.set(35, “6011343456sdgfd”);
reqMsg.set(37, “123456789012”);
reqMsg.set(41, “1234567890123456”);
reqMsg.set(124, “GIVE ME DATA FROM SERVER B”);
} catch (ISOException e) {
e.printStackTrace();
}
return reqMsg;
}
}
[/java]


DONE!!
it’s all the jPOS Server Forward Message Simulator.
You can download my eclipse jPOS Server Forward Message Simulator project by click this link bellow:

Please disable popup blocker for view the link, after you click the link below it will open new tab for downloading the files.


Hope this post can help somebody, thanks for comming in my blog.
Regards.

16 responses to “jPOS Server Forward Message Simulator”

  1. phenom Avatar
    phenom

    ada baiknya tutorial dengan db juga gan…

    1. Didik H Avatar

      gan phenom, thanks gan sarannya.. lain kali buat post tentang kombinasi sama db gan.. mkasih ya udah mampir.. šŸ˜€

  2. Mohamed Kassim Avatar
    Mohamed Kassim

    Hi Didik H;
    Thank you for the post. I have been trying to run this it is failing getting can’t load com.mandiri.soa.ubp.UBPPackager. I was trying to look where i can modify and my my own packager because i don’t find yours, i can’t get the location for that. The post look very helpful for once i managed to run it.

    1. Didik H Avatar

      Thanks for your feed back Mohamed, yes we can use any packager as long as the server and client using same specs.

  3. Darma Avatar
    Darma

    Good jobs gan… really appreciate.

  4. Taha Yassine Avatar
    Taha Yassine

    Hi, I have tried to implements the same things but no result

    1. Didik H Avatar

      Hallo, what is the error Taha?

  5. Thomas Avatar
    Thomas

    Good day Didik,
    I am not sure if I am doing this right. I downloaded your files to test. Remapped the JAR files to the ones I have for jPos but I cannot compile and run your client nor the servers.
    Am I missing a step somewhere?
    I have jPos-2.0.4.

    1. Didik H Avatar

      im using 1.9.x jpos version, what is the error?

  6. Rofi Avatar
    Rofi

    Mas, saya ko koneksinya gagal terus ya?

    1. didikhari Avatar
      didikhari

      gagal error nya apa mas?

  7. NM ARUN BALAJI Avatar
    NM ARUN BALAJI

    How to configure client server simulators in jPOS using maven dependency?

  8. mt Avatar
    mt

    hi . i get error
    Exception in thread “main” java.lang.NoClassDefFoundError: org/jdom/Content
    at Client.startQ2(Client.java:10)
    at Client.main(Client.java:16)
    Caused by: java.lang.ClassNotFoundException: org.jdom.Content
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    why ?

  9. Emil Avatar
    Emil

    Konsep ISO saya sudah paham nih mas, cuma konsep pengembangan JPos masih buta. Harus belajar dari mana dulu untuk nguasain JPos. kalo ada link tutorial yang bisa dipelajari mohon dishare mas.

    1. didikhari Avatar
      didikhari

      Hallo mas, kalau saya dulu coba pelajari dari programmer guide nya mas, ada bahan pembelajaran dikasih di kantor. lumayan bisa lebih paham konsep dasarnya, dan cara custom channel, packager dan QBean. selebihnya coba untuk pelajari code nya, mulai dai class Q2, sampai ke configurable class yang lain seperti QMUX, QServer, Space, NameRegistrar, dll.

  10. Deva Avatar
    Deva

    Thanks for the post Didik. Download link is not seen in the post. Please post the link to download.

Leave a Reply

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