Spring MVC休息服务有400个不良请求进行一些调用

时间:2016-02-23 04:43:58

标签: rest spring-mvc http-status-code-400 bad-request

我有一个Spring mvc应用程序,我也有一些功能的休息服务。它在上周工作正常,但突然有些电话有问题。

我注意到所有这些调用都是“method = RequestMethod.PUT”类型的函数。我收到以下错误

org.springframework.web.client.HttpClientErrorException: 400 Bad Request
        at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
        at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:614)
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:570)
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
        at org.springframework.web.client.RestTemplate.put(RestTemplate.java:382)

我的控制器

@Controller
@RequestMapping("user/a2")
public class ABCController {

    @Autowired
    private ABCServices       ABCServices;


     @RequestMapping(
                value  = "user/{userName}/checkTest",
                method = {RequestMethod.GET, RequestMethod.POST} -----------------this call works fine
        )
        public @ResponseBody
        String check(@PathVariable String userName) {


     }

     @RequestMapping(
                value  = "user/{userName}/validateABCSS",  
                method = RequestMethod.PUT
            )
            public @ResponseBody 
            ResponseEntity<byte[]> validateABCSS(@PathVariable String userName, @RequestBody AAA uSS) {
                -----------------this call does not work


                if ("Success".equals(result)) {
                    return new ResponseEntity<byte[]>(HttpStatus.OK);
                } else {
                    return new ResponseEntity<byte[]>(result.getBytes(), HttpStatus.BAD_REQUEST);
                }
            }
}

RestClient.java,

public class RestClient {
    private RestTemplate restTemplate;
    private String       UN;
    private String       serverUrl;

    public RestClient() {
        restTemplate = new RestTemplate();
    }

    public RestClient(String pServerUrl, String key, String sec, String pUN) {



        ClientHttpRequestInterceptor tokenAuthInterceptor = new TokenAuthHeaderRequestInterceptor(key,sec, pUN);

        restTemplate.setInterceptors(Collections.singletonList(tokenAuthInterceptor));

        SSLContext sslContext = null;

        try {
            sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
        }  catch (Exception e) {

        }

        SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, 
                new String[]{"SSLv2Hello","SSLv3", "TLSv1"}, null, new AllowAllHostnameVerifier());


        HttpClient               httpClient     =
            HttpClientBuilder.create().setSSLSocketFactory(connectionFactory).build();
        ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

        restTemplate.setRequestFactory(requestFactory);
    }

    public enum ServiceURLs {

        VALIDATE_ABCSS("user/a2/user/{userName}/validateABCSS"), CheckTest("user/a2/user/{userName}/checkTest");

        private String id;
        private String url;

        private ServiceURLs(String id) {
            this.id  = id;
            this.url = id;
        }

        private ServiceURLs(String id, String url) {
            this.id  = id;
            this.url = url;
        }

        public String getId() {

            return this.id;
        }

        public String getUrl() {

            return this.url;
        }
    }


    public RestTemplate getRestTemplate() {
        return this.restTemplate;
    }
}

我将模板调用如下

getRestTemplate().put(serverUrl + RestClient.ServiceURLs.VALIDATE_ABCSS.getUrl(), pObject, getLogin()).

我唯一做的就是配置SSL,但现在将它们更改回旧状态(虽然密钥库有密钥)。我甚至使用只有http的URL。任何帮助赞赏。感谢。

设置:我的应用程序在tomcat中,其余服务应用程序在weblogic中,通过自定义应用程序(密钥和密钥)进行身份验证。

1 个答案:

答案 0 :(得分:0)

可能结果是假的。 检查结果值的原因是什么&#34; false&#34;。