In this post i will share about jPOS Server in-out, have you experienced a case where you as a server need to initiate request? it could be network management message. This post is related topic with my previous post about jPOS Client Receive Request From Remote Server
We are lucky, jPOS can handle this case. all we need to do is to set <in> and <out> inside server configuration. If you look at org.jpos.q2.iso.QServer
you will find initIn()
and initOut()
methods thats actually read <in> and <out> tags.
Ok, lets start the implementation.
First, we need to create server configuration that have <in> and <out> tag inside.
lets name it 10_server.xml
[xml highlight=”15-16″]
8888
300
10
Ā
Ā
NETWORK_IN
NETWORK_OUT
[/xml]
Ok, you can see in line 15 and 16 above, that we have <in> and <out> tags configuration. SO? so what if we have it? is it really matter? YES! because we can use it to config a mux, we know that we use a mux to send a message and whenever we need the mux, we can use NameRegistrar to get the mux’s object.
Ok, lets continue to the next configuration.
We will create mux configuration that connected to above server through <in> and <out> tags.
Lets name it 11_server_mux.xml
[xml highlight=”3-4″]
NETWORK_OUT
NETWORK_IN
unhandled
[/xml]
with above configuration, our server now has ability to send a request message using port 8888. And as i said before, we can get the mux object using NameRegistrar [java]NameRegistrar.get(“mux.my-server-mux”);[/java]. Please note the value on hilighted line (3 and 4) is reverse from server (line 15-16) <in> and <out> tags.
And bellow class is [java]id.web.didikhari.MyRequestListener[/java] we need this class listener to get the request message from client.
package id.web.didikhari; import java.io.IOException; import org.jpos.iso.ISOException; import org.jpos.iso.ISOMsg; import org.jpos.iso.ISORequestListener; import org.jpos.iso.ISOSource; /** * This is sample request listener that always response success DE#39 = "00" * You can use Transaction Manager in real application. * @author didik */ public class MyRequestListener implements ISORequestListener { public boolean process(ISOSource source, ISOMsg reqMsg) { try { ISOMsg respMsg = (ISOMsg) reqMsg.clone(); respMsg.setResponseMTI(); respMsg.set(39, "00"); source.send(respMsg); } catch (ISOException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } }
Ā
That’s all we need to create jPOS Server in-out case. Hope it can help.
i have uploaded code for this post on bitbucket, you can get it here
Leave a Reply