cancel
Showing results for 
Search instead for 
Did you mean: 

PI Java Mapping NullPointerException

Former Member
0 Kudos

Hi Gurus,

I'm having some troubles doing the mapping through java mapping in PI.

I've done the java class in the SAP NWDS and imported it on PI through the ESR.

Now i'm trying to test through the SOAP and i've found the following error in the "Communication Channel Monitor":

500   Internal Server Error  SAP NetWeaver Application Server/Java AS 

java.lang.NullPointerException: while trying to invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of a null object returned from com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()

And the following error in the SXMB_MONI:

<SAP:Category>XIServer</SAP:Category>

  <SAP:Code area="INTERNAL">CLIENT_SEND_FAILED</SAP:Code>

  <SAP:P1>500</SAP:P1>

  <SAP:P2>Internal Server Error</SAP:P2>

  <SAP:P3>(See attachment HTMLError for details)</SAP:P3>

  <SAP:P4 />

  <SAP:AdditionalText />

  <SAP:Stack>Error while sending by HTTP (error code: 500 , error text: Internal Server Error) (See attachment HTMLError for details)</SAP:Stack>

I've developed the code below:


public class PI_Mapping_IF extends AbstractTransformation {

  public void transform(TransformationInput in, TransformationOutput out)    throws StreamTransformationException  {  

  this.execute(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream()); 

  }

  public void execute(InputStream in, OutputStream out)  throws StreamTransformationException { 

  try  

  { 

  // Inicio do java mapping

  getTrace().addInfo("JAVA Mapping Iniciado"); //Log para o PI/XI

  // Declarações referentes ao XML de entrada

  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

  DocumentBuilder db = dbf.newDocumentBuilder();

  Document xml_in = db.parse(in);

  // Declarações referentes ao XML de saída

  Document xml_out = db.newDocument();

  TransformerFactory transformerFactory = TransformerFactory.newInstance();

  Transformer transformer = transformerFactory.newTransformer();

  // Remove o standalone

  xml_in.setXmlStandalone(true);

  // Declara a estrutura que a RFC irá receber

  Element root = xml_out.createElement("ns1:ZFSD_VMOI_UPLOAD_CF_PG");

  root.setAttribute("xmlns:ns1","urn:sap-com:document:sap:rfc:functions");

  xml_out.appendChild(root);

  Element i_cenario = xml_out.createElement("I_CENARIO");

  root.appendChild(i_cenario);

  Element t_input = xml_out.createElement("T_INPUT");

  root.appendChild(t_input);

  Element item = xml_out.createElement("ITEM");

  t_input.appendChild(item);

  Element STRING = xml_out.createElement("STRING");

  item.appendChild(STRING);

  Element t_return = xml_out.createElement("T_RETURN");

  root.appendChild(t_return);

  Element item_r = xml_out.createElement("ITEM");

  t_return.appendChild(item_r);

  Element message = xml_out.createElement("MESSAGE");

  item_r.appendChild(message);

  // Verifica se existe algum filho no nó

  NodeList nodos = xml_in.getChildNodes(); 

  if (nodos.item(0) != null)

  {    

  getTrace().addInfo("O nó(XML) possui filhos"); //Log para o PI/XI

  // Declaração de variáveis

  String ident = ""; // <Ident>

  String buyer = ""; // <BuyerLineItemNum>

  String result = ""; // <Ident>;<BuyerLineItemNum>;<Date>;<QuantityValue>

  // Inicia a extração das informações do XML

  try{

  // Recupera o nó ShipToParty

  NodeList nodeShip = xml_in.getElementsByTagName("ns0:ShipToParty");

  Node node = nodeShip.item(0);

  Element elemXML = (Element) node;

  try{

  NodeList nodeIdent = elemXML.getElementsByTagName("ns0:Ident");

  Element nameElement = (Element) nodeIdent.item(0);

  nodeIdent = nameElement.getChildNodes();

  // Recupera o valor da chave <Ident>

  ident = PI_Mapping_IF.VerifyNull(((Node) nodeIdent.item(0)).getNodeValue());

  }catch(Exception e){

  result += "0.0;";

  }

  // Recupera o nó ListOfMaterialGroupedPlanningDetail

  NodeList nodeBuyer  = xml_in.getElementsByTagName("ns0:MaterialGroupedPlanningDetail");

  for (int i = 0; i < nodeBuyer.getLength(); i++) {

  node = nodeBuyer.item(i);

  elemXML = (Element) node;

  try{

  // Preenche a chave BuyerLineItemNum

  NodeList nodeBuyerLine = elemXML.getElementsByTagName("ns0:BuyerLineItemNum");

  Element elemBuyerLine = (Element) nodeBuyerLine.item(0);

  nodeBuyerLine = elemBuyerLine.getChildNodes();

  buyer = PI_Mapping_IF.VerifyNull(((Node) nodeBuyerLine.item(0)).getNodeValue());

  }catch(Exception e){

  buyer += "0;";

  }

  result = ident+";"+buyer+";";

  Node nodeDt_Qnt = nodeBuyer.item(i);

  Element elemDt_Qnt = (Element)nodeDt_Qnt;

  NodeList nodeValores = elemDt_Qnt.getElementsByTagName("ns0:ScheduleDetail");

  for (int j = 0; j < nodeValores.getLength(); j++) {

  node = nodeValores.item(j);

  elemXML = (Element) node;

  try{

  // Preenche a chave Date

  NodeList modelExtra = elemXML.getElementsByTagName("ns0:Date");

  Element extraElement = (Element) modelExtra.item(0);

  modelExtra = extraElement.getChildNodes();

  result += PI_Mapping_IF.VerifyNull(((Node) modelExtra.item(0)).getNodeValue())+";";

  }catch(Exception e){

  result += "//;";

  }

  try {

  // Preenche a chave QuantityValue

  NodeList modelURL = elemXML.getElementsByTagName("ns0:QuantityValue");

  Element urlElement = (Element) modelURL.item(0);

  modelURL = urlElement.getChildNodes();

  result += PI_Mapping_IF.VerifyNull(((Node) modelURL.item(0)).getNodeValue())+";";

  } catch (Exception e) {

  result += "0.0;";

  }

  }

  // Marca o final do registro

  result += "||";

  // Preenche os nós itens

  Text srcxml = xml_out.createTextNode(result);

  STRING.appendChild(srcxml);

  result = "";

  buyer = "";

  }

  }catch(Exception e){

  }

  // Remove o standalone

  xml_out.setXmlStandalone(true);

  // Preenche o Cenario

  Text cenario = xml_out.createTextNode("P&G");

  i_cenario.appendChild(cenario);

  // Preenche mensagem de retorno

  Text msgxml = xml_out.createTextNode("XML lido com sucesso!");

  message.appendChild(msgxml);

  // Escreve a saida do XML            

  transformer.transform(new DOMSource(xml_out), new StreamResult(out));

  getTrace().addInfo("Fim da execução do Java Mapping");

  }

  } catch (ParserConfigurationException e) {

  getTrace().addWarning(e.getMessage());

  throw new StreamTransformationException("Can not create DocumentBuilder.", e);

  } catch (SAXException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  } catch (TransformerConfigurationException e) {

  e.printStackTrace();

  } catch (TransformerException e) {

  e.printStackTrace();

  }

  }

Am i doing anything wrong in the code? Where can this nullpointerexception be triggered?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi.

Try to use operation mapping test at ESR over similar payload, and send the stacktrace.

Former Member
0 Kudos

where is "ns0" bound to some namespace, by the way?

Former Member
0 Kudos

I haven't thought of doing this, now i'm investigating what could be wrong, since the ESR aren't working with the same XML from the SOAP.

Thank you very much for now

Former Member
0 Kudos

Didn't understand this question, what do you mean by bound "ns0" to a namespace?

Thanks.

Former Member
0 Kudos

These three xml are the same:

