-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support headers with different header length #13
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import org.jpos.iso.ISOPackager; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
@@ -44,7 +45,7 @@ | |
public class ISO8583MessageHandler { | ||
private static final Log log = LogFactory.getLog(ISO8583MessageHandler.class); | ||
|
||
public ISO8583MessageHandler(MessageContext messageContext, String details, String host, int port) { | ||
public ISO8583MessageHandler(MessageContext messageContext, byte[] details, String host, int port) { | ||
try { | ||
Socket socket = new Socket(host, port); | ||
clientHandler(messageContext, socket, details); | ||
|
@@ -56,28 +57,31 @@ public ISO8583MessageHandler(MessageContext messageContext, String details, Stri | |
/** | ||
* handle the iso8583 message request and responses | ||
* | ||
* @param isoMessage packed ISOMessage | ||
* @param connection Socket connection with backend Test server | ||
* @param messageContext the message context | ||
* @param connection Socket connection with backend Test server | ||
* @param isoMessage packed ISOMessage | ||
*/ | ||
public void clientHandler(MessageContext messageContext, Socket connection, String isoMessage) { | ||
public void clientHandler(MessageContext messageContext, Socket connection, byte[] isoMessage) { | ||
DataOutputStream outStream = null; | ||
BufferedReader inFromServer = null; | ||
String message; | ||
DataInputStream inFromServer = null; | ||
try { | ||
outStream = new DataOutputStream(connection.getOutputStream()); | ||
inFromServer = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
inFromServer = new DataInputStream(connection.getInputStream()); | ||
if (connection.isConnected()) { | ||
outStream.writeUTF(isoMessage); | ||
outStream.write(isoMessage); | ||
outStream.flush(); | ||
|
||
/* Sender will receive the Acknowledgement here */ | ||
if ((message = inFromServer.readLine()) != null) { | ||
unpackResponse(messageContext, message); | ||
} | ||
Thread.sleep(200); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you put 200 sleep here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will take time to get the response from the back end in the input stream buffer. That's why I put. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check without it ... |
||
int messageLength = inFromServer.available(); | ||
byte[] message = new byte[messageLength]; | ||
inFromServer.readFully(message, 0, messageLength); | ||
unpackResponse(messageContext, message); | ||
} | ||
} catch (IOException e) { | ||
handleException("An exception occurred in sending the iso8583 message", e); | ||
} catch (InterruptedException e) { | ||
handleException("An exception occurred in reading the iso8583 message", e); | ||
} finally { | ||
try { | ||
if (outStream != null) { | ||
|
@@ -94,18 +98,18 @@ public void clientHandler(MessageContext messageContext, Socket connection, Stri | |
} | ||
|
||
/** | ||
* unpack the response string of isoMessage | ||
* unpack the response byte of isoMessage | ||
* | ||
* @param message response String of isoMessage | ||
* @param messageContext the message context | ||
* @param message response byte of isoMessage | ||
*/ | ||
public void unpackResponse(MessageContext messageContext, String message) { | ||
public void unpackResponse(MessageContext messageContext, byte[] message) { | ||
try { | ||
int headerLength = getHeaderLength(messageContext); | ||
ISOPackager packager = ISO8583PackagerFactory.getPackager(headerLength); | ||
ISOMsg isoMsg = new ISOMsg(); | ||
isoMsg.setPackager(packager); | ||
isoMsg.unpack(message.getBytes()); | ||
isoMsg.unpack(message); | ||
messageBuilder(messageContext, isoMsg); | ||
} catch (ISOException e) { | ||
handleException("Couldn't unpack the message since message is not in ISO Standard :" + message, e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore it is wrong to close connection in this finally block. It should be closed by the method who creates it in it's finally block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved