Packager Propio como?

44 views
Skip to first unread message

Fabio Arias

unread,
Mar 24, 2009, 1:23:42 PM3/24/09
to jPOS Users
Muy Buenos Dias amigos, tengo un problema deseo realizar una
implementacion con jPos pero debo implementar un protocolo ya
existente, he intentado varias cosas pero aun no me ha funcionado del
todo correcto.

El protocolo tiene las siguientes bases

Incomming
Longitud ( 1 Byte Valor Hexadecimal incluye este primer byte)
Tipo de Transaccion ( 1 Byte Valor Hexadecimal )
Data Request ( ASCII longitud variable dependiendo de la longitud-2)

Outgoing
Longitud ( 1 Byte Valor Hexadecimal incluye este primer byte)
Tipo de Transaccion ( 1 Byte Valor Hexadecimal )
Data response ( ASCII longitud variable dependiendo de la longitud-2)

Como hago para implementar esto con jPos, les agradezco todo la ayuda
que me puede dar.

Gracias

Mark Salter

unread,
Mar 24, 2009, 2:37:19 PM3/24/09
to jpos-...@googlegroups.com
First an apology for my Spanish, courtesy of babelfish. This is
primarily an English based mailing list, but let's try...

Primero una apología por mi español, cortesía del babelfish. Éste es
sobre todo una lista de personas a quienes se mandan propaganda basada
inglesa, pero let' intento de s…

Fabio Arias wrote:
> Muy Buenos Dias amigos, tengo un problema deseo realizar una
> implementacion con jPos pero debo implementar un protocolo ya
> existente, he intentado varias cosas pero aun no me ha funcionado del
> todo correcto.
>
> El protocolo tiene las siguientes bases
>
> Incomming
> Longitud ( 1 Byte Valor Hexadecimal incluye este primer byte)
> Tipo de Transaccion ( 1 Byte Valor Hexadecimal )
> Data Request ( ASCII longitud variable dependiendo de la longitud-2)
>
> Outgoing
> Longitud ( 1 Byte Valor Hexadecimal incluye este primer byte)
> Tipo de Transaccion ( 1 Byte Valor Hexadecimal )
> Data response ( ASCII longitud variable dependiendo de la longitud-2)

Is the Data portion in each direction an ISO8583 structure?

¿Es la porción de los datos en cada dirección una estructura ISO8583?

>
> Como hago para implementar esto con jPos, les agradezco todo la ayuda
> que me puede dar.

Depending on the answers to the above questions, you might take a look
at FSDMsg instead of the ISO8583 Packager(s) or variants.

Dependiendo de las respuestas a las preguntas antedichas, usted puede
ser que heche una ojeada FSDMsg en vez de los embaladores ISO8583 o de
las variantes.

>
> Gracias

You are welcome.

Usted es agradable.


--
http://babelfish.yahoo.com/
Mark

Fabio Arias

unread,
Mar 24, 2009, 2:47:33 PM3/24/09
to jPOS Users
Mark, thanks for ur response, the data portion is just array of bytes,
no have a ISO8583 structure, thats is the problem, but i need that my
protocolo or messaging specifications works with jPos.

For Example:

Request.

42 04 30 34 7C 33 7C 35 31 35 36 7C 34 39 34 7C | B.04|3|5156|494|
34 33 37 7C 32 30 30 37 31 32 30 37 30 35 30 34 | 437|
200712070504
34 31 7C 31 32 33 34 35 36 7C 32 36 36 7C 31 30 | 41|123456|266|10
30 30 30 2E 30 30 7C 33 31 31 38 34 34 34 35 37 | 000.00|311844457
36
7C
| 6|

Response.

4D 04 31 30 31 7C 31 30 30 30 30 2E 30 30 7C 31 | M.101|10000.00|1
37 31 30 35 31 7C 33 37 35 39 30 39 7C 31 30 2F | 71051|375909|10/
31 32 2F 30 37 20 30 39 3A 32 30 3A 31 30 7C 30 | 12/07 09:20:10|0
30 30 33 37 30 32 7C 33 30 35 32 37 31 34 39 35 | 003702|305271495
30 7C 32 30 30 38 2F 30 31 2F 30 39 7C | 0|
2008/01/09|