  • <?xml version="1.0"?><a:xml xmlns:a="urn:123">root</a:xml>
  • <?xml version="1.0"?><xml xmlns="urn:123">root</xml>
  • <?xml version="1.0"?><ns0:xml xmlns:ns0="urn:123">root</ns0:xml>

But your code will work only with last one, because it doesn't bound namespace to prefix ns0.

Former Member
0 Kudos

No, mapping test and runtime launch will work with the same payload, not <SOAP:Envelope> or sth like that. The main difference is only DynamicConfiguration and some runtime parameters (MessageId and so on), but your code doesn't use those.

Former Member
0 Kudos

You're right, but how can i do this?

Thanks.

Former Member
0 Kudos

Now it's working on ESR, but not in SOAP with the same XML..

Former Member
0 Kudos

As far as I remember, you should implement NamespaceContext class: NamespaceContext (Java Platform SE 6). I will look for example.

Former Member
0 Kudos

1. Is this java mapping the only one in operation mapping, or there are others mapping steps?

2. What is the URL for sending message to? (for example, you could use soapUI, provide us HTTP POST dump for sender)

Former Member
0 Kudos

Sorry for confusing you, NamespaceContext is only for XPath requests. For your way of extraction, instead of

NodeList nodeShip = xml_in.getElementsByTagName("ns0:ShipToParty"); 

you should use

NodeList nodeShip = xml_in.getElementsByTagNameNS("*", "ShipToParty"); 

or precise namespace:

NodeList nodeShip = xml_in.getElementsByTagNameNS("urn:tra-la-la:something-everywhere", "ShipToParty"); 
Former Member
0 Kudos

I've tried the two options, but it didn't work =/

Former Member
0 Kudos

The main problem was the Element name, the correct was "item" and i was creating "ITEM".

Thank you all!

Answers (0)