cancel
Showing results for 
Search instead for 
Did you mean: 

Custom action with XML type input and output parameter.

Former Member
0 Kudos

Hi,

I want to develop custom action with xml type input and/or output parameter.

Is there sample code for java side. How is the definition of input and/or output parameter and set/get methods?

does it need special .jar file to develop custom action like this?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Cemil - yes, you can use XML data types. Use the class

com.sap.lhcommon.xml.XMLDataType

for your parameter type. Here is a snippet from a custom action we use to log XML (instead of just returning the #text node like the default logger does):

public class XMLLogger extends ActionReflectionBase
{
    private String source;
    private String eventType;
    private String textMessage;
    private XMLDataType xmlMessage;
    ...

    public XMLLogger()
    {
        log = new Logger("UserLog");
        source = DEFAULT_SOURCE;
        eventType = TYPE_INFO;
        textMessage = "";
        xmlMessage = new XMLDataType();
    }

    ...

    public XMLDataType getXmlMessage()
    {
        return xmlMessage;
    }

    public void setXmlMessage(XMLDataType xmlMessage)
    {
        this.xmlMessage = xmlMessage;
    }

    ...

    public void Invoke(Transaction transaction, ILog ilog)
    {
        StringBuffer sb = new StringBuffer();
        sb.append('[');
        sb.append(source);
        sb.append("] ");
        sb.append(textMessage);
        sb.append(XMLUtils.convertXmlToString(xmlMessage));
        ...
    }
}

XMLUtils is a helper class we wrote - it's just a bunch of standard Java XML boilerplate code. The important part you need to know is XMLDataType.getDocument() will return an org.w3c.dom.Document.

I hope that was enough information to help.

-tim

Former Member
0 Kudos

Tim,

thank you very much for the answer.

Could you give me the some import statements for the XMLUtils and teh Logger.

I did not find the libraries.

Thanks.

Former Member
0 Kudos

Cemil,

The logger was com.sap.xmii.system.Logger, but you should be using [NW logging API|http://help.sap.com/saphelp_nwce10/helpdata/en/4a/c3953ff1353c17e10000000a114084/frameset.htm].

As I explained in my previous, XMLUtils is a class we wrote - the import statement would do you no good. Once you have the org.w3c.dom.Document via XMLDataType.getDocument(), then you have everything you need. I don't have all my documentation in front of me, but I'm going to assume there is an XMLDataType.setDocument(org.w3c.dom.Document) method too. If you are interested, here is the standard Java code we use to transform the XML to a String:


   ...
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer();
   transformer.setOutputProperty(OutputKeys.INDENT, "yes");

   DOMSource source = new DOMSource(xml.getDocument());
   sw = new StringWriter();
   StreamResult result = new StreamResult(sw);
   transformer.transform(source, result);
   return sw.toString();
   ...

Note that the variable "xml" is an XMLDataType and that all exception handling is omitted.

-tim

Answers (3)

Answers (3)

Former Member
0 Kudos

Mike, there is no plan to update the article for 12.x. It would be nice, but I'm sufficiently removed from everyday development of our ERP integration that I no longer feel qualified to write it.

Besides, I'm still miffed that MII came out with dynamic transaction calls in 12.0. Part 2 of the series of articles was going to show how we implemented a dynamic transaction call custom action...

-tim

agentry_src
Active Contributor
0 Kudos

Tim,

You were one of the driving forces behind them creating the dynamic transaction call. I would be rather proud that they liked your idea enough to "borrow" it themselves.

If you do decide to publish again, can I request your Regular Expression action block as the subject?

Thanks,

Mike

Former Member
0 Kudos

Hi Tim and Mike,

Thanks you both for help.

I ask if there is XML typed parameter in custom action.

I already wrote some custom actions but parameters were simple types (string, integer etc. (not xml)).

I need som information if custom action has XML typed parameter.How to handle it in java side?

Is there sample for this variation of custom action.

Thanks.

Former Member
0 Kudos

The article Mike refers to is [here|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0407ed8-7f81-2a10-d49e-ea99d6b744cb]. This was for MII 11.5.

-tim

agentry_src
Active Contributor
0 Kudos

Tim,

Thanks for the link. I didn't go back far enough looking for it. Any plans to update it for 12.0 or 12.x?

Mike

agentry_src
Active Contributor
0 Kudos

Cemil,

Start here:

[https://wiki.sdn.sap.com/wiki/display/xMII/Customization]

Sam has not updated his custom action instructions from his 11.5 document, but most of it should still be useful information. I also think Tim Drury wrote an article about it. I will see if I can find a link to it if you need to see it. Let me know if you need more help than the wiki holds.

Regards,

Mike