简体   繁体   中英

NullPointerException while invoking method getInputParameters()

I am doing Parameterized Java Mapping in SAP PI 7.5 with following parameters bound by the tag names specified in the Operation Mapping

(BS_NAME,CHANNEL_NAME,EMAIL). 

On testing the below java mapping in the test tab of OM using the payload, it gives the following error:

NullPointerException while trying to invoke the method com.sap.aii.mapping.api.TransformationInput.getInputParameters() of a null object loaded from field of an object loaded from local variable "this**"

I debugged the code but didn't found the issue, any suggestions?

Please find below Java code for XmlNFe_To_Mail Class. BodyText Class is also used to fetch some content. The error is encountered in the XmlNFe_To_Mail Class.

public class XmlNFe_To_Mail extends AbstractTransformation {
private String prefixoSubject = new String();
private String emailFrom = new String();
private String prefixoDocumento = new String();
private String frase = new String();
private String gap = "\n\r";
private AbstractTrace trace = null;
private Map map = null;
private String BSSystem = "";
private String ComChannel = "";
private String Emails = "";
private final String NFE_EMPRESA = "NFE Company: ";
private final String NFe = "NFE";
private final String NFe_Mail = "nfe@company.com";
TransformationInput input = null;
TransformationOutput output = null;
public void execute(InputStream in , OutputStream out) throws StreamTransformationException {
    // TODO Auto-generated method stub
    {
        BSSystem = input.getInputParameters().getString("BS_NAME");
        ComChannel = input.getInputParameters().getString("CHANNEL_NAME");
        Emails = input.getInputParameters().getString("EMAIL");
        try {
            configParamEmail();
            BufferedReader inpxml = new BufferedReader(new InputStreamReader( in ));
            StringBuffer buffer = new StringBuffer();
            String line = "";
            String quebra = System.getProperty("line.separator");
            while ((line = inpxml.readLine()) != null) {
                line.replaceAll("\r\n", "");
                line.replaceAll(quebra, "");
                line.replaceAll(" />", "/>");
                line.replaceAll(" />", "/>");
                line.replaceAll(" />", "/>");
                buffer.append(line);
            }
            String inptxml = buffer.toString();
            inptxml = inptxml.replace("\r\n", "");
            inptxml = inptxml.replaceAll(quebra, "");
            inptxml = inptxml.replaceAll(" />", "/>");
            inptxml = inptxml.replaceAll(" />", "/>");
            inptxml = inptxml.replaceAll(" />", "/>");
            String idNFe = "";
            String numeroNF = "";
            String idEvent = "";
            idNFe = inptxml.substring(inptxml.indexOf("<chNFe>") + 7, inptxml.indexOf("</chNFe>"));
            numeroNF = idNFe.substring(25, 34);
            if (inptxml.indexOf("infEvento") > 0) {
                idEvent = inptxml.substring(inptxml.indexOf("<tpEvento>") + 10, inptxml.indexOf("</tpEvento>"));
                if (idEvent.length() > 0) {
                    if (idEvent.equals("111111")) {
                        this.setPrefixoDocumento(this.getPrefixoDocumento().replaceAll("NFE", "CancNFe"));
                        this.setPrefixoSubject(this.getPrefixoSubject().replaceAll("NFE", "NFE CANCELADA"));
                    } else if (idEvent.equals("100000")) {
                        this.setPrefixoDocumento(this.getPrefixoDocumento().replaceAll("NFE", "CCE"));
                        this.setPrefixoSubject(this.getPrefixoSubject().replaceAll("NFE", "CCE"));
                    } else {
                        this.setPrefixoDocumento(this.getPrefixoDocumento().replaceAll("NFE", "ManDest"));
                        this.setPrefixoSubject(this.getPrefixoSubject().replaceAll("NFE", "MANIFESTO"));
                    }
                }
            }
            Channel chn = null;
            RfcAccessor rfc = null;
            String email = "";
            String pdf = "";
            chn = LookupService.getChannel(getBSystem(), getCChannel());
            rfc = LookupService.getRfcAccessor(chn);
            String req = "<ns0:TEST_NFE_MAIL_OPT xmlns:ns0='urn:sap-com:document:sap:rfc:functions'><I_ACCESS_KEY>" +
                idNFe + "<I_ACCESS_KEY></ns0:ZOTC_NFE_EMAIL_OUTPUT>";
            InputStream inputRFC = new ByteArrayInputStream(req.getBytes("UTF-8"));
            XmlPayload rfcPayload = LookupService.getXmlPayload(inputRFC);
            XmlPayload result = rfc.call(rfcPayload);
            InputStream resp = result.getContent();
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(resp);
            Node node = (Node) doc.getElementsByTagName("E_EMAIL").item(0);
            if (node.hasChildNodes() && !node.getFirstChild().getNodeValue().equals("")) {
                email = node.getFirstChild().getNodeValue();
            }
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transform = tf.newTransformer();
            Document docout = db.newDocument();
            Element root = docout.createElement("ns0:Mail");
            root.setAttribute("xmlns:ns0", "http://sap.com/xi/XI/Mail/30");
            docout.appendChild(root);
            Element subject = docout.createElement("Subject");
            root.appendChild(subject);
            Text subjectText = docout.createTextNode(getPrefixoSubject() + numeroNF);
            subject.appendChild(subjectText);
            Element from = docout.createElement("From");
            root.appendChild(from);
            Text fromText = docout.createTextNode(getEmailFrom());
            from.appendChild(fromText);
            if (email.length() > 0) {
                email += ";";
            } else {
                email = this.getEmaillist();
            }
            Element to = docout.createElement("To");
            root.appendChild(to);
            Text toText = docout.createTextNode(email);
            to.appendChild(toText);
            Element contentType = docout.createElement("Content_Type");
            root.appendChild(contentType);
            Text contentTypeText = docout.createTextNode("multipart/mixed;boundary=--AaZz");
            contentType.appendChild(contentTypeText);
            BodyText texto = new BodyText(idNFe, getFrase(), inptxml, pdf);
            Element content = docout.createElement("Content");
            root.appendChild(content);
            Text contentText = null;
            if ("NFE Company: ".equalsIgnoreCase(getPrefixoSubject())) {
                contentText = docout.createTextNode(texto.getnfeText());
            } else if ("NFE CANCELADA Company: ".equalsIgnoreCase(getPrefixoSubject())) {
                contentText = docout.createTextNode(texto.getCnfeText());
            } else if ("CCE Company: ".equalsIgnoreCase(getPrefixoSubject())) {
                contentText = docout.createTextNode(texto.getcceText());
            }
            content.appendChild(contentText);
            DOMSource domS = new DOMSource(docout);
            transform.transform((domS), new StreamResult(out));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // Exception Handling }
        }
    }
}
public String getGap() {
    return gap;
}
public void setGap(String gap) {
    this.gap = gap;
}
public String getFrase() {
    return frase;
}
public void setFrase(String frase) {
    this.frase = frase;
}
public String getBSystem() {
    return BSSystem;
}
public String getEmaillist() {
    return Emails;
}
public String getCChannel() {
    return ComChannel;
}
public String getPrefixoSubject() {
    return prefixoSubject;
}
public void setPrefixoSubject(String prefixoSubject) {
    this.prefixoSubject = prefixoSubject;
}
public String getEmailFrom() {
    return emailFrom;
}
public void setEmailFrom(String emailFrom) {
    this.emailFrom = emailFrom;
}
public String getPrefixoDocumento() {
    return prefixoDocumento;
}
public void setPrefixoDocumento(String prefixoDocumento) {
    this.prefixoDocumento = prefixoDocumento;
}
private void configParamEmail() {
    setEmailFrom(NFe_Mail);
    setPrefixoDocumento(NFe);
    setPrefixoSubject(NFE_EMPRESA);
}
@Override
public void transform(TransformationInput in , TransformationOutput out) throws StreamTransformationException {
    this.execute( in .getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}
/*public void setParameter(Map arg0) {
// TODO Auto-generated method stub
}*/

}

Kindly let me know what changes should be done. Thanks.

It's missing instance from the TransformationInput/TransformationOutput classes because their variables are null,

   TransformationInput input = null;               
   TransformationOutput output = null;

So you need to instance them or pass them as reference on some setter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM