出现错误:UnknownContentTypeException,HttpMessageConverter 不支持 text/html 类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
10935 2020-11-10 14:43:24.036 WARN  [pool-7-thread-64               ] [JwtApiClientExecutor                                  ] >>>>>>>>>>>>>>>> JWT API restTemplate.exchange exception  - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecu      tor.java:73
10936 org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.fasterxml.jackson.databind.JsonNode] and content type [text/html]
10937 at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:126)
10938 at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:998)
10939 at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:981)
10940 at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:741)
10941 at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
10942 at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583)
10943 at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor.execute(JwtApiClientExecutor.java:71)
10944 at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$FastClassBySpringCGLIB$$6e21617c.invoke(<generated>)
10945 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
10946 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
10947 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
10948 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
10949 at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:100)
10950 at com.decathlon.sfc.order.bff.core.aspect.ElkLoggingAspect.aroundAdvice(ElkLoggingAspect.java:39)
10951 at jdk.internal.reflect.GeneratedMethodAccessor169.invoke(Unknown Source)
10952 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10953 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
10954 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
10955 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
10956 at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
10957 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
10958 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
10959 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
10960 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
10961 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
10962 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
10963 at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$EnhancerBySpringCGLIB$$e2ad8559.execute(<generated>)
10964 at com.decathlon.sfc.order.bff.core.entity.output.ApiOutput.execute(ApiOutput.java:80)
10965 at com.decathlon.sfc.order.bff.core.entity.task.Task.executeOutput(Task.java:133)
10966 at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
10967 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
10968 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
10969 at java.base/java.lang.Thread.run(Thread.java:834)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2020-11-10 16:30:20.404 INFO  [pool-10-thread-1               ] [JwtApiClientExecutor                                  ] >>>>>>>>>>>>>>>>> JWT API request 准备发出  - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecutor.java:74
2020-11-10 16:30:20.725 WARN [pool-10-thread-1 ] [JwtApiClientExecutor ] >>>>>>>>>>>>>>>> JWT API restTemplate.exchange exception - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecutor.java:79
org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.fasterxml.jackson.databind.JsonNode] and content type [application/json]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:126)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:998)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:981)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:741)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor.execute(JwtApiClientExecutor.java:77)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$FastClassBySpringCGLIB$$6e21617c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:100)
at com.decathlon.sfc.order.bff.core.aspect.ElkLoggingAspect.aroundAdvice(ElkLoggingAspect.java:39)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$EnhancerBySpringCGLIB$$94a8788c.execute(<generated>)
at com.decathlon.sfc.order.bff.core.entity.output.ApiOutput.execute(ApiOutput.java:88)
at com.decathlon.sfc.order.bff.core.entity.task.Task.executeOutput(Task.java:133)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2020-11-10 16:02:47.935 INFO  [pool-10-thread-1               ] [JwtApiClientExecutor                                  ] >>>>>>>>>> 准备拿 token  - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecutor.java:40
2020-11-10 16:02:47.966 WARN [pool-10-thread-1 ] [JwtApiClientExecutor ] getToken 出现错误 - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecutor.java:45
java.lang.IllegalArgumentException: Content-Type cannot contain wildcard type '*'
at org.springframework.util.Assert.isTrue(Assert.java:118)
at org.springframework.http.HttpHeaders.setContentType(HttpHeaders.java:949)
at org.springframework.http.converter.AbstractHttpMessageConverter.addDefaultHeaders(AbstractHttpMessageConverter.java:256)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:88)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:943)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:737)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:418)
at com.decathlon.sfc.order.bff.core.apiclient.credential.TokenCredential.getToken(TokenCredential.java:123)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor.execute(JwtApiClientExecutor.java:43)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$FastClassBySpringCGLIB$$6e21617c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:100)
at com.decathlon.sfc.order.bff.core.aspect.ElkLoggingAspect.aroundAdvice(ElkLoggingAspect.java:39)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor$$EnhancerBySpringCGLIB$$4ecaf1a4.execute(<generated>)
at com.decathlon.sfc.order.bff.core.entity.output.ApiOutput.execute(ApiOutput.java:80)
at com.decathlon.sfc.order.bff.core.entity.task.Task.executeOutput(Task.java:133)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
2020-11-10 16:02:47.967 INFO [pool-10-thread-1 ] [JwtApiClientExecutor ] >>>>>>>>>> 拿到 token:null - com.decathlon.sfc.order.bff.core.apiclient.JwtApiClientExecutor - JwtApiClientExecutor.java:48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    public static RestTemplate diyRestTemplate(){
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM,MediaType.TEXT_HTML, MediaType.TEXT_PLAIN));
restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
return restTemplate;
}



jwt.setRestTemplate(new RestTemplate());
》》》jwt.setRestTemplate(RestTemplateConfig.diyRestTemplate());



ResponseEntity<Object> response = restTemplate.exchange(options.getUrl(), HttpMethod.POST, new HttpEntity<>(bizParamBody, headers), Object.class);
ObjectMapper objectMapper = new ObjectMapper();
String str = objectMapper.writeValueAsString(response.getBody());
JsonNode jsonNode = objectMapper.readTree(str);


Object objectResponse = restTemplate.postForObject(requestUrl, bodyNode, Object.class);
objectMapper.readTree(objectMapper.writeValueAsString(objectResponse));