prowide-iso20022 icon indicating copy to clipboard operation
prowide-iso20022 copied to clipboard

Calling setAny() on SupplementaryDataEnvelope1

Open seanleblancicdtech opened this issue 1 year ago • 1 comments

We are trying to build a camt.998 message. Is there a good sample on how to call setAny() on the com.prowidesoftware.swift.model.mx.dic.SupplementaryDataEnvelope1 class? It takes an Object, and during the marshaling step it will throw an exception like this (if the type is a LinkedHashMap, for example):

[com.sun.istack.SAXException2: javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context. javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context.]

It seems this type is annotated as XmlAnyElement are there any good code samples on using this in Prowide?

seanleblancicdtech avatar Jun 28 '23 22:06 seanleblancicdtech

Hello Sean. Please let us know if this code sample meets your requirements:

@Test
public void test() throws ParserConfigurationException {

    // create the target CAMT message
    MxCamt99800103 mx = new MxCamt99800103();

    // create and add the header to the message
    BusinessAppHdrV02 bah = AppHdrFactory.createBusinessAppHdrV02(
            "BBBBNGLA", "XXXXNGLARTG", "707281121261702", new MxId("camt.998.001.03"));
    bah.setBizSvc("cbn.rtgs.01");
    mx.setAppHdr(bah);

    // create the standard content using the CAMT model
    mx.setCshMgmtPrtryMsg(new CashManagementProprietaryMessageV03());
    mx.getCshMgmtPrtryMsg().setMsgHdr(new MessageHeader1());
    mx.getCshMgmtPrtryMsg().getMsgHdr().setMsgId("707281121261702");
    mx.getCshMgmtPrtryMsg().setPrtryData(new ProprietaryData5());
    mx.getCshMgmtPrtryMsg().getPrtryData().setTp("cma.textMessage.001.01");
    mx.getCshMgmtPrtryMsg().getPrtryData().setData(new SupplementaryDataEnvelope1());

    // then create a custom DOM structure for the proprietary content
    DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
    Document document = documentBuilder.newDocument();

    Element root = document.createElementNS("urn:cma:xsd:cma.textMessage.001.01", "Document");
    // root.setAttributeNS("urn:cma:xsd:cma.textMessage.001.01", "xsi:schemaLocation", null);
    document.appendChild(root);

    Element txtMsg = document.createElement("TxtMsg");
    root.appendChild(txtMsg);

    Element rcvr = document.createElement("Rcvr");
    txtMsg.appendChild(rcvr);

    Element rcvrPrtcId = document.createElement("PrtcId");
    rcvr.appendChild(rcvrPrtcId);

    Element rcvrBICFI = document.createElement("BICFI");
    rcvrBICFI.setTextContent("CCCCNGLA");
    rcvrPrtcId.appendChild(rcvrBICFI);

    Element sndr = document.createElement("Sndr");
    txtMsg.appendChild(sndr);

    Element sndrPrtcId = document.createElement("PrtcId");
    sndr.appendChild(sndrPrtcId);

    Element sndrBICFI = document.createElement("BICFI");
    sndrBICFI.setTextContent("BBBBNGLA");
    sndrPrtcId.appendChild(sndrBICFI);

    Element impt = document.createElement("Impt");
    impt.setTextContent("INFO");
    txtMsg.appendChild(impt);

    Element txt = document.createElement("Txt");
    txt.setTextContent("Text message");
    txtMsg.appendChild(txt);

    // Add the proprietary content to the ANY data of the standard structure
    mx.getCshMgmtPrtryMsg().getPrtryData().getData().setAny(root);

    // print the message
    MxWriteConfiguration conf = new MxWriteConfiguration();
    conf.headerPrefix = null;
    conf.documentPrefix = null;
    System.out.println(mx.message(conf));
}

ptorres-prowide avatar Feb 05 '24 19:02 ptorres-prowide