Skip to Content
0

Debugging JAVA Mapping attachment read

Nov 30, 2017 at 03:54 PM

41

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Evgeniy Kolmakov Nov 30, 2017 at 05:02 PM
0

Hi Abhishek!

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

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
Abhishek Gupta Dec 01, 2017 at 10:24 AM
0

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

Show 1 Share
10 |10000 characters needed characters left 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.

0
ambuj mishra Dec 01, 2017 at 12:06 PM
0

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/

Share
10 |10000 characters needed characters left characters exceeded