【发布时间】:2015-09-13 04:30:03
【问题描述】:
受Smooks EDI writer 中建议的解决方案的启发,我有以下 Java 代码:
// Creates minimal EDI message with one field populated
EdifactV3D98AMEDPID edi = new EdifactV3D98AMEDPID();
UNBInterchangeHeader header = new UNBInterchangeHeader();
UNBInterchangeHeader.S002SenderIdentification s002SenderIdentification = new UNBInterchangeHeader.S002SenderIdentification();
s002SenderIdentification.setE0004SenderIdentification("TEST");
header.setS002SenderIdentification(s002SenderIdentification);
edi.setUNBInterchangeHeader(header);
Smooks smooks = new Smooks("edi-output-smooks-config.xml");
// Sets up access to exports specified in Smooks config
ExecutionContext executionContext = smooks.createExecutionContext();
Exports exports = Exports.getExports(smooks.getApplicationContext());
Result[] results = exports.createResults();
smooks.filterSource(executionContext, new JavaSource(edi), results);
List<Object> objects = Exports.extractResults(results, exports);
JavaResult.ResultMap map = (JavaResult.ResultMap) objects.get(0);
D98AInterchangeFactory factory = D98AInterchangeFactory.getInstance();
UNEdifactInterchange41 unEdifactInterchange = (UNEdifactInterchange41) map.get("unEdifactInterchange");
// Should output EDI message as String, but StringWriter is empty
StringWriter ediOutStream = new StringWriter();
factory.toUNEdifact(unEdifactInterchange, ediOutStream);
... 使用以下 Smooks 配置:
<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd">
<!-- Imports D98A Edifact binding found in Maven dependency -->
<import file="/org/milyn/edi/unedifact/d98a/message-bindingconfig.xml" />
<import file="/org/milyn/smooks/edi/unedifact/model/r41/bindings/unedifact-interchange.xml" />
<!-- Configures Result object for accessing EDI output -->
<core:exports>
<core:result type="org.milyn.payload.JavaResult"/>
</core:exports>
</smooks-resource-list>
StringWriter 返回一个空字符串,而我曾希望/期望 Java 对象为 EDI 字符串。
有什么建议或指点吗?
【问题讨论】:
-
我在 maven 中找不到这些类:EdifactV3D98AMEDPID,UNBInterchangeHeader。你知道包还是依赖?
-
我在 github 上找到了它们 -> github.com/smooks/unedifact 我必须检查 unedifact 项目并构建 d98a 模块。
-
org.milyn.edi.unedifact d98a-binding 1.4 -
我创建了一个测试,它从文件中读取 EDI,然后将 EDI 正确输出为字符串。所以我认为我的问题与我在上面创建的 EDI 有关。填写单个字段可能不足以创建有效的 EDI。