Today i want to share about JPos Server Forward Request Message to Another Server. The Jpos server get request message from a client and then forward the message to another server for some purpose.
Picture below show us the illustration:
we will focuse on how Server A forward the message to the server B, and give response message to the client.
First create file 10_server.xml
[xml]
[/xml]
Server A will listen to port 15500, so the client send request to that port and will be captured with process method in ServerListener class. But, before we create ServerListener Class we have to create another xml files to connect with Server B. lets give file name 15_channel.xml and 20_mux.xml
Bellow is the 15_channel.xml
[xml]
[/xml]
And this is for 20_mux.xml, see that we fill “in” tag with value of “out” tag,
and “out” tag with “in” declared on 15_channel.xml
[xml]
[/xml]
And the last thing we have to do is create ServerListener class that implement ISORequestListener. In the process method get the jpos-client-mux and send request to that server B, and after get the response from server B, server A will send response to the client.
[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;
import org.jpos.iso.MUX;
import org.jpos.q2.Q2;
import org.jpos.util.NameRegistrar;
/**
* Server Listener will capture all request message to the process method
* @author Didik Hari
*
*/
public class ServerListener implements ISORequestListener{
public static void main(String[] args) {
Q2 q2 = new Q2();
q2.start();
}
@Override
public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
try {
if (isoMsg.getMTI().equals(“0800”)) {
ISOMsg reply = (ISOMsg) isoMsg.clone();
reply.setResponseMTI();
reply.set(39, “00”);
isoSrc.send(reply);
return true;
}
// send request to server B
MUX mux = (MUX) NameRegistrar.getIfExists(“mux.jpos-client-mux”);
ISOMsg reply = mux.request(isoMsg, 10 * 1000);
if (reply != null) {
System.out.println(new String(reply.pack()));
reply.set(125, “RESPONSE FROM SERVER A”);
isoSrc.send(reply);
}
} catch (ISOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
[/java]
and that’s all my post about JPos Server Forward Request Message to Another Server
Hope this post can help somebody.
Leave a Reply