用于Dynamics Nav响应代码400的Java客户端

时间:2014-10-23 11:34:38

标签: java navision

我正在创建一个java客户端,用于使用Dynamics Navision中公开的Web服务。 当我从Chrome扩展名调用Web服务作为Wizdler时,响应是正确的。 但是当我从我的java代码进行相同的调用时,响应是状态代码400(服务器返回的HTTP响应代码:400)。 我在标题和正文中使用与Widzler相同的参数调用Web服务。 似乎错误是SOAP正文格式,但我不明白。 有什么想法吗?

这些图像是widzler的调用和响应。 Call from widzler Respose is ok

这是我的java代码

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

这就是错误

<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>

0 个答案:

没有答案