Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

PI Java Mapping NullPointerException

$
0
0

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.


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>