Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Adapter Development for Dynamic EOIO Queue

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

Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question