Search code examples
javaiso8583j8583

How to generate an ISO message in j8583


I have text data,

PROCESSINGCODE: 000000
SYSTEMTRACEAUDITNUMBER: 000001
Cardacceptorterminalidentification:3239313130303031
Reservednational:001054455354204D45535347
Networkmanagementinformationcode:0301

I need to generate an ISO Message with bitmap fields using j8583 project.

I have tried parsing a isomesssage, but I do not know how to generate an ISO Message.

Note: I know that this can be done with jpos, but I need to do it with j8583.

I have created below program.

public static void main(String[] args) {


MessageFactory<IsoMessage> mf = new MessageFactory<IsoMessage>();
    try {
        //mfact = ConfigParser.createFromClasspathConfig("C:\\Users\\DHEERAJ\\workspace\\j8583.xml");

        String path="C:\\Users\\DHEERAJ\\workspace\\j8583.xml";
        ConfigParser.configureFromUrl(mf, new File(path).toURI().toURL());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  
        mf.setForceSecondaryBitmap(true);
        mf.setUseBinaryBitmap(true);
        mf.setAssignDate(true);  
        mf.setTraceNumberGenerator(new SimpleTraceGenerator((int)  (System.currentTimeMillis() % 100000)));  
        System.out.println("NEW MESSAGE");  
        IsoMessage m = mf.newMessage(0200); 

       m.setValue(3, "000000", IsoType.ALPHA, 6);  
       m.setValue(11, "000001", IsoType.ALPHA, 6);  
        m.setValue(41, "3239313130303031", IsoType.ALPHA, 16);  
        m.setValue(60, "001054455354204D45535347", IsoType.ALPHA, 24);  
           m.setValue(70, "0301", IsoType.ALPHA, 4);

           m.setForceSecondaryBitmap(true);

}

I have got below output.

V0080¢ € 00000010201245030000013239313130303031001054455354204D455353470301

This output doesn't have bitmap values, and have some unwanted values at start.

Can someone please help with this?

Thanks.


Solution

  • The following Java code prints 0200A220000000800010040000000000000000000010240507450000013239313130303031001054455354204D455353470301, in which you can see the bitmap information.

    import com.solab.iso8583.MessageFactory;
    import com.solab.iso8583.IsoMessage;
    import com.solab.iso8583.IsoType;
    import com.solab.iso8583.parse.ConfigParser;
    import com.solab.iso8583.impl.SimpleTraceGenerator;
    import java.io.File;
    import java.io.IOException;
    
    class Sample {
        public static void main(String[] args) {
            // Check http://j8583.sourceforge.net/javadoc/index.html
    
            MessageFactory<IsoMessage> mf = new MessageFactory<IsoMessage>();
    
            try {
                String path="j8583.xml";
                ConfigParser.configureFromUrl(mf, new File(path).toURI().toURL());
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            mf.setForceSecondaryBitmap(true);
            mf.setUseBinaryBitmap(true);
            mf.setAssignDate(true); // This sets field 7 automatically
            mf.setTraceNumberGenerator(new SimpleTraceGenerator((int)  (System.currentTimeMillis() % 100000)));
    
            IsoMessage m = mf.newMessage(0x200); // You must use 0x200, 0x400, etc.
            m.setValue(3, "000000", IsoType.ALPHA, 6);
            m.setValue(11, "000001", IsoType.ALPHA, 6);
            m.setValue(41, "3239313130303031", IsoType.ALPHA, 16);
            m.setValue(60, "001054455354204D45535347", IsoType.ALPHA, 24);
            m.setValue(70, "0301", IsoType.ALPHA, 4);
            m.setForceSecondaryBitmap(true);
    
            System.out.println(m.debugString());
        }
    }