简体   繁体   English

找不到适合响应类型和内容类型的HttpMessageConverter

[英]no suitable HttpMessageConverter found for response type and content type

I was trying to get the ResponseEntity with spring rest template as given below. 我试图获得带有Spring rest模板的ResponseEntity,如下所示。 I am getting the below error, 我收到以下错误,

Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface org.springframework.security.oauth2.common.OAuth2AccessToken] and content type [application/json;charset=ISO-8859-1]

Code: 码:

ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();

        resource.setAccessTokenUri("https://.../oauth2/token");
        resource.setUsername("u");
        resource.setPassword("p");
        resource.setClientSecret(".....s");
        resource.setClientId("....i");
        resource.setGrantType("password");
        List<String> scopes = new ArrayList<String>(2);
        scopes.add("write");
        scopes.add("read");
        resource.setScope(scopes);
         OAuth2RestTemplate oAuthRestTemplate =  new OAuth2RestTemplate(resource);

    try{
        SSLUtil.turnOffSslChecking();
        ResponseEntity<String> result = oAuthRestTemplate.getForEntity("https:......." + "/api/version", String.class);
        System.out.println(result);
          } catch (RestClientException e) {         
            e.printStackTrace();
        }

I tried setting Media type as Application/json as in this post.But still the same error. 我在这篇文章中尝试将媒体类型设置为Application / json。但是仍然是相同的错误。

Full trace: 完整跟踪:

Exception in thread "main" error="access_denied", error_description="Error requesting access token."
    at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:121)
    at org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider.obtainAccessToken(ResourceOwnerPasswordAccessTokenProvider.java:47)
    at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:142)
    at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:118)
    at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:216)
    at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:168)
    at org.springframework.security.oauth2.client.OAuth2RestTemplate.createRequest(OAuth2RestTemplate.java:89)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:479)
    at org.springframework.security.oauth2.client.OAuth2RestTemplate.doExecute(OAuth2RestTemplate.java:123)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:446)
    at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:236)
    at com.ClientTemplate.main(ClientTemplate.java:56)
Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface org.springframework.security.oauth2.common.OAuth2AccessToken] and content type [application/json;charset=ISO-8859-1]
    at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:107)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:491)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:454)
    at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:113)
    ... 11 more

You need to add MappingJackson2HttpMessageConverter and add content type to be application/json to the header. 您需要添加MappingJackson2HttpMessageConverter并向标头添加内容类型为application/json See here 这里

暂无
暂无

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

相关问题 没有找到适合响应类型的 HttpMessageConverter - no suitable HttpMessageConverter found for response type 找不到适用于响应类型[..]和内容类型[application / json]的HttpMessageConverter - No suitable HttpMessageConverter found for response type [..] and content type [application/json] 没有为响应类型找到合适的HttpMessageConverter - Custom RestTemplate - No suitable HttpMessageConverter found for response type - Custom RestTemplate 无法提取响应:没有找到适合响应类型 class 和内容类型 [text/html] 的 HttpMessageConverter - Could not extract response: no suitable HttpMessageConverter found for response type class and content type [text/html] 没有找到适合响应类型和内容类型的 HttpMessageConverter [application/json;charset=UTF-8] 发生异常 - No suitable HttpMessageConverter found for response type and content type [application/json;charset=UTF-8] exception occurs Android版Spring-无法提取响应:找不到适合响应类型的HttpMessageConverter - Spring for Android - Could not extract response: no suitable HttpMessageConverter found for response type RestClientException无法提取响应:找不到合适的HttpMessageConverter作为响应类型 - RestClientException Could not extract response: no suitable HttpMessageConverter found for response type 找不到适合响应类型 [class org.springframework.http.ResponseEntity] 和内容类型 [application/octet-stream] 的 HttpMessageConverter - No suitable HttpMessageConverter found for response type [class org.springframework.http.ResponseEntity] and content type [application/octet-stream] 契约:未找到响应类型的HttpMessageConverter - Pact: no HttpMessageConverter found for response type 找不到适合请求类型 [java.util.LinkedHashMap] 和内容类型 [multipart/form-data] 的 HttpMessageConverter - no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM