Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8aa3ec35ad | ||
|
|
2c3d3e8a6d | ||
|
|
3e714d3409 | ||
|
|
ce4f150e8b | ||
|
|
5413998bb6 | ||
|
|
d3245ee728 | ||
|
|
a4f7ec8696 | ||
|
|
629db2304c | ||
|
|
c1c6314144 | ||
|
|
8f498d3551 | ||
|
|
38b161c1c6 | ||
|
|
3b1cf15c3e | ||
|
|
5333413e30 | ||
|
|
3d0749687e | ||
|
|
32dc578814 | ||
|
|
ab740f9efa | ||
|
|
9ecc907739 | ||
|
|
bec6340fe5 | ||
|
|
c9e970904f | ||
|
|
eaab64e73f | ||
|
|
81f178f870 | ||
|
|
8d1e8f389c | ||
|
|
8dd44c4ae3 | ||
|
|
42e17fb036 | ||
|
|
80dd7f78ec | ||
|
|
041c058b33 | ||
|
|
c00ef7b88d | ||
|
|
a05373efec | ||
|
|
5c53676cda | ||
|
|
759ec1497b | ||
|
|
d99279ec7e | ||
|
|
515724bd7e | ||
|
|
59365dae25 | ||
|
|
fd2f9e8103 | ||
|
|
07b277c7fa | ||
|
|
3a4840108d | ||
|
|
8edbad8659 | ||
|
|
2c466a76c5 | ||
|
|
df5c1d7bd2 | ||
|
|
16858e2f42 |
+1
-1
@@ -1,7 +1,7 @@
|
||||
apply plugin:'java'
|
||||
apply plugin: 'maven'
|
||||
defaultTasks 'build'
|
||||
version='1.8.0'
|
||||
version='1.9.1'
|
||||
description='Java implementation of the ISO 8583 protocol, focused on making the creation, edition and reading of ISO8583 messages as simple and flexible as possible.'
|
||||
sourceCompatibility=6
|
||||
targetCompatibility=6
|
||||
|
||||
@@ -98,8 +98,8 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="GradleSettings">
|
||||
<option name="gradleHome" value="$PROJECT_DIR$/../../../gradle-1.4" />
|
||||
<option name="preferLocalInstallationToWrapper" value="true" />
|
||||
<option name="gradleHome" value="$PROJECT_DIR$/../../../gradle-1.8" />
|
||||
<option name="linkedProjectPath" value="" />
|
||||
</component>
|
||||
<component name="GradleUISettings2">
|
||||
<setting name="root" />
|
||||
@@ -271,7 +271,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/j8583.iml" filepath="$PROJECT_DIR$/j8583.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Java 7" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Java 6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="SvnConfiguration" maxAnnotateRevisions="500" myUseAcceleration="nothing" myAutoUpdateAfterCommit="false" cleanupOnStartRun="false">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.sf.j8583</groupId>
|
||||
<artifactId>j8583</artifactId>
|
||||
<version>1.5.8-SNAPSHOT</version>
|
||||
<version>1.9.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>j8583</name>
|
||||
<description>Java implementation of the ISO 8583 protocol, focused on making the creation, edition and reading of ISO8583 messages as simple and flexible as possible.</description>
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583;
|
||||
|
||||
/**
|
||||
|
||||
@@ -262,7 +262,7 @@ public class IsoValue<T> implements Cloneable {
|
||||
} else if (ldiff == 2) {
|
||||
lhead = "00" + lhead;
|
||||
}
|
||||
outs.write(lhead.getBytes(encoding));
|
||||
outs.write(encoding == null ? lhead.getBytes():lhead.getBytes(encoding));
|
||||
} else {
|
||||
//write the length in ASCII
|
||||
if (digits == 3) {
|
||||
|
||||
@@ -423,7 +423,11 @@ public class MessageFactory<T extends IsoMessage> {
|
||||
log.warn("Field {} is not really in the message even though it's in the bitmap", i);
|
||||
bs.clear(i - 1);
|
||||
} else {
|
||||
IsoValue<?> val = fpi.parseBinary(i, buf, pos, getCustomField(i));
|
||||
CustomField<?> decoder = fpi.getDecoder();
|
||||
if (decoder == null) {
|
||||
decoder = getCustomField(i);
|
||||
}
|
||||
IsoValue<?> val = fpi.parseBinary(i, buf, pos, decoder);
|
||||
m.setField(i, val);
|
||||
if (val != null) {
|
||||
if (val.getType() == IsoType.NUMERIC || val.getType() == IsoType.DATE10
|
||||
@@ -450,7 +454,11 @@ public class MessageFactory<T extends IsoMessage> {
|
||||
log.warn("Field {} is not really in the message even though it's in the bitmap", i);
|
||||
bs.clear(i - 1);
|
||||
} else {
|
||||
IsoValue<?> val = fpi.parse(i, buf, pos, getCustomField(i));
|
||||
CustomField<?> decoder = fpi.getDecoder();
|
||||
if (decoder == null) {
|
||||
decoder = getCustomField(i);
|
||||
}
|
||||
IsoValue<?> val = fpi.parse(i, buf, pos, decoder);
|
||||
m.setField(i, val);
|
||||
//To get the correct next position, we need to get the number of bytes, not chars
|
||||
pos += val.toString().getBytes(fpi.getCharacterEncoding()).length;
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583.codecs;
|
||||
|
||||
import com.solab.iso8583.CustomBinaryField;
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.solab.iso8583.codecs;
|
||||
|
||||
import com.solab.iso8583.CustomBinaryField;
|
||||
import com.solab.iso8583.CustomField;
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.IsoValue;
|
||||
import com.solab.iso8583.parse.FieldParseInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A codec to manage subfields inside a field of a certain type.
|
||||
*
|
||||
* @author Enrique Zamudio
|
||||
* Date: 25/11/13 11:25
|
||||
*/
|
||||
public class CompositeField implements CustomBinaryField<CompositeField> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CompositeField.class);
|
||||
/** Stores the subfields. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<IsoValue> values;
|
||||
/** Stores the parsers for the subfields. */
|
||||
private List<FieldParseInfo> parsers;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setValues(List<IsoValue> values) {
|
||||
this.values = values;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<IsoValue> getValues() {
|
||||
return values;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
public CompositeField addValue(IsoValue<?> v) {
|
||||
if (values == null) {
|
||||
values = new ArrayList<IsoValue>(4);
|
||||
}
|
||||
values.add(v);
|
||||
return this;
|
||||
}
|
||||
public <T> CompositeField addValue(T val, CustomField<T> encoder, IsoType t, int length) {
|
||||
return addValue(t.needsLength() ? new IsoValue<T>(t, val, length, encoder)
|
||||
: new IsoValue<T>(t, val, encoder));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> IsoValue<T> getField(int idx) {
|
||||
if (idx < 0 || idx > values.size())return null;
|
||||
return values.get(idx);
|
||||
}
|
||||
public <T> T getObjectValue(int idx) {
|
||||
IsoValue<T> v = getField(idx);
|
||||
return v==null ? null : v.getValue();
|
||||
}
|
||||
|
||||
public void setParsers(List<FieldParseInfo> fpis) {
|
||||
parsers = fpis;
|
||||
}
|
||||
public List<FieldParseInfo> getParsers() {
|
||||
return parsers;
|
||||
}
|
||||
public CompositeField addParser(FieldParseInfo fpi) {
|
||||
if (parsers == null) {
|
||||
parsers = new ArrayList<FieldParseInfo>(4);
|
||||
}
|
||||
parsers.add(fpi);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompositeField decodeBinaryField(byte[] buf, int offset, int length) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<IsoValue> vals = new ArrayList<IsoValue>(parsers.size());
|
||||
int pos = 0;
|
||||
try {
|
||||
for (FieldParseInfo fpi : parsers) {
|
||||
IsoValue<?> v = fpi.parseBinary(0, buf, pos, null);
|
||||
if (v != null) {
|
||||
if (v.getType() == IsoType.NUMERIC || v.getType() == IsoType.DATE10
|
||||
|| v.getType() == IsoType.DATE4 || v.getType() == IsoType.DATE_EXP
|
||||
|| v.getType() == IsoType.AMOUNT || v.getType() == IsoType.TIME) {
|
||||
pos += (v.getLength() / 2) + (v.getLength() % 2);
|
||||
} else {
|
||||
pos += v.getLength();
|
||||
}
|
||||
if (v.getType() == IsoType.LLVAR || v.getType() == IsoType.LLBIN) {
|
||||
pos++;
|
||||
} else if (v.getType() == IsoType.LLLVAR || v.getType() == IsoType.LLLBIN) {
|
||||
pos+=2;
|
||||
}
|
||||
vals.add(v);
|
||||
}
|
||||
}
|
||||
final CompositeField f = new CompositeField();
|
||||
f.setValues(vals);
|
||||
return f;
|
||||
} catch (ParseException ex) {
|
||||
log.error("Decoding binary CompositeField", ex);
|
||||
return null;
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
log.error("Decoding binary CompositeField", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompositeField decodeField(String value) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<IsoValue> vals = new ArrayList<IsoValue>(parsers.size());
|
||||
byte[] buf = value.getBytes();
|
||||
int pos = 0;
|
||||
try {
|
||||
for (FieldParseInfo fpi : parsers) {
|
||||
IsoValue<?> v = fpi.parse(0, buf, pos, null);
|
||||
if (v != null) {
|
||||
pos += v.toString().getBytes(fpi.getCharacterEncoding()).length;
|
||||
if (v.getType() == IsoType.LLVAR || v.getType() == IsoType.LLBIN) {
|
||||
pos+=2;
|
||||
} else if (v.getType() == IsoType.LLLVAR || v.getType() == IsoType.LLLBIN) {
|
||||
pos+=3;
|
||||
}
|
||||
vals.add(v);
|
||||
}
|
||||
}
|
||||
final CompositeField f = new CompositeField();
|
||||
f.setValues(vals);
|
||||
return f;
|
||||
} catch (ParseException ex) {
|
||||
log.error("Decoding CompositeField", ex);
|
||||
return null;
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
log.error("Decoding CompositeField", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeBinaryField(CompositeField value) {
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
try {
|
||||
for (IsoValue<?> v : value.getValues()) {
|
||||
v.write(bout, true, true);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
log.error("Encoding binary CompositeField", ex);
|
||||
//shouldn't happen
|
||||
}
|
||||
return bout.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeField(CompositeField value) {
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] buf = null;
|
||||
try {
|
||||
String encoding = null;
|
||||
for (IsoValue<?> v : value.getValues()) {
|
||||
v.write(bout, false, true);
|
||||
if (encoding == null)encoding = v.getCharacterEncoding();
|
||||
}
|
||||
buf = bout.toByteArray();
|
||||
return new String(buf, encoding==null?"UTF-8":encoding);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
log.error("Encoding text CompositeField", ex);
|
||||
} catch (IOException ex) {
|
||||
log.error("Encoding text CompositeField", ex);
|
||||
//shouldn't happen
|
||||
}
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("CompositeField[");
|
||||
if (values!=null) {
|
||||
boolean first=true;
|
||||
for (IsoValue<?> v : values) {
|
||||
if (first)first=false;else sb.append(',');
|
||||
sb.append(v.getType());
|
||||
}
|
||||
}
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583.codecs;
|
||||
|
||||
import com.solab.iso8583.CustomBinaryField;
|
||||
|
||||
@@ -21,12 +21,14 @@ package com.solab.iso8583.parse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import com.solab.iso8583.codecs.CompositeField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -106,6 +108,224 @@ public class ConfigParser {
|
||||
return mfact;
|
||||
}
|
||||
|
||||
protected static <T extends IsoMessage> void parseHeaders(
|
||||
final NodeList nodes, final MessageFactory<T> mfact) throws IOException {
|
||||
ArrayList<Element> refs = null;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Element elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid type for ISO8583 header: " + elem.getAttribute("type"));
|
||||
}
|
||||
if (elem.getChildNodes() == null || elem.getChildNodes().getLength() == 0) {
|
||||
if (elem.getAttribute("ref") != null && !elem.getAttribute("ref").isEmpty()) {
|
||||
if (refs == null) {
|
||||
refs = new ArrayList<Element>(nodes.getLength()-i);
|
||||
}
|
||||
refs.add(elem);
|
||||
}
|
||||
else throw new IOException("Invalid ISO8583 header element");
|
||||
} else {
|
||||
String header = elem.getChildNodes().item(0).getNodeValue();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Adding ISO8583 header for type {}: {}", elem.getAttribute("type"), header);
|
||||
}
|
||||
mfact.setIsoHeader(type, header);
|
||||
}
|
||||
}
|
||||
if (refs != null) {
|
||||
for (Element elem : refs) {
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid type for ISO8583 header: "
|
||||
+ elem.getAttribute("type"));
|
||||
}
|
||||
if (elem.getAttribute("ref") != null && !elem.getAttribute("ref").isEmpty()) {
|
||||
int t2 = parseType(elem.getAttribute("ref"));
|
||||
if (t2 == -1) {
|
||||
throw new IOException("Invalid type reference "
|
||||
+ elem.getAttribute("ref") + " for ISO8583 header " + type);
|
||||
}
|
||||
String h = mfact.getIsoHeader(t2);
|
||||
if (h == null) {
|
||||
throw new IllegalArgumentException("Header def " + type + " refers to nonexistent header " + t2);
|
||||
}
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Adding ISO8583 header for type {}: {} (copied from {})",
|
||||
elem.getAttribute("type"), h, elem.getAttribute("ref"));
|
||||
}
|
||||
mfact.setIsoHeader(type, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T extends IsoMessage> void parseTemplates(
|
||||
final NodeList nodes, final MessageFactory<T> mfact) throws IOException {
|
||||
ArrayList<Element> subs = null;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Element elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid ISO8583 type for template: " + elem.getAttribute("type"));
|
||||
}
|
||||
if (elem.getAttribute("extends") != null && !elem.getAttribute("extends").isEmpty()) {
|
||||
if (subs == null) {
|
||||
subs = new ArrayList<Element>(nodes.getLength()-i);
|
||||
}
|
||||
subs.add(elem);
|
||||
continue;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
T m = (T)new IsoMessage();
|
||||
m.setType(type);
|
||||
m.setCharacterEncoding(mfact.getCharacterEncoding());
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
IsoType itype = IsoType.valueOf(f.getAttribute("type"));
|
||||
int length = 0;
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
String v = f.getChildNodes().item(0).getNodeValue();
|
||||
CustomField<Object> _cf = mfact.getCustomField(num);
|
||||
m.setValue(num, _cf == null ? v : _cf.decodeField(v), _cf, itype, length);
|
||||
}
|
||||
mfact.addMessageTemplate(m);
|
||||
}
|
||||
if (subs != null) {
|
||||
for (Element elem : subs) {
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
int ref = parseType(elem.getAttribute("extends"));
|
||||
if (ref == -1) {
|
||||
throw new IllegalArgumentException("Message template "
|
||||
+ elem.getAttribute("type") + " extends invalid template "
|
||||
+ elem.getAttribute("extends"));
|
||||
}
|
||||
T tref = mfact.getMessageTemplate(ref);
|
||||
if (tref == null) {
|
||||
throw new IllegalArgumentException("Message template "
|
||||
+ elem.getAttribute("type") + " extends nonexistent template "
|
||||
+ elem.getAttribute("extends"));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
T m = (T)new IsoMessage();
|
||||
m.setType(type);
|
||||
m.setCharacterEncoding(mfact.getCharacterEncoding());
|
||||
for (int i = 2; i < 128; i++) {
|
||||
if (tref.hasField(i)) {
|
||||
m.setField(i, tref.getField(i).clone());
|
||||
}
|
||||
}
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
final String typedef = f.getAttribute("type");
|
||||
if ("exclude".equals(typedef)) {
|
||||
m.setField(num, null);
|
||||
} else {
|
||||
IsoType itype = IsoType.valueOf(typedef);
|
||||
int length = 0;
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
String v = f.getChildNodes().item(0).getNodeValue();
|
||||
CustomField<Object> _cf = mfact.getCustomField(num);
|
||||
m.setValue(num, _cf == null ? v : _cf.decodeField(v), _cf, itype, length);
|
||||
}
|
||||
}
|
||||
mfact.addMessageTemplate(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T extends IsoMessage> FieldParseInfo getParser(
|
||||
Element f, MessageFactory<T> mfact) throws IOException {
|
||||
IsoType itype = IsoType.valueOf(f.getAttribute("type"));
|
||||
int length = 0;
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
FieldParseInfo fpi = FieldParseInfo.getInstance(itype, length, mfact.getCharacterEncoding());
|
||||
NodeList subs = f.getElementsByTagName("field");
|
||||
if (subs != null && subs.getLength() > 0) {
|
||||
final CompositeField combo = new CompositeField();
|
||||
for (int i=0; i<subs.getLength(); i++) {
|
||||
Element sf = (Element)subs.item(i);
|
||||
if (sf.getParentNode()==f) {
|
||||
combo.addParser(getParser(sf, mfact));
|
||||
}
|
||||
}
|
||||
fpi.setDecoder(combo);
|
||||
}
|
||||
return fpi;
|
||||
}
|
||||
|
||||
protected static <T extends IsoMessage> void parseGuides(
|
||||
final NodeList nodes, final MessageFactory<T> mfact) throws IOException {
|
||||
ArrayList<Element> subs = null;
|
||||
HashMap<Integer,HashMap<Integer,FieldParseInfo>> guides = new HashMap<Integer, HashMap<Integer, FieldParseInfo>>();
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Element elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid ISO8583 type for parse guide: " + elem.getAttribute("type"));
|
||||
}
|
||||
if (elem.getAttribute("extends") != null && !elem.getAttribute("extends").isEmpty()) {
|
||||
if (subs == null) {
|
||||
subs = new ArrayList<Element>(nodes.getLength()-i);
|
||||
}
|
||||
subs.add(elem);
|
||||
continue;
|
||||
}
|
||||
HashMap<Integer, FieldParseInfo> parseMap = new HashMap<Integer, FieldParseInfo>();
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
if (f.getParentNode()==elem) {
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
parseMap.put(num, getParser(f, mfact));
|
||||
}
|
||||
}
|
||||
mfact.setParseMap(type, parseMap);
|
||||
guides.put(type, parseMap);
|
||||
}
|
||||
if (subs != null) {
|
||||
for (Element elem : subs) {
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
int ref = parseType(elem.getAttribute("extends"));
|
||||
if (ref == -1) {
|
||||
throw new IllegalArgumentException("Message template "
|
||||
+ elem.getAttribute("type") + " extends invalid template "
|
||||
+ elem.getAttribute("extends"));
|
||||
}
|
||||
HashMap<Integer,FieldParseInfo> parent = guides.get(ref);
|
||||
if (parent == null) {
|
||||
throw new IllegalArgumentException("Parsing guide "
|
||||
+ elem.getAttribute("type") + " extends nonexistent guide "
|
||||
+ elem.getAttribute("extends"));
|
||||
}
|
||||
HashMap<Integer,FieldParseInfo> child = new HashMap<Integer, FieldParseInfo>();
|
||||
child.putAll(parent);
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
String typedef = f.getAttribute("type");
|
||||
if ("exclude".equals(typedef)) {
|
||||
child.remove(num);
|
||||
} else {
|
||||
child.put(num, getParser(f, mfact));
|
||||
}
|
||||
}
|
||||
mfact.setParseMap(type, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads the XML from the stream and configures the message factory with its values.
|
||||
* @param mfact The message factory to be configured with the values read from the XML.
|
||||
* @param stream The InputStream containing the XML configuration. */
|
||||
@@ -141,75 +361,10 @@ public class ConfigParser {
|
||||
}
|
||||
final Element root = doc.getDocumentElement();
|
||||
|
||||
//Read the ISO headers
|
||||
NodeList nodes = root.getElementsByTagName("header");
|
||||
Element elem = null;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid type for ISO8583 header: " + elem.getAttribute("type"));
|
||||
}
|
||||
if (elem.getChildNodes() == null || elem.getChildNodes().getLength() == 0) {
|
||||
throw new IOException("Invalid ISO8583 header element");
|
||||
}
|
||||
String header = elem.getChildNodes().item(0).getNodeValue();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Adding ISO8583 header for type {}: {}", elem.getAttribute("type"), header);
|
||||
}
|
||||
mfact.setIsoHeader(type, header);
|
||||
}
|
||||
|
||||
//Read the message templates
|
||||
nodes = root.getElementsByTagName("template");
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid ISO8583 type for template: " + elem.getAttribute("type"));
|
||||
}
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
@SuppressWarnings("unchecked")
|
||||
T m = (T)new IsoMessage();
|
||||
m.setType(type);
|
||||
m.setCharacterEncoding(mfact.getCharacterEncoding());
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
IsoType itype = IsoType.valueOf(f.getAttribute("type"));
|
||||
int length = 0;
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
String v = f.getChildNodes().item(0).getNodeValue();
|
||||
CustomField<Object> _cf = mfact.getCustomField(num);
|
||||
m.setValue(num, _cf == null ? v : _cf.decodeField(v), _cf, itype, length);
|
||||
}
|
||||
mfact.addMessageTemplate(m);
|
||||
}
|
||||
|
||||
parseHeaders(root.getElementsByTagName("header"), mfact);
|
||||
parseTemplates(root.getElementsByTagName("template"), mfact);
|
||||
//Read the parsing guides
|
||||
nodes = root.getElementsByTagName("parse");
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
elem = (Element)nodes.item(i);
|
||||
int type = parseType(elem.getAttribute("type"));
|
||||
if (type == -1) {
|
||||
throw new IOException("Invalid ISO8583 type for parse guide: " + elem.getAttribute("type"));
|
||||
}
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
HashMap<Integer, FieldParseInfo> parseMap = new HashMap<Integer, FieldParseInfo>();
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
IsoType itype = IsoType.valueOf(f.getAttribute("type"));
|
||||
int length = 0;
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
parseMap.put(num, FieldParseInfo.getInstance(itype, length, mfact.getCharacterEncoding()));
|
||||
}
|
||||
mfact.setParseMap(type, parseMap);
|
||||
}
|
||||
parseGuides(root.getElementsByTagName("parse"), mfact);
|
||||
}
|
||||
|
||||
/** Configures a MessageFactory using the default configuration file j8583.xml. This is useful
|
||||
|
||||
@@ -35,6 +35,7 @@ public abstract class FieldParseInfo {
|
||||
protected int length;
|
||||
private String encoding = System.getProperty("file.encoding");
|
||||
protected boolean forceStringDecoding;
|
||||
private CustomField<?> decoder;
|
||||
|
||||
/** Creates a new instance that parses a value of the specified type, with the specified length.
|
||||
* The length is only useful for ALPHA and NUMERIC types.
|
||||
@@ -72,6 +73,13 @@ public abstract class FieldParseInfo {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setDecoder(CustomField<?> value) {
|
||||
decoder = value;
|
||||
}
|
||||
public CustomField<?> getDecoder() {
|
||||
return decoder;
|
||||
}
|
||||
|
||||
/** Parses the character data from the buffer and returns the
|
||||
* IsoValue with the correct data type in it.
|
||||
* @param field The field index, useful for error reporting.
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583.util;
|
||||
|
||||
/** Utility class to perform HEX encoding/decoding of values. */
|
||||
/** Utility class to perform HEX encoding/decoding of values.
|
||||
* @author Enrique Zamudio
|
||||
*/
|
||||
public final class HexCodec {
|
||||
|
||||
static final char[] HEX = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* j8583 A Java implementation of the ISO8583 protocol
|
||||
* Copyright (C) 2007 Enrique Zamudio Lopez
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
package com.solab.iso8583.util;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
<!ELEMENT header ( #PCDATA ) >
|
||||
<!ATTLIST header type NMTOKEN #REQUIRED >
|
||||
<!ATTLIST header ref NMTOKEN #IMPLIED >
|
||||
|
||||
<!ELEMENT template ( field* ) >
|
||||
<!ATTLIST template type NMTOKEN #REQUIRED >
|
||||
<!ATTLIST template extends NMTOKEN #IMPLIED >
|
||||
|
||||
<!ELEMENT parse ( field+ ) >
|
||||
<!ATTLIST parse type NMTOKEN #REQUIRED >
|
||||
<!ATTLIST parse extends NMTOKEN #IMPLIED >
|
||||
|
||||
<!ELEMENT field ( #PCDATA ) >
|
||||
<!ELEMENT field ( #PCDATA|field )* >
|
||||
<!ATTLIST field num NMTOKEN #REQUIRED >
|
||||
<!ATTLIST field length NMTOKEN #IMPLIED >
|
||||
<!ATTLIST field type ( ALPHA | NUMERIC | AMOUNT | DATE10 | DATE4 | DATE_EXP | TIME | LLVAR | LLLVAR | BINARY | LLBIN | LLLBIN ) #REQUIRED >
|
||||
<!ATTLIST field type ( ALPHA | NUMERIC | AMOUNT | DATE10 | DATE4 | DATE_EXP | TIME | LLVAR | LLLVAR | BINARY | LLBIN | LLLBIN | exclude) #REQUIRED >
|
||||
|
||||
@@ -20,6 +20,14 @@ XML Configuration
|
||||
<header type="0400">ISO015000050</header>
|
||||
+-----
|
||||
|
||||
<<New in 1.9:>> You can define a header as a reference to another header:
|
||||
|
||||
+-----
|
||||
<header type="0800" ref="0200" />
|
||||
+-----
|
||||
|
||||
The header for 0800 messages will be the same as the header for 0200 messages.
|
||||
|
||||
* <<<template>>> element
|
||||
|
||||
Each <<<template>>> element defines a message template, with the message type and the fields that the
|
||||
@@ -42,6 +50,20 @@ XML Configuration
|
||||
</template>
|
||||
+-----
|
||||
|
||||
<<New in 1.9:>> You can define a template as extending another template, so that it includes
|
||||
all the fields from the referenced template as well as any new fields defined in it, as well
|
||||
as excluding fields from the referenced template:
|
||||
|
||||
+-----
|
||||
<template type="0400" extends="0200">
|
||||
<field num="90" type="ALPHA" length="42">Bla bla</field>
|
||||
<field num="102" type="exclude" />
|
||||
</template>
|
||||
+-----
|
||||
|
||||
In the above example, the template for message type 0400 will include all fields defined in the
|
||||
template for message type 0200 <except> field 102, and will additionally include field 90.
|
||||
|
||||
* <<<parse>>> element
|
||||
|
||||
Each <<<parse>>> element defines a parsing template for a message type. It must include all the fields that
|
||||
@@ -71,10 +93,64 @@ XML Configuration
|
||||
<field num="60" type="LLLVAR" />
|
||||
<field num="61" type="LLLVAR" />
|
||||
<field num="70" type="ALPHA" length="3" />
|
||||
<field num="90" type="ALPHA" length="42" />
|
||||
<field num="100" type="LLVAR" />
|
||||
<field num="102" type="LLVAR" />
|
||||
<field num="126" type="LLLVAR" />
|
||||
</parse>
|
||||
+-----
|
||||
|
||||
|
||||
<<New in 1.9:>> As with message templates, you can define parsing guides that extend other
|
||||
parsing guides:
|
||||
|
||||
+-----
|
||||
<parse type="0410" extends="0210">
|
||||
<field num="90" type="ALPHA" length="42" />
|
||||
<field num="102" type="exclude" />
|
||||
</parse>
|
||||
+----
|
||||
|
||||
* Composite fields
|
||||
|
||||
Another new feature introduced in 1.9 is the CompositeField. This is a CustomField that acts
|
||||
as a container for several IsoValues, and it can be configured in the parsing guide of
|
||||
a message type:
|
||||
|
||||
+-----
|
||||
<parse type="0410">
|
||||
<field num="125" type="LLLVAR">
|
||||
<field num="1" type="ALPHA" length="5" />
|
||||
<field num="2" type="LLVAR" />
|
||||
<field num="3" type="NUMERIC" length="6" />
|
||||
<field num="4" type="ALPHA" length="2" />
|
||||
</field>
|
||||
</parse>
|
||||
+-----
|
||||
|
||||
In the above example, when a message with type 0410 is parsed, the value for field 125 will
|
||||
be a <<<CompositeField>>> and you can obtain the subfields via <<<getField()>>> or
|
||||
<<<getObjectValue()>>>. The <<<num>>> attribute of the subfields is ignored; it's just
|
||||
there to pass the DTD validation.
|
||||
|
||||
This means that you can do this via code:
|
||||
|
||||
+-----
|
||||
//Assuming original data for field 125 is "018one 03two123456OK"
|
||||
CompositeField f = message.getObjectValue(125);
|
||||
String sub1 = f.getObjectValue(0); //"one "
|
||||
String sub2 = f.getObjectValue(1); //"two"
|
||||
String sub3 = f.getObjectValue(2); //"123456"
|
||||
String sub4 = f.getObjectValue(3); //"OK"
|
||||
+-----
|
||||
|
||||
You can also create a CompositeField, store several subfields inside it, and store it in any
|
||||
field inside an IsoMessage, specifying the same instance as the CustomField:
|
||||
|
||||
+-----
|
||||
CompositeField f = new CompositeField().addValue(new IsoValue<String>(IsoType.ALPHA, "one", 5))
|
||||
.addValue(new IsoValue<String>(IsoType.LLVAR, "two"))
|
||||
.addValue(new IsoValue<Long>(IsoType.NUMERIC, 123l, 6))
|
||||
.addValue(new IsoValue<String>(IsoType.ALPHA, "OK", 2));
|
||||
message.setValue(125, f, f, IsoType.LLLVAR, 0);
|
||||
+-----
|
||||
|
||||
When the message is encoded, field 125 will be "<<<018one 03two000123OK>>>".
|
||||
|
||||
@@ -19,6 +19,13 @@ Configuración por XML
|
||||
+-----
|
||||
<header type="0200">ISO015000050</header>
|
||||
<header type="0400">ISO015000050</header>
|
||||
+-----
|
||||
|
||||
<<Nuevo en 1.9:>> Se puede definir un elemento <<<header>>> como referencia a otro elemento para que tengan
|
||||
el mismo valor:
|
||||
|
||||
+-----
|
||||
<header type="0800" ref="0200" />
|
||||
+-----
|
||||
|
||||
* Elemento <<<template>>>
|
||||
@@ -43,6 +50,19 @@ Configuración por XML
|
||||
</template>
|
||||
+-----
|
||||
|
||||
<<Nuevo en 1.9:>> Se puede definir una plantilla que extienda otra plantilla, de modo que incluya todos
|
||||
los campos de la plantilla que extiende, además de poder excluir campos de la plantilla original.
|
||||
|
||||
+-----
|
||||
<template type="0400">
|
||||
<field num="90" type="ALPHA" length="42">bla bla</field>
|
||||
<field num="102" type="exclude" />
|
||||
</template>
|
||||
+-----
|
||||
|
||||
En este ejemplo, la plantilla para mensajes 0400 include todos los campos de los mensajes 0200
|
||||
<excepto> el campo 102, y además incluye el campo 90.
|
||||
|
||||
* Elemento <<<parse>>>
|
||||
|
||||
Cada elemento <<<parse>>> define una plantilla de lectura para un tipo de mensaje. Debe incluir todos los
|
||||
@@ -72,10 +92,63 @@ Configuración por XML
|
||||
<field num="60" type="LLLVAR" />
|
||||
<field num="61" type="LLLVAR" />
|
||||
<field num="70" type="ALPHA" length="3" />
|
||||
<field num="90" type="ALPHA" length="42" />
|
||||
<field num="100" type="LLVAR" />
|
||||
<field num="102" type="LLVAR" />
|
||||
<field num="126" type="LLLVAR" />
|
||||
</parse>
|
||||
+-----
|
||||
|
||||
|
||||
<<Nuevo en 1.9:>> Al igual que las plantillas, las guías de lectura también pueden extender otras guías:
|
||||
|
||||
+-----
|
||||
<parse type="0410">
|
||||
<field num="90" type="ALPHA" length="42" />
|
||||
<field num="102" type="exclude" />
|
||||
</parse>
|
||||
+-----
|
||||
|
||||
* Campos compuestos
|
||||
|
||||
Otra característica nueva a partir de la versión 1.9 son los campos compuestos, por medio de la clase
|
||||
CompositeField, que es una implementación de CustomField que funciona como un contenedor de varios
|
||||
IsoValues, y puede ser configurado en la guía de lectura de un tipo de mensaje:
|
||||
|
||||
+-----
|
||||
<parse type="0410">
|
||||
<field num="125" type="LLLVAR">
|
||||
<field num="1" type="ALPHA" length="5" />
|
||||
<field num="2" type="LLVAR" />
|
||||
<field num="3" type="NUMERIC" length="6" />
|
||||
<field num="4" type="ALPHA" length="2" />
|
||||
</field>
|
||||
</parse>
|
||||
+-----
|
||||
|
||||
En este ejemplo, cuando un mensaje tipo 0410 se decodifica, el valor del campo 125 será una instancia
|
||||
de <<<CompositeField>>> y se pueden obtener sus subcampos con los métodos <<<getField()>>> y
|
||||
<<<getObjectValue()>>>. El atributo <<<num>>> de los subcampos es ignorado; simplemente se tiene que
|
||||
incluir para pasar la validación del DTD.
|
||||
|
||||
Lo anterior significa que se puede hacer esto con código, una vez que se ha leído el mensaje:
|
||||
|
||||
+-----
|
||||
//Suponiendo que originalmente el campo 125 trae "018one 03two123456OK"
|
||||
CompositeField f = message.getObjectValue(125);
|
||||
String sub1 = f.getObjectValue(0); //"one "
|
||||
String sub2 = f.getObjectValue(1); //"two"
|
||||
String sub3 = f.getObjectValue(2); //"123456"
|
||||
String sub4 = f.getObjectValue(3); //"OK"
|
||||
+-----
|
||||
|
||||
También se puede crear un CompositeField, guardar varios valores en él, y luego ponerlo
|
||||
como valor en cualquier campo de un IsoMessage, usando el mismo objeto como CustomField:
|
||||
|
||||
+-----
|
||||
CompositeField f = new CompositeField().addValue(new IsoValue<String>(IsoType.ALPHA, "one", 5))
|
||||
.addValue(new IsoValue<String>(IsoType.LLVAR, "two"))
|
||||
.addValue(new IsoValue<Long>(IsoType.NUMERIC, 123l, 6))
|
||||
.addValue(new IsoValue<String>(IsoType.ALPHA, "OK", 2));
|
||||
message.setValue(125, f, f, IsoType.LLLVAR, 0);
|
||||
+-----
|
||||
|
||||
Cuando ese mensaje sea codificado, el campo 125 se verá como "<<<018one 03two000123OK>>>".
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<item name="Download" href="http://sourceforge.net/projects/j8583/files/j8583/"/>
|
||||
</links>
|
||||
|
||||
<menu name="j8583 1.8.0">
|
||||
<menu name="j8583 1.9.1">
|
||||
<item name="Introduction" href="index.html"/>
|
||||
<item name="API docs" href="javadoc/index.html" />
|
||||
<item name="Beginner's Guide" href="guide.html"/>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<item name="Descargar" href="http://sourceforge.net/projects/j8583/files/j8583/"/>
|
||||
</links>
|
||||
|
||||
<menu name="j8583 1.5.7">
|
||||
<menu name="j8583 1.9.1">
|
||||
<item name="Introducción" href="index.html"/>
|
||||
<item name="Documentación API" href="../javadoc/index.html" />
|
||||
<item name="Guía de inicio" href="guide.html"/>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package j8583;
|
||||
|
||||
import com.solab.iso8583.util.Bcd;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* BCD encoding tests.
|
||||
*
|
||||
* @author Enrique Zamudio
|
||||
* Date: 25/11/13 10:43
|
||||
*/
|
||||
public class TestBcd {
|
||||
|
||||
@Test
|
||||
public void testEncoding() {
|
||||
byte[] buf = new byte[2];
|
||||
buf[0] = 1; buf[1]=1;
|
||||
Bcd.encode("00", buf);
|
||||
Assert.assertArrayEquals(new byte[]{0, 1}, buf);
|
||||
Bcd.encode("79", buf);
|
||||
Assert.assertArrayEquals(new byte[]{0x79, 1}, buf);
|
||||
Bcd.encode("80", buf);
|
||||
Assert.assertArrayEquals(new byte[]{(byte)0x80,1}, buf);
|
||||
Bcd.encode("99", buf);
|
||||
Assert.assertArrayEquals(new byte[]{(byte)0x99,1}, buf);
|
||||
Bcd.encode("100", buf);
|
||||
Assert.assertArrayEquals(new byte[]{1, 0}, buf);
|
||||
Bcd.encode("779", buf);
|
||||
Assert.assertArrayEquals(new byte[]{7, 0x79}, buf);
|
||||
Bcd.encode("999", buf);
|
||||
Assert.assertArrayEquals(new byte[]{9,(byte)0x99}, buf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecoding() {
|
||||
byte[] buf = new byte[2];
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 1));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 2));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 3));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 4));
|
||||
buf[0]=0x79;
|
||||
Assert.assertEquals(79, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=(byte)0x80;
|
||||
Assert.assertEquals(80, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=(byte)0x99;
|
||||
Assert.assertEquals(99, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=1;
|
||||
Assert.assertEquals(100, Bcd.decodeToLong(buf,0,4));
|
||||
buf[1]=0x79;
|
||||
Assert.assertEquals(179, Bcd.decodeToLong(buf,0,4));
|
||||
buf[1]=(byte)0x99;
|
||||
Assert.assertEquals(199, Bcd.decodeToLong(buf,0,4));
|
||||
buf[0]=9;
|
||||
Assert.assertEquals(999, Bcd.decodeToLong(buf,0,4));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package j8583;
|
||||
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.IsoValue;
|
||||
import com.solab.iso8583.codecs.CompositeField;
|
||||
import com.solab.iso8583.parse.AlphaParseInfo;
|
||||
import com.solab.iso8583.parse.LlvarParseInfo;
|
||||
import com.solab.iso8583.parse.NumericParseInfo;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the CompositeField.
|
||||
*
|
||||
* @author Enrique Zamudio
|
||||
* Date: 25/11/13 17:43
|
||||
*/
|
||||
public class TestComposites {
|
||||
|
||||
final String textData = "One 03Two00999X";
|
||||
final byte[] binaryData = new byte[]{'O', 'n', 'e', ' ', ' ', 3, 'T', 'w', 'o',
|
||||
0, 9, (byte) 0x99, 'X'};
|
||||
|
||||
@Test
|
||||
public void testEncodeText() {
|
||||
final CompositeField f = new CompositeField();
|
||||
f.addValue(new IsoValue<String>(IsoType.ALPHA, "One", 5));
|
||||
f.getValues().get(0).setCharacterEncoding("UTF-8");
|
||||
Assert.assertEquals("One ", f.encodeField(f));
|
||||
f.addValue("Two", null, IsoType.LLVAR, 0);
|
||||
f.getValues().get(1).setCharacterEncoding("UTF-8");
|
||||
Assert.assertEquals("One 03Two", f.encodeField(f));
|
||||
f.addValue(999, null, IsoType.NUMERIC, 5);
|
||||
f.getValues().get(2).setCharacterEncoding("UTF-8");
|
||||
Assert.assertEquals("One 03Two00999", f.encodeField(f));
|
||||
f.addValue("X", null, IsoType.ALPHA, 1);
|
||||
Assert.assertEquals(textData, f.encodeField(f));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBinary() {
|
||||
final CompositeField f = new CompositeField()
|
||||
.addValue(new IsoValue<String>(IsoType.ALPHA, "One", 5));
|
||||
Assert.assertArrayEquals(new byte[]{'O', 'n', 'e', 32, 32}, f.encodeBinaryField(f));
|
||||
f.addValue(new IsoValue<String>(IsoType.LLVAR, "Two"));
|
||||
Assert.assertArrayEquals(new byte[]{'O', 'n', 'e', ' ', ' ', 3, 'T', 'w', 'o'},
|
||||
f.encodeBinaryField(f));
|
||||
f.addValue(new IsoValue<Long>(IsoType.NUMERIC, 999l, 5));
|
||||
f.addValue(new IsoValue<String>(IsoType.ALPHA, "X", 1));
|
||||
Assert.assertArrayEquals(binaryData, f.encodeBinaryField(f));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeText() {
|
||||
final CompositeField dec = new CompositeField()
|
||||
.addParser(new AlphaParseInfo(5))
|
||||
.addParser(new LlvarParseInfo())
|
||||
.addParser(new NumericParseInfo(5))
|
||||
.addParser(new AlphaParseInfo(1));
|
||||
final CompositeField f = dec.decodeField(textData);
|
||||
Assert.assertNotNull(f);
|
||||
Assert.assertEquals(4, f.getValues().size());
|
||||
Assert.assertEquals("One ", f.getValues().get(0).getValue());
|
||||
Assert.assertEquals("Two", f.getValues().get(1).getValue());
|
||||
Assert.assertEquals("00999", f.getValues().get(2).getValue());
|
||||
Assert.assertEquals("X", f.getValues().get(3).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBinary() {
|
||||
final CompositeField dec = new CompositeField()
|
||||
.addParser(new AlphaParseInfo(5))
|
||||
.addParser(new LlvarParseInfo())
|
||||
.addParser(new NumericParseInfo(5))
|
||||
.addParser(new AlphaParseInfo(1));
|
||||
final CompositeField f = dec.decodeBinaryField(binaryData, 0, binaryData.length);
|
||||
Assert.assertNotNull(f);
|
||||
Assert.assertEquals(4, f.getValues().size());
|
||||
Assert.assertEquals("One ", f.getValues().get(0).getValue());
|
||||
Assert.assertEquals("Two", f.getValues().get(1).getValue());
|
||||
Assert.assertEquals(999l, f.getValues().get(2).getValue());
|
||||
Assert.assertEquals("X", f.getValues().get(3).getValue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package j8583;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.IsoValue;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* Test certain ConfigParser features.
|
||||
*
|
||||
* @author Enrique Zamudio
|
||||
* Date: 25/11/13 18:41
|
||||
*/
|
||||
public class TestConfigParser {
|
||||
|
||||
@Test
|
||||
public void testParser() throws IOException, ParseException {
|
||||
MessageFactory<IsoMessage> mfact = new MessageFactory<IsoMessage>();
|
||||
mfact.setConfigPath("config.xml");
|
||||
//Headers
|
||||
Assert.assertNotNull(mfact.getIsoHeader(0x800));
|
||||
Assert.assertNotNull(mfact.getIsoHeader(0x810));
|
||||
Assert.assertEquals(mfact.getIsoHeader(0x800), mfact.getIsoHeader(0x810));
|
||||
//Templates
|
||||
final IsoMessage m200 = mfact.getMessageTemplate(0x200);
|
||||
Assert.assertNotNull(m200);
|
||||
final IsoMessage m400 = mfact.getMessageTemplate(0x400);
|
||||
Assert.assertNotNull(m400);
|
||||
for (int i=2; i <89; i++) {
|
||||
IsoValue<?> v = m200.getField(i);
|
||||
if (v == null) {
|
||||
Assert.assertFalse(m400.hasField(i));
|
||||
} else {
|
||||
Assert.assertTrue(m400.hasField(i));
|
||||
Assert.assertEquals(v, m400.getField(i));
|
||||
}
|
||||
}
|
||||
Assert.assertFalse(m200.hasField(90));
|
||||
Assert.assertTrue(m400.hasField(90));
|
||||
Assert.assertTrue(m200.hasField(102));
|
||||
Assert.assertFalse(m400.hasField(102));
|
||||
|
||||
//Parsing guides
|
||||
final String s800 = "0800201080000000000012345611251125";
|
||||
final String s810 = "08102010000002000000123456112500";
|
||||
IsoMessage m = mfact.parseMessage(s800.getBytes(), 0);
|
||||
Assert.assertNotNull(m);
|
||||
Assert.assertTrue(m.hasField(3));
|
||||
Assert.assertTrue(m.hasField(12));
|
||||
Assert.assertTrue(m.hasField(17));
|
||||
Assert.assertFalse(m.hasField(39));
|
||||
m = mfact.parseMessage(s810.getBytes(), 0);
|
||||
Assert.assertNotNull(m);
|
||||
Assert.assertTrue(m.hasField(3));
|
||||
Assert.assertTrue(m.hasField(12));
|
||||
Assert.assertFalse(m.hasField(17));
|
||||
Assert.assertTrue(m.hasField(39));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.text.ParseException;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.IsoValue;
|
||||
import com.solab.iso8583.codecs.CompositeField;
|
||||
import com.solab.iso8583.parse.NumericParseInfo;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -107,4 +108,16 @@ public class TestParsing {
|
||||
Assert.assertEquals(123456, val.getValue().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComposite() throws ParseException, UnsupportedEncodingException {
|
||||
IsoMessage m = mf.parseMessage("12000040000000000000016one 03two12345.".getBytes(), 0);
|
||||
Assert.assertNotNull(m);
|
||||
CompositeField f = m.getObjectValue(10);
|
||||
Assert.assertNotNull(f);
|
||||
Assert.assertEquals(4, f.getValues().size());
|
||||
Assert.assertEquals("one ", f.getObjectValue(0));
|
||||
Assert.assertEquals("two", f.getObjectValue(1));
|
||||
Assert.assertEquals("12345", f.getObjectValue(2));
|
||||
Assert.assertEquals(".", f.getObjectValue(3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
<!-- These are the ISO headers to be prepended to the message types specified -->
|
||||
<header type="0200">ISO015000050</header>
|
||||
<header type="0210">ISO015000055</header>
|
||||
<header type="0400">ISO015000050</header>
|
||||
<header type="0410">ISO015000055</header>
|
||||
<header type="0400" ref="0200" />
|
||||
<header type="0410" ref="0210" />
|
||||
<header type="0800">ISO015000015</header>
|
||||
<header type="0810">ISO015000015</header>
|
||||
<header type="0810" ref="0800"/>
|
||||
|
||||
<!-- The client example uses this to create requests -->
|
||||
<template type="0200">
|
||||
@@ -37,6 +37,11 @@
|
||||
<field num="126" type="LLLVAR">...and yet another fixed field.</field>
|
||||
</template>
|
||||
|
||||
<template type="0400" extends="0200">
|
||||
<field num="90" type="ALPHA" length="42">BLA</field>
|
||||
<field num="102" type="exclude" />
|
||||
</template>
|
||||
|
||||
<template type="0600">
|
||||
<field num="4" type="AMOUNT">1234</field>
|
||||
<field num="11" type="NUMERIC" length="6">123</field>
|
||||
@@ -116,4 +121,24 @@
|
||||
<field num="102" type="LLLVAR" />
|
||||
</parse>
|
||||
|
||||
<parse type="0800">
|
||||
<field num="3" type="ALPHA" length="6">123456</field>
|
||||
<field num="12" type="DATE4">1231</field>
|
||||
<field num="17" type="DATE4">1231</field>
|
||||
</parse>
|
||||
|
||||
<parse type="0810" extends="0800">
|
||||
<field num="17" type="exclude"/>
|
||||
<field num="39" type="ALPHA" length="2"/>
|
||||
</parse>
|
||||
|
||||
<parse type="1200">
|
||||
<field num="10" type="LLLVAR">
|
||||
<field num="1" type="ALPHA" length="5" />
|
||||
<field num="2" type="LLVAR"/>
|
||||
<field num="3" type="NUMERIC" length="5" />
|
||||
<field num="4" type="ALPHA" length="1" />
|
||||
</field>
|
||||
</parse>
|
||||
|
||||
</j8583-config>
|
||||
|
||||
Reference in New Issue
Block a user