简体   繁体   中英

java.io.IOException: Server returned HTTP response code: 500 for URL:“SoapEndPoint url”

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

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

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();
        }

    }

exception: java.io.IOException: Server returned HTTP response code: 500 for URL: http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger 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: http://10.142.240.103:8082/notification-adaptor/services/ChangeTrigger 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)

I found the soap request xml that was posted to the service endpoint was wrong. There was an extra "\\" character in the request. The issue is not fixed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM