Search in sources :

Example 1 with BaseHeader

use of org.jpos.iso.header.BaseHeader in project jPOS by jpos.

the class XML2003Packager method startElement.

public void startElement(String ns, String name, String qName, Attributes atts) throws SAXException {
    int fieldNumber = -1;
    try {
        String id = atts.getValue(ID_ATTR);
        if (id != null) {
            try {
                fieldNumber = Integer.parseInt(id);
            } catch (NumberFormatException ex) {
                throw new SAXException("Invalid idr " + id);
            }
        }
        if (name.equals(ISOMSG_TAG)) {
            if (fieldNumber >= 0) {
                if (stk.empty())
                    throw new SAXException("inner without outter");
                ISOMsg inner = new ISOMsg(fieldNumber);
                ((ISOMsg) stk.peek()).set(inner);
                stk.push(inner);
            } else {
                stk.push(new ISOMsg(0));
            }
        } else if (name.equals(ISOFIELD_TAG)) {
            ISOMsg m = (ISOMsg) stk.peek();
            String value = atts.getValue(VALUE_ATTR);
            String type = atts.getValue(TYPE_ATTR);
            if (id == null || value == null)
                throw new SAXException("invalid field");
            if (TYPE_BINARY.equals(type)) {
                m.set(new ISOBinaryField(fieldNumber, ISOUtil.hex2byte(value.getBytes(), 0, value.length() / 2)));
            } else if (TYPE_AMOUNT.equals(type)) {
                ISOAmount amount = new ISOAmount(fieldNumber, Integer.parseInt(atts.getValue(CURRENCY_ATTR)), new BigDecimal(value));
                m.set(amount);
            } else {
                m.set(new ISOField(fieldNumber, value));
            }
        } else if (HEADER_TAG.equals(name)) {
            stk.push(new BaseHeader());
        }
    } catch (ISOException e) {
        throw new SAXException("ISOException unpacking " + fieldNumber);
    }
}
Also used : BaseHeader(org.jpos.iso.header.BaseHeader) BigDecimal(java.math.BigDecimal) SAXException(org.xml.sax.SAXException)

Example 2 with BaseHeader

use of org.jpos.iso.header.BaseHeader in project jPOS by jpos.

the class VAPChannelTest method testSendMessageHeaderThrowsNullPointerException2.

@Test
public void testSendMessageHeaderThrowsNullPointerException2() throws Throwable {
    VAPChannel vAPChannel = new VAPChannel("testVAPChannelHost", 100, new XMLPackager());
    ISOMsg m = new ISOMsg("testVAPChannelMti");
    m.setHeader(new BaseHeader());
    try {
        vAPChannel.sendMessageHeader(m, 100);
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        if (isJavaVersionAtMost(JAVA_14)) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        } else {
            assertEquals("Cannot invoke \"java.io.DataOutputStream.write(byte[])\" because \"this.serverOut\" is null", ex.getMessage(), "ex.getMessage()");
        }
        assertEquals(0, m.getDirection(), "m.getDirection()");
    }
}
Also used : XMLPackager(org.jpos.iso.packager.XMLPackager) BaseHeader(org.jpos.iso.header.BaseHeader) Test(org.junit.jupiter.api.Test)

Example 3 with BaseHeader

use of org.jpos.iso.header.BaseHeader in project jPOS by jpos.

the class ISOMsg2Test method testWriteHeader1.

@Test
public void testWriteHeader1() throws Throwable {
    ISOMsg iSOMsg = new ISOMsg("testISOMsgMti");
    final BaseHeader header = mock(BaseHeader.class);
    iSOMsg.setHeader(header);
    ObjectOutputStream out = mock(ObjectOutputStream.class);
    given(header.getLength()).willReturn(0);
    iSOMsg.writeHeader(out);
    assertSame(header, iSOMsg.header, "iSOMsg.header");
}
Also used : ObjectOutputStream(java.io.ObjectOutputStream) BaseHeader(org.jpos.iso.header.BaseHeader) Test(org.junit.jupiter.api.Test)

Example 4 with BaseHeader

use of org.jpos.iso.header.BaseHeader in project jPOS by jpos.

the class XMLPackager method endElement.

public void endElement(String ns, String name, String qname) throws SAXException {
    if (name.equals(ISOMSG_TAG)) {
        ISOMsg m = (ISOMsg) stk.pop();
        if (stk.empty())
            // push outer message
            stk.push(m);
    } else if (ISOFIELD_TAG.equals(name)) {
        stk.pop();
    } else if (HEADER_TAG.equals(name)) {
        BaseHeader h = (BaseHeader) stk.pop();
        ISOMsg m = (ISOMsg) stk.peek();
        m.setHeader(h);
    }
}
Also used : BaseHeader(org.jpos.iso.header.BaseHeader)

Example 5 with BaseHeader

use of org.jpos.iso.header.BaseHeader in project jPOS by jpos.

the class XMLPackager method startElement.

public void startElement(String ns, String name, String qName, Attributes atts) throws SAXException {
    int fieldNumber = -1;
    try {
        String id = atts.getValue(ID_ATTR);
        if (id != null) {
            try {
                fieldNumber = Integer.parseInt(id);
            } catch (NumberFormatException ex) {
                throw new SAXException("Invalid id " + id);
            }
        }
        if (name.equals(ISOMSG_TAG)) {
            if (fieldNumber >= 0) {
                if (stk.empty())
                    throw new SAXException("inner without outer");
                ISOMsg inner = new ISOMsg(fieldNumber);
                ((ISOMsg) stk.peek()).set(inner);
                stk.push(inner);
            } else {
                stk.push(new ISOMsg(0));
            }
        } else if (name.equals(ISOFIELD_TAG)) {
            ISOMsg m = (ISOMsg) stk.peek();
            String value = atts.getValue(VALUE_ATTR);
            String type = atts.getValue(TYPE_ATTR);
            if (id == null)
                throw new SAXException("invalid field");
            value = value == null ? "" : value;
            ISOComponent ic;
            if (TYPE_BINARY.equals(type)) {
                ic = new ISOBinaryField(fieldNumber, ISOUtil.hex2byte(value.getBytes(), 0, value.length() / 2));
            } else if (TYPE_AMOUNT.equals(type)) {
                ic = new ISOAmount(fieldNumber, Integer.parseInt(atts.getValue(CURRENCY_ATTR)), new BigDecimal(value));
            } else {
                ic = new ISOField(fieldNumber, ISOUtil.stripUnicode(value));
            }
            m.set(ic);
            stk.push(ic);
        } else if (HEADER_TAG.equals(name)) {
            BaseHeader bh = new BaseHeader();
            bh.setAsciiEncoding(ASCII_ENCODING.equalsIgnoreCase(atts.getValue(ENCODING_ATTR)));
            stk.push(bh);
        }
    } catch (ISOException e) {
        throw new SAXException("ISOException unpacking " + fieldNumber);
    }
}
Also used : BaseHeader(org.jpos.iso.header.BaseHeader) BigDecimal(java.math.BigDecimal) SAXException(org.xml.sax.SAXException)

Aggregations

BaseHeader (org.jpos.iso.header.BaseHeader)7 Test (org.junit.jupiter.api.Test)4 BigDecimal (java.math.BigDecimal)2 SAXException (org.xml.sax.SAXException)2 ObjectOutputStream (java.io.ObjectOutputStream)1 LogChannel (org.jpos.iso.channel.LogChannel)1 RawChannel (org.jpos.iso.channel.RawChannel)1 GenericValidatingPackager (org.jpos.iso.packager.GenericValidatingPackager)1 XMLPackager (org.jpos.iso.packager.XMLPackager)1