Skip to Content

Debugging JAVA Mapping attachment read

Hi SDNites,

I have written a JAVA mapping to read the attachment and it is not generating the expected output. Can you please advise how can I debug standalone the JAVA mapping which is reading the attachment and doing additional steps on it.

Regards,

Abhi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Nov 30, 2017 at 05:02 PM

    Hi Abhishek!

    For local testing you could use FileOutputStream and save your attachment as file.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 01, 2017 at 10:24 AM

    Thanks Evgeniy.

    With attachment we have to use different class and method. So it might not be a real test locally. Please advise if I understood your statement correctly.

    Regards,

    Abhi

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Abhishek!

      If you want to test if your attachment's contents is built correctly - you could follow the way, I've described.

      After that you just change the code to save byte array, representing your attachment to attachments section.

      Regards, Evgeniy.

  • Dec 01, 2017 at 12:06 PM

    You can write/enhance below code accordingly in NWDS or Eclipse for local testing.

    Class Test{
    public static void main(String[] args) {
    
    try{
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
            dbf.setValidating(false); 
            DocumentBuilder db = dbf.newDocumentBuilder();   
    // replace following  path with your input xml path 
             Document doc = db.parse(new FileInputStream(new File  ("D:\\input1.xml")));
    // replace following  path with your output xml path 
             File OutputDOM = new File("D:\\log.txt");
                FileOutputStream fostream = new FileOutputStream(OutputDOM);
                OutputStreamWriter oswriter = new OutputStreamWriter (fostream);
                BufferedWriter bwriter = new BufferedWriter(oswriter);
    
    // if file doesnt exists, then create it
                if (!OutputDOM.exists()) {
                    OutputDOM.createNewFile();}
    //Write your code within this method
                yourCode(doc,bwriter);
                bwriter.close(); 
    oswriter.close(); 
    fostream.close();
                System.out.println("Log writing completed");
    }
    catch (Exception e)
    {
    System.out.println(e.getMessage());
    }
    
    }
    
    public static void yourCode(Node node, BufferedWriter bw) throws IOException{ 
    {
    //perform some logic on doc and write using String
    
    //Write logs or use system.out.println to debug i console
    System.out.println("WRITING SOME LOGS");
                bw.write("logs");
                bw.newLine();
    
    }
    }

    Reference:

    https://blogs.sap.com/2014/04/02/file-content-conversion-in-esr-using-java-mapping/

    https://blogs.sap.com/2015/06/16/creating-multiple-files-zipping-sending-as-email-attachments-using-java-mapping/

    Add comment
    10|10000 characters needed characters exceeded