简体   繁体   English

Spring Rest模板Http客户端错误异常

[英]Spring Rest Template Http client error exception

RestTemplate Works fine with internal url but fails with public url. RestTemplate可以与内部url一起正常工作,但不能与公共url一起工作。

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    setTimeout(restTemplate , 40000 , 40000);
    return restTemplate;
}

private void setTimeout(RestTemplate restTemplate, int readTimeOut , int connectionTimeOut) {
    restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
    SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
    rf.setReadTimeout(readTimeOut);
    rf.setConnectTimeout(connectionTimeOut);
}

Is there any way to fix this issue ? 有什么办法可以解决此问题?

it throws Httpclientexception by restteamplate when accessing public url. 访问公共URL时,它会由restteamplate抛出Httpclientexception。

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request
17:24:46,913 INFO  [stdout] (default task-1)    at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:79) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO  [stdout] (default task-1)    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO  [stdout] (default task-1)    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO  [stdout] (default task-1)    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO  [stdout] (default task-1)    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:777) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO  [stdout] (default task-1)    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO  [stdout] (default task-1)    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO  [stdout] (default task-1)    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:578) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO  [stdout] (default task-1)    at com.epic.edbs.ib.serviceclient.RestClient.processRestCall(RestClient.java:46) ~[IB-1.00.jar:?]
17:24:46,915 INFO  [stdout] (default task-1)    at com.epic.edbs.ib.serviceclient.EswitchClient.processRequest(EswitchClient.java:92) ~[IB-1.00.jar:?]
17:24:46,915 INFO  [stdout] (default task-1)    at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl.getUserKey(ServiceKeyExchangeImpl.java:79) ~[classes:?]
17:24:46,915 INFO  [stdout] (default task-1)    at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl.getUserExchangeKey(ServiceKeyExchangeImpl.java:49) ~[classes:?]
17:24:46,916 INFO  [stdout] (default task-1)    at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl$$FastClassBySpringCGLIB$$df1e3370.invoke(<generated>) ~[classes:?]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,917 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,917 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,919 INFO  [stdout] (default task-1)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]

Finally I found the answer using below url. 最后,我在下面的网址中找到了答案。

I have missed @JsonIgnoreProperties(ignoreUnknown = true) annotation in request bean. 我错过了请求bean中的@JsonIgnoreProperties(ignoreUnknown = true)批注。

https://www.oipapio.com/question-9416560 https://www.oipapio.com/question-9416560

Thank you very much for your great contribution. 非常感谢您的巨大贡献。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Rest Template Client:拒绝连接到http:// localhost:8080 - Spring Rest Template Client : Connection to http://localhost:8080 refused Spring Rest客户端异常处理 - Spring Rest Client Exception Handling Spring Rest Client 希望看到错误消息而不是异常 - Spring Rest Client want to see error message instead of exception Spring Rest Template创建多部分表单/数据客户端,就像邮递员一样抛出不可转换的异常 - Spring Rest Template creating multipart form/data client working like a postman throws non convertable exception HTTP Get - Python 与 Spring Rest 模板 - HTTP Get - Python vs Spring Rest Template Spring WS-I / O错误:null; 嵌套的异常是org.apache.http.client.ClientProtocolException - Spring WS - I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 代理下 HTTP 客户端 4.5 的 Rest 模板的连接超时 - Connection Timeout for Rest Template with HTTP Client 4.5 under Proxy Spring rest 模板垃圾错误响应体 - Spring rest template garbage error response body 假装客户端内部服务器异常(其余模板也不起作用) - feign client internal server exception (rest template didnt work either) Angularjs $http spring rest 控制器 - 404 错误 - Angularjs $http spring rest controller - 404 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM