Developers Program

How to log api request and response xmls to a file in JAVA

Published: July 07 2006, 6:21:00 PMยทUpdated: July 24 2022, 4:42:29 PM

Products

Answer

1. Add these lines to your class Constructor :

String apiOutputFile="c:\\tmp\\api_output.txt";
String errorOutputFile="c:\\tmp\\api_error.txt";
try {
java.io.PrintStream output = new java.io.PrintStream(new java.io.BufferedOutputStream(new java.io.FileOutputStream(apiOutputFile)));
System.setOut(output);
java.io.PrintStream errors = new java.io.PrintStream(new java.io.BufferedOutputStream(new java.io.FileOutputStream(errorOutputFile)));
System.setErr(errors);
}catch(java.io.IOException ioe) {
//handle exception ...
}

2. Enable logging following the instructions in this KB article:

Enable logging for Java SDK

How well did this answer your question?