title: java.io.IOException: Server returned HTTP response code: 500 for URL:"SoapEndPoint url"
body: <p>My soap API is running on localHost. It is working fine when i access it from the browser or soap UI. But it throws 500 error when I access it from my java client</p>
  
  <p>I tried to debug the code, but could not find anything. The server logs as well does not print anything. Only the tomcat access logs show the response code for the request</p>
  
  <pre><code>public class PostSoapRequest {
      String soapEndpointUrl = "http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger";
  
      public void postRequest(ChangeDeviceTrigger_Element changeDeviceTrigger) {
          try {
              URL obj = new URL(soapEndpointUrl);
              HttpURLConnection con = (HttpURLConnection) obj.openConnection();
              con.setRequestMethod("POST");
              con.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
              con.setRequestProperty("SOAPAction", "http://dpa.nokia.com/ChangeDeviceTrigger/");
              con.setRequestProperty("Connection", "Keep-Alive");
              con.setRequestProperty("User-Agent","Apache-HttpClient/4.1.1");
              String xml = RequestXml.getXmlRequest();
              con.setDoOutput(true);
              DataOutputStream wr = new DataOutputStream(con.getOutputStream());
              wr.writeBytes(xml);
              wr.flush();
              wr.close();
              String responseStatus = con.getResponseMessage();
              System.out.println("responseStatus :" + responseStatus);
              System.out.println("getResponseCode :" + con.getResponseCode());
              BufferedReader reader = null;
  
              if (con.getResponseCode() == 200) {
                  reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                  String inputLine;
                  StringBuffer response = new StringBuffer();
                  while ((inputLine = reader.readLine()) != null) {
                      response.append(inputLine);
              }
                  reader.close();
                  System.out.println("response:" + response.toString());
              }else {
                  reader = new BufferedReader(new InputStreamReader(con.getErrorStream()));
              }
              System.out.println(reader.read());
  
              BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
              String inputLine;
              StringBuffer response = new StringBuffer();
              while ((inputLine = in.readLine()) != null) {
                  response.append(inputLine);
              }
              in.close();
              System.out.println("response:" + response.toString());
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>exception:
      java.io.IOException: Server returned HTTP response code: 500 for URL:         <a href="http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger" rel="nofollow noreferrer">http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger</a>
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at     sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI    mpl.java:62)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
          at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1944)
          at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1939)
          at java.security.AccessController.doPrivileged(Native Method)
          at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1938)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1508)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
          at com.nokia.dpa.ChangeDeviceTrigger.post.PostSoapRequest.postRequest(PostSoapRequest.java:49)
          at com.nokia.dpa.ChangeDeviceTrigger.post.PostSoapRequest.main(PostSoapRequest.java:65)
  Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: <a href="http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger" rel="nofollow noreferrer">http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger</a>
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
          at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
          at java.net.HttpURLConnection.getResponseMessage(HttpURLConnection.java:546)
          at com.nokia.dpa.ChangeDeviceTrigger.post.PostSoapRequest.postRequest(PostSoapRequest.java:30)</p>