Search in sources :

Example 1 with ISOMsg

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++;
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg)

Example 2 with ISOMsg

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;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOMsg(org.jpos.iso.ISOMsg) TLVDataFormat(org.jpos.tlv.TLVDataFormat)

Example 3 with ISOMsg

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;
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg)

Example 4 with ISOMsg

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);
    }
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) SpaceSource(org.jpos.space.SpaceSource) ISOSource(org.jpos.iso.ISOSource)

Example 5 with ISOMsg

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);
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) LogChannel(org.jpos.iso.channel.LogChannel) Test(org.junit.Test)

Aggregations

ISOMsg (org.jpos.iso.ISOMsg)223 Test (org.junit.Test)191 LogEvent (org.jpos.util.LogEvent)41 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)30 ISOException (org.jpos.iso.ISOException)29 ISOComponent (org.jpos.iso.ISOComponent)25 ISOVMsg (org.jpos.iso.ISOVMsg)22 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)21 Context (org.jpos.transaction.Context)20 ISOValidator (org.jpos.iso.ISOValidator)18 Result (org.jpos.rc.Result)17 SimpleConfiguration (org.jpos.core.SimpleConfiguration)15 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)12 TEST0100 (org.jpos.iso.validator.TEST0100)12 FileInputStream (java.io.FileInputStream)9 Vector (java.util.Vector)9 PostChannel (org.jpos.iso.channel.PostChannel)9 MSGTEST (org.jpos.iso.validator.MSGTEST)9 MSGTEST02 (org.jpos.iso.validator.MSGTEST02)9 ISOFilter (org.jpos.iso.ISOFilter)8