Web services getConnetion()返回WebSphere7上的404代码

Web services getConnetion()返回WebSphere7上的404代码,web-services,rest,spring-integration,websphere-7,Web Services,Rest,Spring Integration,Websphere 7,我已经使用Spring集成实现了一个REST服务。 当我尝试使用main函数手动访问服务时,它工作正常。 我还在谷歌Chrome中使用REST客户端测试了这项服务,效果良好。但该服务将在WebSphere server上返回responseCode 404。因此,当我在更高的环境中部署代码时,我面临着这个问题 URL u = new URL("http://localhost:8080/MyApplication/testRestService"); URLConnection uc =

我已经使用Spring集成实现了一个REST服务。 当我尝试使用main函数手动访问服务时,它工作正常。 我还在谷歌Chrome中使用REST客户端测试了这项服务,效果良好。但该服务将在WebSphere server上返回responseCode 404。因此,当我在更高的环境中部署代码时,我面临着这个问题

  URL u = new URL("http://localhost:8080/MyApplication/testRestService");
  URLConnection uc = u.openConnection();
  HttpURLConnection connection = (HttpURLConnection) uc;

  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Accept","*/*");      
  connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

  OutputStream out = connection.getOutputStream();
  Writer wout = new OutputStreamWriter(out);

  //helper function that gets a string from a dom Document
  String input = jsonInput;
  wout.write(input.getBytes());        
  wout.flush();
  wout.close();

  // Response
  int responseCode = connection.getResponseCode();
它依赖于服务器,所以返回时响应代码为404?我们需要任何服务器端配置吗


任何建议都将不胜感激。

我尝试使用Apache HTTP客户端,代码现在正在WebSphere上运行。我仍然无法找到java.net.HttpURLConnection无法在WebSphere上工作的原因

请在下面找到我的更新代码:

DefaultHttpClient httpClient = null;
        HttpPost postRequest = null;
        StringEntity inputEntity = null;
        HttpResponse response = null;
        try{


            //RETREIVE WEB SERVICE URL FROM DB
            String callbackURL = "http://localhost:8080/MyApplication/testRestService";
            httpClient = new DefaultHttpClient();
            postRequest = new HttpPost(callbackURL);            
            String inputData = request.toString();

            inputEntity = new StringEntity(inputData);
            inputEntity.setContentType("application/x-www-form-urlencoded");
            postRequest.setEntity(inputEntity);

            response = httpClient.execute(postRequest);



            if (response.getStatusLine().getStatusCode() != 201 && response.getStatusLine().getStatusCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "+ response.getStatusLine().getStatusCode());
            }

            //System.out.println("HTTP Response Code :"+response.getStatusLine().getStatusCode());
            LOGGER.debug("HTTP Response Code :"+response.getStatusLine().getStatusCode());

            httpClient.getConnectionManager().shutdown();
        }catch(IOException ex){
            ex.printStackTrace();
            throw ex;
        }finally{
            httpClient.getConnectionManager().shutdown();
            httpClient = null;
            postRequest = null;
            inputEntity = null;
            response = null;
        }

为什么对
URLConnection
httpClient
使用不同的
ContentType


请显示您的REST服务配置:
404
表示
未找到
。因此,您在请求中使用(或不使用)一些选项,这使得它与服务器的
RequestMapping
不匹配

我的解决方案是使用Apache HTTP客户端API解决的。使用wireshark之类的网络监视器(或eclipse内置的)来比较来自每个客户端的数据。既然您已经使用Spring,考虑使用<代码> RestMedis< /Cord>,它将消除您在直接编码客户端时需要的大量样板代码。我编辑了这个问题。我在这里粘贴了单元测试核心,所以提到了错误的内容类型。我使用的是“application/x-www-form-urlencoded”内容类型。如果请求参数中缺少某些内容,那么当我在主程序和jetty服务器内部测试时,为什么相同的代码可以工作。只有当我将其部署到Wbsphere7应用服务器的更高环境中时,才会出现创建问题。。。