title: java logging the xml response from a server
body: <pre><code>HTTP/1.1 500 Internal Server Error
  Content-Type: application/xml; charset=UTF-8
  Connection: close
  Content-Length: 401
  
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; 
  &lt;fulfillmentService&gt;&lt;responseCode&gt;1106&lt;/responseCode&gt; 
  &lt;status&gt;FAILURE&lt;/status&gt;&lt;systemType&gt;CIS&lt;/systemType&gt; 
  &lt;responseDescription&gt;Sorry! We are unable to process your request. Call 111 for customer care or visit www.mtnzambia.com.&lt;/responseDescription&gt;&lt;requestId&gt;WEB_10.100.244.97_92505288-f094-4834-a978-658c19e3f656&lt;/requestId&gt;&lt;/fulfillmentService&gt;
  </code></pre>
  
  <p>I need a way of logging this XML response in java. When I send a request from my java this is what is returned. I need a way of printing out the response description.</p>
  
  <p>Below is my java code:</p>
  
  <pre><code> url = new URL(endpoint);
  
  
          connection = (HttpURLConnection) url.openConnection();
    responseCode = connection.getResponseCode();
          respTxt = connection.getResponseMessage();
          System.out.println("Status code after sending the the payload to mtn =&gt; " + responseCode + " Now waiting for response: ");
          Object vm = connection.toString();
          //   BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          PrintWriter pw = new PrintWriter(connection.getOutputStream());
  
          // send xml to jsp
          // pw.write(buffer, 0, bytes_read);
          // pw.close();
          BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null) {
              System.out.println(inputLine);
          }
  </code></pre>