use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class TagSequenceBase method writeTo.
@Override
public synchronized void writeTo(ISOMsg isoMsg) throws ISOException {
int maxField = isoMsg.getMaxField();
List<TagValue> tagValueList = getOrderedList();
int fieldNumber = 0;
for (TagValue tagValue : tagValueList) {
Object value = tagValue.getValue();
if (value != null) {
ISOComponent subField;
if (value instanceof byte[]) {
subField = new ISOBinaryField(fieldNumber + maxField + 1, (byte[]) value);
} else if (value instanceof String) {
subField = new ISOField(fieldNumber + maxField + 1, (String) value);
} else if (value instanceof TagSequence) {
TagSequence subSequence = (TagSequence) tagValue;
subField = new ISOMsg(fieldNumber + maxField + 1);
subSequence.writeTo((ISOMsg) subField);
} else if (value instanceof ISOMsg) {
ISOMsgTagValue subSequence = (ISOMsgTagValue) tagValue;
subField = subSequence.getValue();
subField.setFieldNumber(fieldNumber + maxField + 1);
} else {
throw new ISOException("Unknown TagValue subclass: " + tagValue.getClass());
}
isoMsg.set(new ISOTaggedField(tagValue.getTag(), subField));
}
fieldNumber++;
}
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class BERTLVPackager method unpackValue.
private ISOComponent unpackValue(String tagNameHex, final byte[] tlvData, int subFieldNumber, int dataLength) throws ISOException, UnknownTagNumberException {
final int tagNumber = Integer.parseInt(tagNameHex, 16);
final TLVDataFormat dataFormat = getTagFormatMapper().getFormat(tagNumber);
ISOComponent value;
String unpackedValue;
int uninterpretLength;
switch(dataFormat) {
case COMPRESSED_NUMERIC:
uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterRightPaddedF);
unpackedValue = bcdInterpreterRightPaddedF.uninterpret(tlvData, 0, uninterpretLength);
if (unpackedValue.length() > 1 && unpackedValue.charAt(unpackedValue.length() - 1) == 'F') {
unpackedValue = unpackedValue.substring(0, unpackedValue.length() - 1);
}
value = new ISOField(subFieldNumber, unpackedValue);
break;
case PACKED_NUMERIC:
case PACKED_NUMERIC_DATE_YYMMDD:
case PACKED_NUMERIC_TIME_HHMMSS:
uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterLeftPaddedZero);
unpackedValue = bcdInterpreterLeftPaddedZero.uninterpret(tlvData, 0, uninterpretLength);
if (unpackedValue.length() > 1 && unpackedValue.charAt(0) == '0') {
unpackedValue = unpackedValue.substring(1);
}
value = new ISOField(subFieldNumber, unpackedValue);
break;
case ASCII_NUMERIC:
case ASCII_ALPHA:
case ASCII_ALPHA_NUMERIC:
case ASCII_ALPHA_NUMERIC_SPACE:
case ASCII_ALPHA_NUMERIC_SPECIAL:
uninterpretLength = getUninterpretLength(dataLength, asciiInterpreter);
unpackedValue = asciiInterpreter.uninterpret(tlvData, 0, uninterpretLength);
value = new ISOField(subFieldNumber, unpackedValue);
break;
case BINARY:
case PROPRIETARY:
value = new ISOBinaryField(subFieldNumber, tlvData);
break;
case CONSTRUCTED:
value = new ISOMsg(subFieldNumber);
unpack(value, tlvData, true);
break;
default:
throw new IllegalArgumentException("Unknown TLVDataFormat: " + dataFormat);
}
return value;
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class SelectDestination method prepare.
@Override
public int prepare(long id, Serializable context) {
Context ctx = (Context) context;
ISOMsg m = (ISOMsg) ctx.get(requestName);
boolean destinationSet = false;
if (m != null && (m.hasField(2) || m.hasField(35))) {
try {
Card card = Card.builder().validator(validator).isomsg(m).build();
String destination = getDestination(card);
if (destination != null) {
ctx.put(destinationName, destination);
destinationSet = true;
}
} catch (InvalidCardException ex) {
return ctx.getResult().fail(CMF.INVALID_CARD_OR_CARDHOLDER_NUMBER, Caller.info(), ex.getMessage()).FAIL();
}
}
if (!destinationSet && ctx.get(destinationName) == null)
ctx.put(destinationName, defaultDestination);
if (failOnNoRoute && ctx.get(destinationName) == null)
return ctx.getResult().fail(CMF.ROUTING_ERROR, Caller.info(), "No routing info").FAIL();
return PREPARED | NO_JOIN | READONLY;
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class SendResponse method sendResponse.
private void sendResponse(long id, Context ctx) {
ISOSource src = (ISOSource) ctx.get(source);
ISOMsg m = (ISOMsg) ctx.get(request);
ISOMsg resp = (ISOMsg) ctx.get(response);
try {
if (ctx.getResult().hasInhibit()) {
ctx.log("*** RESPONSE INHIBITED ***");
} else if (ctx.get(TX.toString()) != null) {
ctx.log("*** PANIC - TX not null - RESPONSE OMITTED ***");
} else if (resp == null) {
ctx.log(response + " not present");
} else if (src == null) {
ctx.log(source + " not present");
} else if (!src.isConnected())
ctx.log(source + " is no longer connected");
else {
if (src instanceof SpaceSource)
((SpaceSource) src).init(isp, timeout);
if (src.isConnected() && resp != null) {
headerStrategy.handleHeader(m, resp);
src.send(resp);
}
}
} catch (Throwable t) {
ctx.log(t);
}
}
use of org.jpos.iso.ISOMsg in project jPOS by jpos.
the class BSHRequestListenerTest method testProcess2.
@Test
public void testProcess2() throws Throwable {
BSHRequestListener bSHRequestListener = new BSHRequestListener();
ISOMsg m = new ISOMsg();
m.setMTI("testBSHRequestListenerMti");
boolean result = bSHRequestListener.process(new LogChannel(), m);
assertFalse("result", result);
assertNull("bSHRequestListener.whitelist", bSHRequestListener.whitelist);
}
Aggregations