Search in sources :

Example 51 with ISOException

use of org.jpos.iso.ISOException in project jPOS by jpos.

the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException4.

@Test
public void testValidateThrowsISOException4() throws Throwable {
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(false);
    msgVlds[1] = new MSGTEST();
    msgVlds[2] = new TEST0100(true);
    ISOValidator[] fvlds = new ISOFieldValidator[3];
    ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
    iSOBaseValidatingPackager.setFieldValidator(fvlds);
    iSOBaseValidatingPackager.setMsgValidator(msgVlds);
    try {
        iSOBaseValidatingPackager.validate(new ISOMsg());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "MTI not available", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : MSGTEST(org.jpos.iso.validator.MSGTEST) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) TEST0100(org.jpos.iso.validator.TEST0100) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 52 with ISOException

use of org.jpos.iso.ISOException in project jPOS by jpos.

the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException6.

@Test
public void testValidateThrowsISOException6() throws Throwable {
    ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[0] = new MSGTEST(true);
    ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
    fvlds[0] = iVA_ALPHANUMNOBLANK;
    ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
    iSOBaseValidatingPackager.setFieldValidator(fvlds);
    iSOBaseValidatingPackager.setMsgValidator(msgVlds);
    try {
        iSOBaseValidatingPackager.validate(new ISOMsg());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
        assertFalse("ex.treated()", ((ISOVException) ex).treated());
        assertNotNull("ex.getErrComponent()", ((ISOVException) ex).getErrComponent());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : IVA_ALPHANUMNOBLANK(org.jpos.iso.IVA_ALPHANUMNOBLANK) MSGTEST(org.jpos.iso.validator.MSGTEST) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOVException(org.jpos.iso.validator.ISOVException) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 53 with ISOException

use of org.jpos.iso.ISOException in project jPOS by jpos.

the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException3.

@Test
public void testValidateThrowsISOException3() throws Throwable {
    ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
    ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
    msgVlds[2] = new TEST0100(true);
    ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
    fvlds[0] = iVA_ALPHANUMNOBLANK;
    ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
    iSOBaseValidatingPackager.setFieldValidator(fvlds);
    iSOBaseValidatingPackager.setMsgValidator(msgVlds);
    try {
        iSOBaseValidatingPackager.validate(new ISOMsg());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "MTI not available", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : IVA_ALPHANUMNOBLANK(org.jpos.iso.IVA_ALPHANUMNOBLANK) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) TEST0100(org.jpos.iso.validator.TEST0100) ISOFieldValidator(org.jpos.iso.ISOFieldValidator) Test(org.junit.Test)

Example 54 with ISOException

use of org.jpos.iso.ISOException in project jPOS by jpos.

the class TLVList method getTLVMsg.

/**
 * Read next TLV Message from stream and return it
 * @param buffer the buffer
 * @return TLVMsg
 */
private TLVMsg getTLVMsg(ByteBuffer buffer) throws ISOException {
    // tag = 0 if tag not found
    int tag = getTAG(buffer);
    if (tag == 0)
        return null;
    // Get Length if buffer remains!
    if (!buffer.hasRemaining())
        throw new ISOException(String.format("BAD TLV FORMAT - tag (%x)" + " without length or value", tag));
    int length = getValueLength(buffer);
    if (length > buffer.remaining())
        throw new ISOException(String.format("BAD TLV FORMAT - tag (%x)" + " length (%d) exceeds available data.", tag, length));
    byte[] arrValue = new byte[length];
    buffer.get(arrValue);
    return getTLVMsg(tag, arrValue);
}
Also used : ISOException(org.jpos.iso.ISOException)

Example 55 with ISOException

use of org.jpos.iso.ISOException in project jPOS by jpos.

the class TagSequenceBase method readFrom.

@Override
public synchronized void readFrom(ISOMsg isoMsg) throws ISOException {
    int maxField = isoMsg.getMaxField();
    int minField = -1;
    for (int i = 0; i <= maxField; i++) {
        ISOComponent child = isoMsg.getComponent(i);
        if (child instanceof ISOTaggedField) {
            minField = i;
            break;
        }
    }
    if (minField == -1) {
        // No TaggedFields to read
        return;
    }
    for (int i = minField; i <= maxField; i++) {
        ISOComponent child = isoMsg.getComponent(i);
        if (child != null) {
            if (child instanceof ISOTaggedField) {
                TagValue tagValue;
                ISOTaggedField taggedSubField = (ISOTaggedField) child;
                ISOComponent delegate = taggedSubField.getDelegate();
                if (delegate instanceof ISOMsg) {
                    Map subChildren = delegate.getChildren();
                    boolean allTaggedValue = true;
                    for (Object subChild : subChildren.values()) {
                        if (!(subChild instanceof ISOTaggedField)) {
                            allTaggedValue = false;
                            break;
                        }
                    }
                    if (allTaggedValue) {
                        tagValue = createTagValueSequence(taggedSubField.getTag());
                        ((TagSequence) tagValue).readFrom((ISOMsg) delegate);
                    } else {
                        tagValue = new ISOMsgTagValue(getTag(), isoMsg);
                    }
                } else if (delegate instanceof ISOBinaryField) {
                    tagValue = createBinaryTagValuePair(taggedSubField.getTag(), taggedSubField.getBytes());
                } else if (delegate instanceof ISOField) {
                    tagValue = createLiteralTagValuePair(taggedSubField.getTag(), taggedSubField.getValue().toString());
                } else {
                    throw new ISOException("Unknown ISOComponent subclass in ISOTaggedField: " + delegate.getClass());
                }
                this.add(tagValue);
            } else {
                throw new ISOException("Children after first ISOTaggedField should be instance of ISOTaggedField." + " Field " + i + " is not an ISOTaggedField");
            }
        }
    }
}
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) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

ISOException (org.jpos.iso.ISOException)66 Test (org.junit.Test)36 ISOMsg (org.jpos.iso.ISOMsg)29 ISOField (org.jpos.iso.ISOField)15 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)12 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)8 IOException (java.io.IOException)7 ISOBinaryField (org.jpos.iso.ISOBinaryField)7 TEST0100 (org.jpos.iso.validator.TEST0100)7 Map (java.util.Map)6 ConfigurationException (org.jpos.core.ConfigurationException)6 ISOComponent (org.jpos.iso.ISOComponent)6 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LogEvent (org.jpos.util.LogEvent)5 SAXParseException (org.xml.sax.SAXParseException)5 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)4 ISOVException (org.jpos.iso.validator.ISOVException)4 ISOTaggedField (org.jpos.tlv.ISOTaggedField)4 ArrayList (java.util.ArrayList)3