As u see, the first byte have a value of long or data including self,
the next byte have a transaction type, and the rest of bytes is the
data message, i need a way for create a ISOServer that receive and
response this kind of data.

Thanks a lot

Alejandro Revilla

unread,
Mar 24, 2009, 2:50:51 PM3/24/09
to jpos-...@googlegroups.com
As Mark says:

>
> Dependiendo de las respuestas a las preguntas antedichas, usted puede
> ser que heche una ojeada FSDMsg en vez de los embaladores ISO8583 o de
> las variantes.
>

Your protocol looks like something that could be handled by
org.jpos.util.FSDMsg.

Fabio Arias

unread,
Mar 24, 2009, 3:01:44 PM3/24/09
to jPOS Users
Alejandro, gracias por las respuesta, cual seria la manera de
implementarlo, encontre la clase pero la verdad no tengo mucha idea de
como aplicar lo que me dicen, por favor les pido disculpas.

Mark Salter

unread,
Mar 24, 2009, 3:13:49 PM3/24/09
to jpos-...@googlegroups.com
Fabio Arias wrote:
> Mark, thanks for ur response, the data portion is just array of bytes,
> no have a ISO8583 structure, thats is the problem, but i need that my
> protocolo or messaging specifications works with jPos.

Ok, so FSDMsg or FSDISOMsg are probably going to be your thing.

You still need to construct the configuration files to define the
structure. Do you have a document that defines the fields that are
present in each direction, their formats and their meanings? If not get
one as soon as possible.

The length byte you will handle in a Channel, reading and returning the
correct number of bytes, for subsequent unpacking.

>
> For Example:
>
> Request.
>
> 42 04 30 34 7C 33 7C 35 31 35 36 7C 34 39 34 7C | B.04|3|5156|494|
> 34 33 37 7C 32 30 30 37 31 32 30 37 30 35 30 34 | 437|200712070504
> 34 31 7C 31 32 33 34 35 36 7C 32 36 36 7C 31 30 | 41|123456|266|10
> 30 30 30 2E 30 30 7C 33 31 31 38 34 34 34 35 37 | 000.00|311844457
> 36 7C | 6|
>
> Response.
>
> 4D 04 31 30 31 7C 31 30 30 30 30 2E 30 30 7C 31 | M.101|10000.00|1
> 37 31 30 35 31 7C 33 37 35 39 30 39 7C 31 30 2F | 71051|375909|10/
> 31 32 2F 30 37 20 30 39 3A 32 30 3A 31 30 7C 30 | 12/07 09:20:10|0
> 30 30 33 37 30 32 7C 33 30 35 32 37 31 34 39 35 | 003702|305271495
> 30 7C 32 30 30 38 2F 30 31 2F 30 39 7C | 0|2008/01/09|
>
> As u see, the first byte have a value of long or data including self,
> the next byte have a transaction type, and the rest of bytes is the
> data message, i need a way for create a ISOServer that receive and
> response this kind of data.

Shame the dump uses '|' as a divider between hex and character areas, it
confused me for a bit 8).

Once you have your message specification to hand, search this mailing
list for FSDMsg and FSDISOMsg there have been many discussions parts of
which will be relevant.

One link I found points to an entry within Andy's ever useful and often
referenced blog:-

http://www.andyorrock.com/2007/07/as-may-you-know.html

This talks through a use of FSDMsg - for a different message structure,
and it might give you the idea.

My use of FSDMsg and it's hierarchical config files always take me a
little while to get into, but if you do need advice, this is the place
to find it.

>
> Thanks a lot

Thanks for moving to English, was my BabelSpanish that bad?

8)

--
Mark

Andy Orrock

unread,
Mar 24, 2009, 3:19:03 PM3/24/09
to jpos-...@googlegroups.com
Thanks, Mark! I was just about to pass Fabio the same link.

Andy

chhil

unread,
Mar 24, 2009, 3:20:44 PM3/24/09
to jpos-...@googlegroups.com
2 things, search the mailing list for FSDMsg and you will see examples.
You can take a peek at 

Andy Orrock

unread,
Mar 24, 2009, 3:25:53 PM3/24/09
to jpos-...@googlegroups.com

Wow, I even forgot I had written those other ones.  Thanks, Murtuza.

 

Andy

 

From: jpos-...@googlegroups.com [mailto:jpos-...@googlegroups.com] On Behalf Of chhil
Sent: Tuesday, March 24, 2009 2:21 PM
To: jpos-...@googlegroups.com
Subject: Re: Packager Propio como?

 

2 things, search the mailing list for FSDMsg and you will see examples.

Fabio Arias

unread,
Mar 24, 2009, 3:34:03 PM3/24/09
to jPOS Users
Hi Andy/Mark/Alejandro, how r u?, andy i'm try to understand the note
write for u, but i cant, if u can help me a little more, i appreciate
u a lot, my problem is just a caprice,because i work with jPos 4
years, but i have a client with a private protocol NO-ISO8583, i made
this and works, but with the POS disconnect, the server continue
receive a data zero all time.

---------------------------------------
Start Server
---------------------------------------
clientSideChannel = new SPCChannel(new SPCPackager());
pool = new ThreadPool(Integer.parseInt
(prop.getProperty("bwg.listener.minThread")), Integer.parseInt
(prop.getProperty("bwg.listener.maxThread")));
pool.setLogger(logger, "iso-bwg-pool-" +
serverDTO.getDescription());
server = new ISOServer(serverDTO.getPort(),
(ServerChannel) clientSideChannel, pool);
server.setLogger(logger, "iso-bwg-server-" +
serverDTO.getDescription());
server.addISORequestListener(new SPCListener
(Integer.parseInt(serverDTO.getId())));
proceso = new Thread(server);
proceso.start();


