Skip to Content

Testing Adapter Module in NWDS

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on May 28, 2008 at 09:06 PM

    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:

    developing-user-enhancement-modules-in-adapter-eng

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2008 at 08:42 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.