jPOS Server in-out

jPOS Server in-out

HI!! i’m back, finally! hehe

Hi, everybody! Its been a while from my last post. I almost forgot that i have this blog. 😀

So, 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 class 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

<server class="org.jpos.q2.iso.QServer" logger="Q2" name="my-server">

    <attr name="port" type="java.lang.Integer">8888</attr>
    <attr name="maxSessions" type="java.lang.Integer">300</attr>	
    <attr name="minSessions" type="java.lang.Integer">10</attr>
	
	<channel name="my-server-channel" class="org.jpos.iso.channel.ASCIIChannel" logger="Q2"
             packager="org.jpos.iso.packager.GenericPackager">
             <property name="packager-config" value="src/main/resources/cfg/iso87ascii.xml" />
    </channel>

    <request-listener class="id.web.didikhari.MyRequestListener" logger="Q2" realm="incoming-request-listener">
    </request-listener>
	
    <in>NETWORK_IN</in>
    <out>NETWORK_OUT</out>
</server>

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 version="1.0" ?>
<mux class="org.jpos.q2.iso.QMUX" logger="Q2" name="my-server-mux">
	<in>NETWORK_OUT</in>
	<out>NETWORK_IN</out>
	<unhandled>unhandled</unhandled>
</mux>

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 NameRegistrar.get("mux.my-server-mux");. 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 id.web.didikhari.MyRequestListener 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" <br/>
 * 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

9 comments

  1. hallo,

    Thank you for sharing this.

    How does someone track timeout incase of no response from client.

    thank you

  2. halo bang…
    makin jago aja nih bang 😀
    mau dong dibagi ilmu jpos nya…

    kalau belum pake Q2 dan masi pake ISOMUX behavior nya agak aneh mas,
    kalo di liat2 and di check kaya nya channel.receive dari ISOServer bentrok sama channel.receive dari ISOMUX, jadi nya Response nya Intermittent, kadang jadi Response buat MUX, kadang jadi Request buat Server danmasuk ke RequestListener…
    ada yang bisa di lkukan untuk nangani ini? sselain pindah ke Q2

    1. Hallo hab. Gmn kabar?

      Ak jarang pakai isomux, jadi kurang tah behavior isomux nya.

      Cuman kalau dari issue nya, mungkin bisa dibedain object channel nya, antara isoserver dan isomux. Setting timeout di mux nya jgn terlalu kecil jg hab, sama pastiin kalau key message nya sudah sesuai stan+terminalid dan mti & response mti nya match.

      1. baik alhamdulillah,mas didik gimana?
        alhamdulillah ya masi inget 😛

        nah itu dia mas…walaupun channel nya memang beda…tapi kan yang di lakukan channel.receive sama…
        ketika channel.receive di isomux jalan, yauda message TCP nya uda keburu di ambil di isomux
        ketika channel.receive di ISOServer jalan, yauda message dari TCP nya uda di ambil ISOServer jadi kalo kita kirim request pake ISOMUX dari server, response nya malah kadang masuk ke Class Listener yang kita set di ISOSERVER sedangkan mux.request nya malah timeout…

        kalau untuk key management aku uda yakin match karena aku taro beberapa cekpoin jg sebelum get by key… hehe,
        timeout jg sudah 30 detik, dan secara tcp dump pun memang si client sudah mengirim tcp message

        kaya nya ini dulu pernah mas didik alamin pas nanya di user jpos group hhee…
        di thread ini :
        https://groups.google.com/forum/#!topic/jpos-users/YuWsr8HiKMM

        kadang dia sukses, kadang dia timeout, jadi pas timeout ini kaya nya tcp message nya di rebut requestlistener nya isoserver

        nah kaya nya itu solved nya setelah ganti ke Q2 ya om? atau gimana om?
        emng si ISOMUX uda depricated, haha…..uda waktu nya di ganti 😛

Leave a Reply

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