问题
I'm trying to write a main that packs and unpacks an ISOMessage using jpos framework.
The problem is that my message contains some sub_fields like field 48, and i keep getting it as null value.
Down below my configuration + the main program
Packager
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE isopackager PUBLIC
"-//jPOS/jPOS Generic Packager DTD 1.0//EN"
"http://jpos.org/dtd/generic-packager-1.0.dtd">
<!-- ISO 8583:1993 (ASCII) field descriptions for GenericPackager -->
<isopackager>
<isofield id="0" length="4" name="Message Type Indicator"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="1" length="64" name="Bitmap" class="org.jpos.iso.IFA_BITMAP" />
<isofield id="2" length="19" name="PRIMARY ACCOUNT NUMBER"
class="org.jpos.iso.IFA_LLNUM" />
<isofield id="3" length="6" name="PROCESSING CODE" class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="4" length="12" name="AMOUNT, TRANSACTION" class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="7" length="10" name="DATE AND TIME, TRANSMISSION"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="11" length="6" name="Systems trace audit number"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="12" length="6" name="Time, Local transaction"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="13" length="4" name="Date, Local transaction"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="14" length="4" name="Date, Expiration" class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="18" length="4" name="Merchant type" class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="22" length="4" name="Point of service entry mode code"
class="org.jpos.iso.IFA_NUMERIC" />
<isofield id="25" length="2" name="POS Condition code" class="org.jpos.iso.IFA_NUMERIC" ></isofield>
<isofield id="41" length="8"
name="Card acceptor terminal identification" class="org.jpos.iso.IF_CHAR" ></isofield>
<isofield id="42" length="15" name="Card acceptor identification code"
class="org.jpos.iso.IF_CHAR" />
<isofieldpackager id="48"
length="255"
name="Additional private data"
class="org.jpos.iso.IFA_LLLNUM"
emitBitmap="false"
packager="org.jpos.iso.packager.GenericSubFieldPackager">
<isofield
id="1"
length="8"
name="PSP Identifier"
class="org.jpos.iso.IFA_NUMERIC"/>
<isofield
id="2"
length="8"
name="Ecommerce Acquirer Identifier"
class="org.jpos.iso.IFA_NUMERIC"/>
</isofieldpackager>
<isofield id="49" length="3" name="Currency Code, Transaction"
class="org.jpos.iso.IFA_NUMERIC" />
</isopackager>
main.java
public static void main(String[] args) throws ISOException {
IServicesUtils service = new ServiceUtilsImpl();
String filePackager = (String) service
.getValuesFromPropertiesFile(new String[] { IConstants.DEMO_PACKAGER_LOCATION },
"parameters.properties")
.get(IConstants.DEMO_PACKAGER_LOCATION);
GenericPackager packager = new GenericPackager(filePackager);
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("1100");
isoMsg.set("2", "1111110000000010");
isoMsg.set("3", "000000");
isoMsg.set("4", StringUtils.leftPad("116.0", 12, "0"));
isoMsg.set("7", DateUtils.getTransmissionDate(new Date()));
isoMsg.set("11", service.generateSTAN());
isoMsg.set("12", DateUtils.getField12Iso("1207"));
isoMsg.set("13", DateUtils.getField13Iso("1105"));
isoMsg.set("14", "0808");
isoMsg.set("18", "3306");
isoMsg.set("22", "....");
isoMsg.set("25", "59");
isoMsg.set("41", "59002300");
isoMsg.set("42", "111110000012345");
isoMsg.set("48", "111110000077658");
isoMsg.set("48.1", "00221166");
isoMsg.set("49", "804");
logISOMsg(isoMsg);
byte[] data = isoMsg.pack();
logger.info("RESULT : " + new String(data));
}
private static void logISOMsg(ISOMsg msg) {
System.out.println("----ISO MESSAGE-----");
try {
System.out.println(" MTI : " + msg.getMTI());
for (int i = 1; i <= msg.getMaxField(); i++) {
if (msg.hasField(i)) {
logger.info(" Field-" + i + " : " + msg.getString(i));
}
}
} catch (ISOException e) {
e.printStackTrace();
} finally {
System.out.println("--------------------");
}
}
This main prints all the field except field 48, it returns null value. don't know why, is there a problem at packaging level, or something else.
回答1:
Your outer packager for field 48 has to be of binary class, i.e. IFA_LLLBINARY or IFB_LLLBINARY depending on your spec. You may have to add the firstField
attribute and set it to 1 if there's no field 0. As an alternative, you can define field 0 as IF_NOP
(no operation).
来源:https://stackoverflow.com/questions/43051329/packing-subfields-using-jpos-api