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.
hi Didik. Can you tell me how to run this application?
Hi Deepak, here i have made new post and share my eclipse project about this post here: http://didikhari.web.id/java/jpos-server-forward-message-simulator
you can run the Client.java class in your eclipse IDE. Thanks
Mas, mau tanya, kalau forward message nya ke core system gimana cara ya? Ada tips nya kah? Soalnya kalau saya pake channel gitu saya dapat error
channel-receiver-jpos-client-receive
java.lang.NullPointerException
at org.jpos.iso.BaseChannel.createISOMsg(BaseChannel.java:666)
at org.jpos.iso.BaseChannel.createMsg(BaseChannel.java:663)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:691)
at org.jpos.q2.iso.ChannelAdaptor$Receiver.run(ChannelAdaptor.java:317)
at java.lang
Thanks
Seharusnya tidak ada masalah mas Hady, kalau memang format spesifikasi messaging sudah jelas, seharusnya pakai channel tidak masalah.
Itu terjadi error pas apa ya? nerima ya?
pakai NACChannel channel? kemungkinan format channel nya berbeda.
Terima Kasih Jawabannya mas,
Kemarin saya ubah menjadi ASCII dan berhasil. Mas ada lagi yang mau saya tanyakan:
1. Apakah kita harus menggunakan transaction manager? Kalau tidak menggunakan transaction manager, efeknya apa ya?
2. Space , apakah kita harus menggunakan space dan coding seperti contoh Mas Didik di post tgl 2 Juni? Kalau kita menggunakan space default masalahnya apa ya?
3. Ketika memulai project, apakah harus menggunakan JPOSEE atau JPOS atau JPOS Template, bedanya apa mas?
4. Saya sekarang mendapat error seperti berikut :
channel-receiver-jpos-client-receive
Read timeout
kira-kira kalau itu dibiarkan apakah ada efek?
5. Pada konfigurasi mux saya menggunakan unhandled-queue , lalu? Maksudnya itu efekny apa ya? apakah harus sy tambahkan codingan lain?
Mohon maaf pertanyaan saya banyak, karena baru 1 minggu kurang saya belajar JPOS.
Thanks.
1. Kita tidak harus menggunakan transaction manager mas. namun ketika jPOS yang kita deploy semakin banyak koneksi yang dibuka dan flow/processnya bervariasi, kita akan semakin sulit me-maintainnya. coba mas Hadi baca-baca lagi tentang Group Selector dan AbortParticipant.
2. Tidak ada masalah juga mas, namun jika kita menggunakan transaction manager lebih dari satu (jPOS yang kita deploy sudah sangat kompleks, banyak koneksi yang dibuka, flow yang bervariasi, dll) kita harus memisahkan space nya untuk masing2 transaction manager.
3. Mungkin kalau pertanyaan yang ini beda-beda jawabanya, tergantung selera mas. kalau saya memang hanya belajar JPOS dulu, jPOS template belum pernah belajar, JPOSEE juga belum pernah mencoba, yang penting konsep jPOS dapet dulu mas.
4. error itu terjadi karena si server tidak mengirimkan response.
5. unhandled bisa dibaca JPos Client Receive Request From Remote Server
santai saja mas š saya juga masih dalam tahap belajar kog.
Kalau masih ada yang kurang paham dari posting saya tersebut, bisa kirim komentar ke masing-masing post mas. Biar topiknya sesuai dengan postingnya.
Terimakasih sudah baca blog saya. š
Mas,
Saya mengikuti contoh yang diatas, tapi hasil nya adalah, ketika dalam 1 session ada 2 transaksi yang masuk, mengakibatkan MUX ny menyelesaikan transaksi 1 per 1, sehingga process nya tidak bisa paralel.. apakah benar seperti itu?
Kira-kira bisa gk ya, supaya request nya masuk dulu semua, nanti ada 1 thread lagi yang mengurus fwd message dari Server A ke Server B dan menunggu reply nya?
Thanks.
Please I need help on creating a JPOSEE client… I’m new to JPOS
you can start on jposee documentation
trims krn contoh diatas, sy sdh berhasil buat flow switcher kira2 seperti ini :
clientAswitcherserverA
clientBswitcherserverB
maklum masih nubi jd ane mem-parsing bit utk mengarahkan request via QMUX ke channel serverA atau serverB, jika bit48=A maka ke mux channel serverA dst.
kira2 ada suggest metode utk “proper way” nya gk gan?
oya 1 lagi.. ane pake Q2, dan buat 2 server xml di port 1000 dan 2000,
cara dapetin incoming itu masuknya dr port mana, gmn caranya ya?
trims.
Hello. And Bye.
Hi, Bye
Write more, thats all I have to say. Literally, it seems as
though you relied on the video to make your point.
You obviously know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something
enlightening to read?