Search code examples
javajpos

Implementing IFB_LLLLCHAR


We are using jpos server with ASCIChannel and custom package which contains one field with max length 9999. To do this we implemented IFB_LLLLCHAR as follows:

public class IFB_LLLLCHAR extends ISOStringFieldPackager {
    public IFB_LLLLCHAR() {
        super(NullPadder.INSTANCE, AsciiInterpreter.INSTANCE, BcdPrefixer.LLLL);
    }
    
    public IFB_LLLLCHAR(int len, String description) {
        super(len, description, NullPadder.INSTANCE, AsciiInterpreter.INSTANCE, BcdPrefixer.LLLL);
        checkLength(len, 9999);
    }

    public void setLength(int len)
    {
        checkLength(len, 9999);
        super.setLength(len);
    }
}

The problem is that I couldn't use the whole 9999 because if the size of whole message goes over 9999 it throws the following exception while sending it:

<exception name="len exceeded">
    java.io.IOException: len exceeded
    at org.jpos.iso.channel.ASCIIChannel.sendMessageLength(ASCIIChannel.java:80)
    at org.jpos.iso.BaseChannel.send(BaseChannel.java:528)
    at com.advam.gateway.terminalmanagementserver.gateway.LogUploadFuncTest.testLogUpload(LogUploadFuncTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    </exception>

Why am I getting this exception, and how to fix it? I don't have much knowledge about inside of jpos.


Solution

  • The total length of the complete message cannot exceed 9999 using the AsciiChannel (like @gerrytan already pointed out).

    The AsciiChannel assumes a protocol where the first four bytes are the ASCII value of the length digits.

    You might want to look at HEXChannel or NACChannel as they can accommodate larger lengths. HEXChannel and NACChannel allow length up to 0xFFFF.