on 08-01-2014 11:24 AM
Hello All
I have developed the module to achieve Dynamic EOIO Queue.
I have deployed the module.
I am getting error = "An error occurred while processing message: 8b644171-fa18-4e01-1775-a4069728c0c3. The detailed error (if any): com.sap.aii.adapter.jms.api.channel.filter.MessageFilterException: while trying to invoke the method org.w3c.dom.Element.getChildNodes() of a null object loaded from local variable Elmnt1: NullPointerException: while trying to invoke the method org.w3c.dom.Element.getChildNodes() of a null object loaded from local variable 'Elmnt1' at com.sap.aii.adapter.jms.core.channel.filter.SendToModuleProcessorFilter.filter(SendToModuleProcessorFilter.java:95) ..."
Code
com.sap.adaptermodule;
java.rmi.RemoteException;
javax.ejb.EJBException;
javax.ejb.SessionBean;
javax.ejb.SessionContext;
javax.ejb.TimedObject;
javax.ejb.Timer;
org.w3c.dom.Document;
org.w3c.dom.Node;
org.w3c.dom.NodeList;
org.w3c.dom.Element;
java.io.InputStream;
javax.xml.parsers.DocumentBuilder;
javax.xml.parsers.DocumentBuilderFactory;
com.sap.aii.af.lib.mp.module.*;
com.sap.engine.interfaces.messaging.api.*;
public class DynamicEOIOBean implements SessionBean, TimedObject
{
static final String c_param1 = "queuePrefix";
static final String c_param2 = "Xmlnode";
private static final long serialVersionUID=100L;
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.TimedObject#ejbTimeout(javax.ejb.Timer)
*/
public void ejbTimeout(Timer arg0) {
// TODO Auto-generated method stub
}
public void ejbCreate() throws javax.ejb.CreateException
{
}
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)throws
ModuleException
{
try
{
String param1 = moduleContext.getContextData(c_param1);
String param2 = moduleContext.getContextData(c_param2);
Message msg = (Message) inputModuleData.getPrincipalData();
Payload payload = msg.getDocument();
InputStream inps = (InputStream) payload.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(inps);
doc.getDocumentElement().normalize();
NodeList nodeLst1 = doc.getElementsByTagName(param1);
NodeList nodeLst2 = doc.getElementsByTagName(param2);
Element Elmnt1 = (Element) nodeLst1.item(0);
Element Elmnt2 = (Element) nodeLst2.item(0);
NodeList ndLst1 = Elmnt1.getChildNodes();
NodeList ndLst2 = Elmnt2.getChildNodes();
String queueId;
if (ndLst1.item(0) != null)
queueId = ndLst1.item(0).getNodeValue().concat(ndLst2.item(0).getNodeValue());
else
queueId = msg.getSequenceId();
msg.setSequenceId(queueId);
inputModuleData.setPrincipalData(msg);
return inputModuleData;
} catch (Exception e) {
e.printStackTrace();
ModuleException me = new ModuleException("Unable to create Queue", e);
throw me;
}
}
}
Please help to resolve what need to change in code.
Thanks
Dheeraj Kumar
Hi Dheeraj,
Can you share your input xml?
It looks like that value for the parameters (param1 & param2) is not coming in your payload.
In your code, you have assigned param1 and param2 value as constant value with "queuePrefix" and "Xmlnode". Check whether <queuePrefix> and <xmlnode> field is coming in your payload.
Can you test by using below code and assign param1 and param2 value in channel?
String param1 = moduleContext.getContextData("param1");
String param2 = moduleContext.getContextData("param2");
Make sure that parameter values coming in your payload.
Regards,
Praveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Praveen
When I include my module in CC then payload does not generate.
When I delete my module then payload is generated as below:
<?xml version="1.0" encoding="UTF-8" ?>
- <YPSP6>
- <IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1" />
<YP6PROJ SEGMENT="1">
<PSPID>SP-35677</PSPID>
</YP6PROJ>
</IDOC>
</YPSP6>
See my CC screenshot
I am very confused ow to proceed now.
When I include my module then see the screenshot below which I am getting in CC monitoring
Thanks
Dheeraj Kumar
Hi Dheeraj,
Yes you're right. I misunderstood that its a field. Based on the input xml you provided, i understand that you need to get the dynamic queue name in child element.
For your parameter: /YPSP6/IDOC/YP6PROJ/PSPID, you need to code to get value based on the xpath like below.
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("/YPSP6/IDOC/YP6PROJ/PSPID").evaluate(doc, XPathConstants.NODESET);
Please use below code and test, it works for me.
Code:
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
throws ModuleException {
try {
String param1 = (String) moduleContext.getContextData("param1");
//String param2 = (String) moduleContext.getContextData("param2");
Message msg = (Message) inputModuleData.getPrincipalData();
Payload payload = msg.getDocument();
InputStream inps = (InputStream) payload.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(inps);
doc.getDocumentElement().normalize();
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile(param1).evaluate(doc, XPathConstants.NODESET);
//NodeList nodeLst1 = doc.getElementsByTagName(param1);
//NodeList nodeLst2 = doc.getElementsByTagName(param2);
//Element Elmnt1 = (Element) nodeLst1.item(0);
//NodeList ndLst1 = Elmnt1.getChildNodes();
String queueId;
if (nodeList.item(0) != null)
queueId =nodeList.item(0).getFirstChild().getNodeValue();
else
queueId = msg.getSequenceId();
msg.setSequenceId(queueId);
inputModuleData.setPrincipalData(msg);
return inputModuleData;
}
catch (Exception e) {
e.printStackTrace();
ModuleException me = new ModuleException("Unable to create Queue", e);
throw me;
}
}
Sender Channel:
Input XML:
<?xml version="1.0" encoding="utf-8" ?>
<YPSP6><IDOC BEGIN="1"><YP6PROJ SEGMENT="1"><PSPID>SP-35677</PSPID></YP6PROJ></IDOC></YPSP6>
Message in Sxmb_Moni:
Thanks
Regards,
Praveen
Hello Dheeraj,
I find that your source payload is idoc; but idocs doesn't support module development.
Ajay Wandre
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
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.