cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter Development for Dynamic EOIO Queue

former_member185881
Active Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Please check this link

Regards,

Praveen

former_member185881
Active Participant
0 Kudos

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

former_member185881
Active Participant
0 Kudos

Hello Praveen

queuePrefic = PRIM_ is not a field in payload. I am using this value as a constant and passing to module in field Elmnt1. I believe I am passing constant value in wrong way. Can you help me to correct this.

Regards

Dheeraj Kumar

Former Member
0 Kudos

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

former_member185881
Active Participant
0 Kudos

Hello Praveen

editing the reply because i missunderstood.

Thanks for the help.


One more thing I have to get another optional paramter from CC "PRIM_" which I need to concatinate before value SP-35677.

Thanks

Dheeraj Kumar

Message was edited by: Dheeraj Kumar

former_member185881
Active Participant
0 Kudos

Hello Praveen

For XPath xPath  which is the jar file you have imported.

I typed in code

import javax.xml.xpath.*;

at the time of deployment I am getting higher version error.

can we explicitly type in code these import statement or there is any different procesdure.

Thanks

Dheeraj Kumar

Former Member
0 Kudos

Hi Dheeraj,

I'm not using any jar files, i'm in java 6.

Which Java version you are having?  I think xpath will support from jdk 1.5

Regards,

Praveen

former_member185881
Active Participant
0 Kudos

Hello Praveen

I am in jdk 1.5

Regards

Dheeraj Kumar

former_member185881
Active Participant
0 Kudos

Hi Praveen

Thanks for all help.

My prob is resolved with the code you provided.

Now will work on concatinate function in this code.

Thanks

Dheeraj Kumar

Answers (1)

Answers (1)

ajay_wandre
Explorer
0 Kudos

Hello Dheeraj,

I find that your source payload is idoc; but idocs doesn't support module development.

Ajay Wandre