tilln / jmeter-iso8583

ISO8583 Plugin for JMeter
MIT License
62 stars 32 forks source link

ISO8583 Request Listener BSH script to set particular EMV tag value in DE55 #97

Closed ManojhM-1530 closed 3 months ago

ManojhM-1530 commented 3 months ago

Hi @tilln ,

Requesting a solution for the ISO-8583, In request DE55 has more EMV tags but in expected response I need only "9F36" Tag alone in my response. Can you please help to configure in responder BSH script to set particular EMV tag value for DE55.

Request message : 55 : Length (binary) x62 - 98 Type 01 00 5F - length 95 9F33 : 03 XXXXXX 95 : 05 XXXXXXXXXX 9F37 : 04 XXXXXXXX 9F10 : 07 XXXXXXXXXXXXXX 9F26 : 08 XXXXXXXXXXXXXXXX 9F36 : 02 XXXX 82 : 02 XXXX 9C : 01 XX 9F1A : 02 XXXX 9A : 03 XXXXXX 9F02 : 06 XXXXXXXXXXXX 5F2A : 02 XXXX 9F03 : 06 XXXXXXXXXXXX 84 : 07 XXXXXXXXXXXXXX

Expected Response message : 55 : Length (binary) x08 - 8 Type 01 00 05 - length 5 9F36 : 02 XXXX

This is the BSH script file for Request Listener.

if ("0100".equals(message.getMTI())) { message.setResponseMTI(); message.set(55,"9F3602XXXX"); source.send(message); }

By using the above BSH code getting error as

"ERROR n.c.b.j.i.Q2: (channel/.**..*:92) [receive] org.jpos.iso.IFB_LLLHBINARY: Problem unpacking field 0 (org.jpos.iso.ISOException: Field length 17971 too long. Max: 254) unpacking field=55, consumed=91 org.jpos.iso.ISOException: org.jpos.iso.IFB_LLLHBINARY: Problem unpacking field 0 (org.jpos.iso.ISOException: Field length 17971 too long. Max: 254) unpacking field=55, consumed=91"

tilln commented 3 months ago

When you set DE55 in your responder script, you may have to prefix it with the length, type etc. as per

Expected Response message : 55 : Length (binary) x08 - 8 Type 01 00 05 - length 5

Also, depending on your packager, setting the field value as a Hex-string only works for ISOBinaryFieldPackager fields, so perhaps you need to use set(int fldno, byte[] value) instead of message.set(55,"9F3602XXXX");.

You'll have to share at least your packager definition and ideally your whole script, otherwise I can only guess what's wrong.

ManojhM-1530 commented 3 months ago

Hi @tilln,

This is the packager file for field 55,

image

This is the JMX script,

image

And there is any way to message.unset(XX) a particular EMV tag field in DE55.

tilln commented 3 months ago

How about something like this:

if (message.getMTI() == '0100') {
    message.setResponseMTI()

    def emv = new org.jpos.tlv.TLVList()
    emv.unpack(message.getComponent('55.2').pack()) // parse EMV tag fields

    [0x9F36, 0x95, /*etc*/ ].each { emv.deleteByTag(it) } // keep required fields only

    emv.append(0x9F36, 'XXXX') // add new fields

    message.set('55.2', emv.pack())
    source.send(message)
}
ManojhM-1530 commented 3 months ago

Hi @tilln ,

Thank you for your response. The provided BSH code is functioning correctly, and I am able to add or remove the necessary EMV tags as needed.

I sincerely appreciate your valuable advice.

Regards, Manojh

ManojhM-1530 commented 3 months ago

Hi @tilln ,

For Field 55 facing difficulty on BSH file,

This is the sampler Request , image

The Packager we used for field 55, image

I try this method but can't able to unpack image

Please help us to resolve the issue...

tilln commented 3 months ago

What's the error message please?

tilln commented 3 months ago

I've just spotted the proprietary tags DF15 and DF16 in your sampler. So presumably you are getting something like org.jpos.emv.UnknownTagNumberException: df15

You will have to extend the jPOS classes as in the example below.

package org.jpos.tlv.packager.bertlv;

import org.jpos.emv.EMVProprietaryTagType;
import org.jpos.emv.UnknownTagNumberException;

public class CustomICCBERTLVFormatMapper extends DefaultICCBERTLVFormatMapper {

    public static CustomICCBERTLVFormatMapper INSTANCE = new CustomICCBERTLVFormatMapper();

    protected EMVProprietaryTagType getProprietaryTagType(Integer tagNumber) throws UnknownTagNumberException {
        if (tagNumber == 0xdf15) {
            return new EMVProprietaryTagTypeDF15();
        }
        return super.getProprietaryTagType(tagNumber);
    }

}
package org.jpos.tlv.packager.bertlv;

import org.jpos.iso.ISOException;

public class CustomBERTLVBinaryPackager extends BERTLVBinaryPackager {

    static { setTagFormatMapper(CustomICCBERTLVFormatMapper.INSTANCE); }

    public CustomBERTLVBinaryPackager() throws ISOException {
        super();
    }
}
package org.jpos.tlv.packager.bertlv;

import org.jpos.emv.*;
import org.jpos.iso.ISOUtil;
import org.jpos.tlv.TLVDataFormat;

public class EMVProprietaryTagTypeDF15 implements EMVProprietaryTagType {
    final static int tagNumber = 0xDF15;

    public int getTagNumber() { return tagNumber; }
    public String getTagShortDescription() { return "..."; }
    public String getTagDescription() { return "..."; }
    public DataSource getSource() { return DataSource.ISSUER; } // or DataSource.TERMINAL or DataSource.ICC
    public TLVDataFormat getFormat() { return TLVDataFormat.BINARY; } // refer https://github.com/jpos/jPOS/blob/v2_1_8/jpos/src/main/java/org/jpos/tlv/TLVDataFormat.java
    public DataLength getDataLength() { return new FixedDataLength(4); } // whatever your length
    public ByteLength getByteLength() { return new FixedByteLength(2); } // whatever your packed length
    public boolean isProprietaryFormat() { return true; }
    public String getTagNumberHex() { return Integer.toHexString(tagNumber).toUpperCase(); }
    public byte[] getTagNumberBytes() { return ISOUtil.int2byte(tagNumber); }
    public Class<?> getDataType() throws ProprietaryFormatException { return byte[].class; } // assuming binary
    public boolean isProprietaryTag() { return true; }

}
ManojhM-1530 commented 3 months ago

Hi @tilln,

Thank you for your response. The org.jpos.emv.UnknownTagNumberException: df15 has resolved.

Regards, Manojh