I'm creating a java client for consume the web services exposed in Dynamics Navision. When I call the web services from chrome extensions as Wizdler the response is correct. But when I make the same call from my java code, the response is status code 400 (Server returned HTTP response code: 400). I call the web service with the same parameter in header and body as in Widzler. It appears that the error is the SOAP body format, but I don't see. Any idea?
These images are the call and the response with widzler.
This is my java code
private static String getAuthenticatedResponse(final String urlStr, final String domain,
final String userName, final String password,
String filtro) throws IOException, SOAPException {
StringBuilder response = new StringBuilder();
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(domain + "\\" + userName, password.toCharArray());
}
});
URL urlRequest = new URL(urlStr);
String msj = "<Soap:Envelope xmlns:Soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:es='urn:microsoft-dynamics-schemas/page/customer'><Soap:Header/><Soap:Body><es:ReadMultiple xmlns='urn:microsoft-dynamics-schemas/page/customer'></es:ReadMultiple></Soap:Body></Soap:Envelope>";
HttpURLConnection conn = (HttpURLConnection) urlRequest.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml; charset='utf-8'");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("SOAPAction", "urn:microsoft-dynamics-schemas/page/customer:ReadMultiple");
conn.setRequestProperty("Accept", "application/xml, text/xml, */*; q=0.01");
conn.connect();
OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(msj);
osw.flush();
osw.close();
InputStream stream = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
String str = "";
while ((str = in.readLine()) != null) {
response.append(str);
}
in.close();
conn.disconnect();
return response.toString();
}
And this is the error
<html><head><title>Apache Tomcat/7.0.52 - Informe de Error</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>Estado HTTP 500 - java.io.IOException: Server returned HTTP response code: 400 for URL: http://srv-w2k8-navisi:7047/DynamicsNAV70/WS/CRONUS%20Espa%C3%B1a%20S.A/Page/Customer</h1><HR size="1" noshade="noshade"><p><b>type</b> Informe de Excepción</p><p><b>mensaje</b> <u>java.io.IOException: Server returned HTTP response code: 400 for URL: http://srv-w2k8-navisi:7047/DynamicsNAV70/WS/CRONUS%20Espa%C3%B1a%20S.A/Page/Customer</u></p><p><b>descripción</b> <u>El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.</u></p><p><b>excepción</b> <pre>javax.servlet.ServletException: java.io.IOException: Server returned HTTP response code: 400 for URL: http://srv-w2k8-navisi:7047/DynamicsNAV70/WS/CRONUS%20Espa%C3%B1a%20S.A/Page/Customer
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre></p><p><b>causa raíz</b> <pre>java.io.IOException: Server returned HTTP response code: 400 for URL: http://srv-w2k8-navisi:7047/DynamicsNAV70/WS/CRONUS%20Espa%C3%B1a%20S.A/Page/Customer
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
com.datadec.navision.navisionWS.getAuthenticatedResponse(navisionWS.java:170)
com.datadec.navision.navisionWS.GetCompanies(navisionWS.java:122)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre></p><p><b>nota</b> <u>La traza completa de la causa de este error se encuentra en los archivos de diario de Apache Tomcat/7.0.52.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52</h3></body></html>