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.
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]
[/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]
[/xml]
and the 40_client_mux.xml is:
[xml]
[/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.
Leave a Reply