cancel
Showing results for 
Search instead for 
Did you mean: 

Testing Adapter Module in NWDS

former_member187563
Contributor
0 Kudos

hi,

I have got a code for adapter module,I wanted to test it standalone using NWDS.

class XML2EdifactBean

{

public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)

throws ModuleException { //Some Code... }

}

I am getting some error while executing the adapter module ,so I want to call the function using main method.Can you provide me with a sample code for this.

regards,

Ujjwal Kumar.

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

This would be too complex to do all necessary steps for a stand alone test.

I recommend to split the generic adapter module stuff and the part, you really want to do something.

For the adapter modul, which we used on Teched session:

I did following: I introduced a helper class and passed the DOM code

public class HelperClass {
	
	String hostElementName = "host";
	String hostName = "host";
	
	
    public static void main(String[] args) {
        try {
            InputStream in = new FileInputStream(new File("in.xml"));
            OutputStream out = new FileOutputStream(new File("out.xml"));
            new HelperClass().execute(in, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setHostElementName(String hostElementName){
    	this.hostElementName = hostElementName;
    }
    public void setHostName(String hostName){
    	this.hostName = hostName;
    }

    public void execute(InputStream in, OutputStream out){
    	try  {
    		DocumentBuilderFactory factory;
        factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(in);
        Element rootNode = document.getDocumentElement();
        if(rootNode != null)  {
            Element childElement =
            document.createElement(hostElementName);
            childElement.appendChild(document.createTextNode(hostName));
            rootNode.appendChild(childElement);
        }

        // Transforming the DOM object to Stream object.
        TransformerFactory tfactory = TransformerFactory.newInstance();
        Transformer transformer = tfactory.newTransformer();
        Source src = new DOMSource(document);
        
        Result dest = new StreamResult(out);
        transformer.transform(src,dest);
    	} catch(Exception e){}
    }
}

in the bean class, I used the helper class:

	XMLPayload xmlpayload = msg.getDocument();
            InputStream in = xmlpayload.getInputStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            HelperClass hc = new HelperClass();
            hc.setHostElementName(hostElementName);
            hc.setHostName(hostName);
            hc.execute(in,out);
            
            byte[] docContent = out.toByteArray();
            if(docContent != null)  {
                xmlpayload.setContent(docContent);
                inputModuleData.setPrincipalData(msg);
            }

Now I can test the parser in the NWDI

Regards

Stefan

Answers (1)

Answers (1)

Former Member
0 Kudos

hi ujjwal,

check the below links for reference,

/people/william.li/blog/2006/08/28/teched-2006-epi350--developing-and-testing-adapter-modules-in-sap-netweaver-exchange-infrastructure

/people/william.li/blog/2007/09/19/teched-2007-epi351--developing-user-enhancement-modules-in-the-adapter-engine

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00838345-708c-2a10-1199-9514c0b0...

webinar powerpoint presentation:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e21106cc-0c01-0010-db95-dbfc0ffd...

/people/alessandro.guarneri/blog/2006/03/16/xi-mapping-module-for-afw

Note: reward points if solution found helpfull

Regards

Chandrakanth.k