Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Smooks:从Java输出EDI_Java_Edi_Smooks - Fatal编程技术网

Smooks:从Java输出EDI

Smooks:从Java输出EDI,java,edi,smooks,Java,Edi,Smooks,受中提出的解决方案的启发,我有以下Java代码: // Creates minimal EDI message with one field populated EdifactV3D98AMEDPID edi = new EdifactV3D98AMEDPID(); UNBInterchangeHeader header = new UNBInterchangeHeader(); UNBInterchangeHeader.S002SenderIdentification s002SenderId

受中提出的解决方案的启发,我有以下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);
//创建一个字段填充的最小EDI消息
EdifactV3D98AMEDPID edi=新的EdifactV3D98AMEDPID();
UNBINCERVERSEHEADER header=新的UNBINCERVERSEADER();
UNBCInterchangeHeader.S002 SenderIdentification S002 SenderIdentification=新的UNBCInterchangeHeader.S002 SenderIdentification();
S002发送方标识。SETE0004发送方标识(“测试”);
标题.SETS002发送标识(S002发送标识);
edi.SET头(头);
Smooks Smooks=新的Smooks(“edi输出Smooks config.xml”);
//设置对Smooks配置中指定的导出的访问权限
ExecutionContext ExecutionContext=smooks.createExecutionContext();
Exports Exports=Exports.getExports(smooks.getApplicationContext());
结果[]结果=exports.createResults();
filterSource(executionContext,新JavaSource(edi),结果);
列表对象=导出。提取结果(结果,导出);
JavaResult.ResultMap=(JavaResult.ResultMap)objects.get(0);
D98AInterchangeFactory=D98AInterchangeFactory.getInstance();
UNEdifactInterchange41 unEdifactInterchange=(UNEdifactInterchange41)map.get(“unEdifactInterchange”);
//应将EDI消息输出为字符串,但StringWriter为空
StringWriter ediOutStream=新StringWriter();
工厂。Toundeifact(非事实交换、电子数据外流);
。。。使用以下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字符串


有什么建议或建议吗?

我找不到类EdifactV3D98AMEDPID,unb。但我做了一个类似的测试:

UNEdifactInterchange41 edi = new UNEdifactInterchange41();
UNB41 header = new UNB41();
header.setSender(null);
Party sender = new Party();
sender.setInternalId("TEST");
header.setSender(sender);
edi.setInterchangeHeader(header);

Smooks smooks = new Smooks("edi-output-smooks-config.xml");

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 u = (UNEdifactInterchange41) map.get("unEdifactInterchange");

// Should output EDI message as String, but StringWriter is empty
StringWriter ediOutStream1 = new StringWriter();
factory.toUNEdifact(u, ediOutStream1);
我已经测试过了,你会发现:

UNB++::TEST'

我希望这能帮助你

我在maven中找不到这些类:eDiscoveryV3D98AMEDPID,UNBI。你知道软件包或依赖关系吗?我在github->上找到了它们,我必须检查一下非本地项目并构建d98a模块。org.milyn.edi.unedifact d98a binding 1.4我创建了一个测试,它从文件中读取edi,然后将edi正确地作为字符串输出。所以我认为我的问题与我在上面创建的EDI有关。填写单个字段可能不足以创建有效的EDI。你的例子也适用于我,所以我将从这里继续。谢谢你的努力!没问题,很乐意帮忙:)很棒的东西伙计们。。。很高兴看到人们仍然从中获得价值:)嗨@Panchitoboy你能帮我处理835 edi文件吗,我该如何解析我的edi文件。@Panchitoboy我是新手,在配置方面没有足够的知识
UNB++::TEST'