on 05-26-2008 9:17 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
webinar powerpoint presentation:
/people/alessandro.guarneri/blog/2006/03/16/xi-mapping-module-for-afw
Note: reward points if solution found helpfull
Regards
Chandrakanth.k
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.