如何在 smooks 中添加 header "UNH" 到 UNEdifactInterchange41 Object

how to add header "UNH" to UNEdifactInterchange41 Object in smooks

我必须创建能量值的 mscons 导出。我根据找到的一些示例创建了一些代码,但现在我卡住了。 MSCONS 需要一个 UNB 和一个 UNH header。 我可以将 UNB header 添加到 UNEdifactInterchange41 object,但我找不到附加 UNH header 的方法。

到目前为止,这是我的代码:

import org.milyn.SmooksException;
import org.milyn.edi.unedifact.d16b.D16BInterchangeFactory;
import org.milyn.edi.unedifact.d16b.MSCONS.*;
import org.milyn.smooks.edi.unedifact.model.r41.*;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.StringWriter;
import org.milyn.smooks.edi.unedifact.model.r41.types.MessageIdentifier;
import org.milyn.smooks.edi.unedifact.model.r41.types.Party;
import org.milyn.smooks.edi.unedifact.model.r41.types.SyntaxIdentifier;

public class EDI {

    public static void main(String[] args) throws IOException, SAXException, SmooksException {

        D16BInterchangeFactory factory = D16BInterchangeFactory.getInstance();
        UNEdifactInterchange41 edi = new UNEdifactInterchange41();       
        Mscons mscons = new Mscons();

        /*UNB*/
        UNB41 unb = new UNB41();
        unb.setSender(null);
        Party sender = new Party();
        sender.setInternalId(getSenderInternalId());
        sender.setCodeQualifier(getSenderCodeQualifier());
        sender.setId(getSenderId());
        SyntaxIdentifier si=new SyntaxIdentifier();
        si.setVersionNum("3");
        si.setId("UNOC");
        unb.setSyntaxIdentifier(si);
        unb.setSender(sender);
        edi.setInterchangeHeader(unb);
        /*UNH*/
        UNH41 unh = new UNH41();
        MessageIdentifier mi=new MessageIdentifier();
        mi.setTypeSubFunctionId("MSCONS");
        mi.setControllingAgencyCode("UN");
        mi.setAssociationAssignedCode("2.2h");

        String refno=createRefNo();
        unh.setMessageIdentifier(mi);


        /* How to attach UNH? */


    }
}

听起来你几乎是对的,你需要将 UNH 附加到消息中,而不是相反:

mi.setMessageIdentifier(unh);

如果你需要,你有一个例子: https://github.com/ClaudePlos/VOrders/blob/master/src/main/java/pl/vo/integration/edifact/EdifactExportPricat.java