----------------------------------------
My Own Implementation for ISOChannel
---------------------------------------
public class SPCChannel extends BaseChannel {

public SPCChannel() {
super();
}

/**
* Construct client ISOChannel
* @param host server TCP Address
* @param port server port number
* @param p an ISOPackager
* @param TPDU an optional raw header (i.e. TPDU)
* @see ISOPackager
*/
public SPCChannel(String host, int port, ISOPackager p) {
super(host, port, p);
}

/**
* Construct server ISOChannel
* @param p an ISOPackager
* @param TPDU an optional raw header (i.e. TPDU)
* @exception IOException
* @see ISOPackager
*/
public SPCChannel(ISOPackager p) throws IOException {
super(p);
this.header = null;
}

/**
* constructs server ISOChannel associated with a Server Socket
* @param p an ISOPackager
* @param serverSocket where to accept a connection
* @exception IOException
* @see ISOPackager
*/
public SPCChannel(ISOPackager p, ServerSocket serverSocket)
throws IOException {
super(p, serverSocket);
}

@Override
@SuppressWarnings("empty-statement")
protected byte[] streamReceive() throws IOException {
byte[] b = new byte[2];
String data = "-1";
int longitud = 0;
byte[] r = null;
byte[] tmp = null;
if (isConnected()) {
try {
synchronized (serverIn) {
int available = serverIn.available();
System.out.println("ESTA HABILITADO ? " +
available);
if (available > 0) {
serverIn.read(b, 0, 2);
tmp = new byte[((int) b[0]) - 2];
serverIn.read(tmp, 0, ((int) b[0]) - 2);
r = new byte[((int) b[0])];
r[0] = Integer.toString(tmp.length).getBytes()
[0];
r[1] = Integer.toString(tmp.length).getBytes()
[1];
System.arraycopy(tmp, 0, r, 2, tmp.length);
}
}
} catch (EOFException e) {
e.printStackTrace();
//throw new EOFException("Fallo EOF en streamReceive
"+e.getMessage());
} catch (InterruptedIOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (r == null) {
r = new byte[2];
r[0] = (byte) 0x30;
r[1] = (byte) 0x30;
}
}
}
return r;
}

/**
* sends an ISOMsg over the TCP/IP session
* @param m the Message to be sent
* @exception IOException
* @exception ISOException
* @exception ISOFilter.VetoException;
*/
public void send(ISOMsg m)
throws IOException, ISOException, VetoException {
LogEvent evt = new LogEvent(this, "send");
evt.addMessage(m);
try {
if (!isConnected()) {
throw new ISOException("unconnected ISOChannel");
}
m.setDirection(ISOMsg.OUTGOING);
m = applyOutgoingFilters(m, evt);
m.setDirection(ISOMsg.OUTGOING); // filter may have drop
this info
m.setPackager(getDynamicPackager(m));
byte[] b = m.pack();
byte[] cxrSend = null;
synchronized (serverOut) {
//sendMessageLength(b.length + getHeaderLength());
//sendMessageHeader(m, b.length);
System.out.println("Envia = " + new String(b));
cxrSend = new byte[b.length - 2];
cxrSend[0] = (byte) (b.length - 2);
cxrSend[1] = (byte) 0x04;
System.arraycopy(b, 4, cxrSend, 2, b.length - 4);
System.out.println("Envia = " + new String
(cxrSend));
System.out.println("Enviando = " + ISOUtil.hexdump
(cxrSend));
sendMessage(cxrSend, 0, cxrSend.length);
sendMessageTrailler(m, cxrSend.length);
serverOut.flush();
}
cnt[TX]++;
setChanged();
notifyObservers(m);
} catch (VetoException e) {
evt.addMessage(e);
throw e;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (IOException e) {
evt.addMessage(e);
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException("unexpected exception", e);
} finally {
//disconnect();
Logger.log(evt);
}
}
}

----------------------------------------
My Own ISOPackager
----------------------------------------
public class SPCPackager extends ISOBasePackager {

protected ISOFieldPackager fld[] = {
new IFA_LLCHAR(99, "CAMPO SPC")
};

public SPCPackager() {
super();
setFieldPackager(fld);
}

@Override
protected boolean emitBitMap() {
return false;
}

@Override
protected int getFirstField() {
return 2;
}
/*@Override
protected ISOFieldPackager getBitMapfieldPackager() {
return null;
}*/

Mark Salter

unread,
Mar 24, 2009, 4:31:41 PM3/24/09
to jpos-...@googlegroups.com
Fabio Arias wrote:

> i made this and works, but with the POS disconnect, the server
> continue receive a data zero all time.

Calling serverIn.available() is - I fear - counter productive.

Better I think that the serverIn.read(b,0,2) blocks until data arrives.

If nothing is available then won't your code fall through to the
finally, which builds a two byte[] of :-

byte[] {0x30,0x30)

into r for the return?

Are these the ASCII c'00' you are seeing? I would have thought you
would see c'00' arriving whenever the server was not receiving data
though, not just after the POS disconnects as the isConnected would
start returning false if the connection was severed?

--
Mark

Fabio Arias

unread,
Mar 24, 2009, 4:43:26 PM3/24/09
to jPOS Users
Mark, 'r' variable return, i push 0x30,0x30 just for say the data is
zero, but doesnt works, the ISOField is IFA_LLCHAR thats mean two
first bytes got the long of data, because i convert the original data
to the format ISOField. But the problem isnt that, else, when the
response is sending for POS the server, i dont know how, receive data
zero.


-----------------------
log
-----------------------
FORMATTERS : {3=com.brainwinner.dto.FormatterDTO@c9ba38,
200001=com.brainwinner.dto.FormatterDTO@1e0be38,
1=com.brainwinner.dto.FormatterDTO@1e859c0,
5=com.brainwinner.dto.FormatterDTO@15c7850}
<log realm="iso-bwg-server-CBC" at="Tue Mar 24 15:46:45 COT 2009.593">
<iso-server>
listening on port 8000
</iso-server>
</log>
<log realm="iso-bwg-server-SPC" at="Tue Mar 24 15:46:45 COT 2009.796">
<iso-server>
listening on port 7776
</iso-server>
</log>
<log realm="iso-bwg-server-SPC.session/127.0.0.1" at="Tue Mar 24
15:46:59 COT 2009.156">
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
<session-start/>
</log>
Data ISO 7204|154659|14784|2124|3852|20090324154659|121212|266|
10000.00|3124567890|
<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.171">
<receive>
<isomsg direction="incoming">
<field id="0" value="04|154659|14784|2124|3852|20090324154659|
121212|266|10000.00|3124567890|"/>
</isomsg>
</receive>
</log>
Transaccion
data = < 04|154659|14784|2124|3852|20090324154659|121212|266|10000.00|
3124567890|
Envia = 0604007|
Envia = 007|
Enviando = 0000 06 04 30 30 37
7C ..007|

Data ISO 00
<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.187">
<receive>
<isomsg direction="incoming">
<field id="0" value=""/>
</isomsg>
</receive>
</log>
Transaccion
data = <
<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.203">
<send>
<isomsg direction="outgoing">
<field id="0" value="04007|"/>
</isomsg>
</send>
</log>
Envia = 0604007|
Envia = 007|
Enviando = 0000 06 04 30 30 37
7C ..007|

<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.453">
<send>
<isomsg direction="outgoing">
<field id="0" value="04007|"/>
</isomsg>
</send>
</log>
at com.brainwinner.net.server.SPCChannel.streamReceive
(SPCChannel.java:77)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:492)
at org.jpos.iso.ISOServer$Session.run(ISOServer.java:123)
Data ISO 00
<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.968">
<receive>
<isomsg direction="incoming">
<field id="0" value=""/>
</isomsg>
</receive>
</log>
Transaccion
data = <
Envia = 0604007|
Envia = 007|
Enviando = 0000 06 04 30 30 37
7C ..007|

<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:46:59 COT 2009.984">
<send>
<isomsg direction="outgoing">
<field id="0" value="04007|"/>
</isomsg>
<exception name="Software caused connection abort: socket write
error">
java.net.SocketException: Software caused connection abort: socket
write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite
(SocketOutputStream.java:92)
at org.jpos.util.ThreadPool$PooledThread.run(ThreadPool.java:
100)
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at com.brainwinner.net.server.SPCChannel.streamReceive
(SPCChannel.java:77)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:492)
at org.jpos.iso.ISOServer$Session.run(ISOServer.java:123)
at org.jpos.util.ThreadPool$PooledThread.run(ThreadPool.java:
100)
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at com.brainwinner.net.server.SPCChannel.streamReceive
(SPCChannel.java:77)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:492)
at org.jpos.iso.ISOServer$Session.run(ISOServer.java:123)
at org.jpos.util.ThreadPool$PooledThread.run(ThreadPool.java:
100)
at java.net.SocketOutputStream.write(SocketOutputStream.java:
136)
at java.io.BufferedOutputStream.flushBuffer
(BufferedOutputStream.java:65)
java.io.EOFException
at java.io.BufferedOutputStream.flush
(BufferedOutputStream.java:123)
at java.io.DataOutputStream.flush(DataOutputStream.java:106)
at com.brainwinner.net.server.SPCChannel.send(SPCChannel.java:
136)
at com.brainwinner.net.listener.SPCListener$Process.run
(SPCListener.java:77)
at org.jpos.util.ThreadPool$PooledThread.run(ThreadPool.java:
100)
</exception>
</send>
</log>
Data ISO 00
<log realm="iso-bwg-server-SPC.channel//127.0.0.1:3380" at="Tue Mar 24
15:47:00 COT 2009.750">
<receive>
<isomsg direction="incoming">
<field id="0" value=""/>
</isomsg>
</receive>
</log>
Data ISO 00
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at com.brainwinner.net.server.SPCChannel.streamReceive
(SPCChannel.java:77)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:492)
at org.jpos.iso.ISOServer$Session.run(ISOServer.java:123)
at org.jpos.util.ThreadPool$PooledThread.run(ThreadPool.java:
100)
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)

Mark Salter

unread,
Mar 24, 2009, 5:14:01 PM3/24/09
to jpos-...@googlegroups.com
Fabio Arias wrote:
> Mark, 'r' variable return, i push 0x30,0x30 just for say the data is
> zero, but doesnt works,
So returning the c'00' is an attempt to improve things, but it doesn't help?

I have to admit I am lost...

> the ISOField is IFA_LLCHAR thats mean two
> first bytes got the long of data, because i convert the original data
> to the format ISOField. But the problem isnt that, else, when the
> response is sending for POS the server, i dont know how, receive data
> zero.

Ok, I think there is more to the exchange of messages than I can
currently see from your postings. You are presenting a lot of
information, but it is hard to see what might be pertinent to your
problem, or what your problem actually is.

Can you state what the problem is please?

Can you also describe the POS devices activities step by step, including
making and breaking the connection to your server? Collating the
relevant trace data from your debugging output for each step might also
help.

Does the POS device see any of your response at all? Does it like what
it sees or not? It does look like the connection might be being severed
after or during your response write, but do you have two Exception
overlaying each other in your output - the write failing and a read
falling as the connection is severed?

--
Mark

Reply all
Reply to author
Forward
0 new messages