[英]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.