简体   繁体   English

找不到内容类型为text / html的MessageBodyReader并键入接口java.util.List

[英]Unable to find a MessageBodyReader of content-type text/html and type interface java.util.List

Please do not consider it as duplicate request as i have gone through all the post in stackoverflow, none of them answered. 请不要将其视为重复的请求,因为我已经遍历了stackoverflow中的所有帖子,没有一个回答。 no response i found. 我没有找到回应。

Issue is : 问题是:

I am facing a very weird issue making a GET request with same piece of code via standalone application (inside main()). 我面临着一个非常奇怪的问题,即通过独立的应用程序(在main()内部)使用相同的代码发出GET请求。 It works where as if the same code is put in Java EE app and deployed on a wildfly 10 server, it gives Error 它可以像在Java EE应用程序中放入相同代码并将其部署在wildfly 10服务器上一样工作,它会产生错误

"Unable to find a MessageBodyReader of content-type text/html and type interface java.util.List" “无法找到内容类型为text / html的MessageBodyReader并键入接口java.util.List”

Code: 码:

ClientConfig configuration = new ClientConfig();
configuration.property(ClientProperties.CONNECT_TIMEOUT, 10000);
configuration.property(ClientProperties.READ_TIMEOUT, 10000);
Client iexRestClient=ClientBuilder.newClient(configuration);
WebTarget webTarget = 
iexRestClient.target("https://api.iextrading.com/1.0/ref-data/symbols/");
Response response = 
webTarget.request().accept(MediaType.APPLICATION_JSON).get(Response.class);
System.out.println("response status "+response.getStatus());
List<IEXTicker> tickers = response.readEntity(new 
GenericType<List<IEXTicker>>(){});
System.out.println("size of tickers "+tickers.size());

Required jars(pom.xml file) 所需的jars(pom.xml文件)

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.26</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
    <version>2.26</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.26</version>
</dependency>

Model class : IEX_Ticker.java 模型类:IEX_Ticker.java

@Entity
@Table(name = "IEX_Ticker")
@JsonIgnoreProperties(ignoreUnknown = true)
public class IEXTicker implements Serializable {


    private static final long serialVersionUID = 1L;

    public IEXTicker() {
        super();
    }

    @Id
    @Column(name = "symbol", length = 20)
    private String symbol;

    @Column(name = "name", length = 500)
    private String name;

    @Column(name = "date", length = 20)
    private String date;

    @Column(name = "isEnabled")
    private boolean isEnabled;

    @Column(name = "type", length = 20)
    private String type;

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }


    public boolean isEnabled() {
        return isEnabled;
    }

    public void setEnabled(boolean isEnabled) {
        this.isEnabled = isEnabled;
    }


    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String toString() {
        return "Symbol :" + symbol + " Name : " + name + " Date : " + date + " IsEnabled : 
        "+isEnabled+" Type:
        "+type;
    }

}

Error : 错误:

2017-10-31 20:32:17 ERROR stderr:71 - javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/html and type interface java.util.List  
2017-10-31 20:32:17 ERROR stderr:71 - javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type text/html and type interface java.util.List  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:42)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:75)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:52)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)  
2017-10-31 20:32:18 ERROR stderr:71 -   at  org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:225)  
2017-10-31 20:32:18 ERROR stderr:71 -   at com.swigel.iex.api.IEXTickerOperation.populateIEXTickerData1(IEXTickerOperation.java:127)  
2017-10-31 20:32:18 ERROR stderr:71 -   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
2017-10-31 20:32:18 ERROR stderr:71 -   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
2017-10-31 20:32:18 ERROR stderr:71 -   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
2017-10-31 20:32:18 ERROR stderr:71 -   at java.lang.reflect.Method.invoke(Unknown Source)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)  
2017-10-31 20:32:18 ERROR stderr:71 -   at  org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)  
2017-10-31 20:32:18 ERROR stderr:71 -   at  org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)  
2017-10-31 20:32:18 ERROR stderr:71 -   at  org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)  
2017-10-31 20:32:18 ERROR stderr:71 -   at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)

I had the same problem. 我有同样的问题。 It was caused by the server which did not, as expected, return a content-type: application/json, but it returned: 原因是服务器未按预期返回内容类型:application / json,但返回了:

content-type: text/html; charset=UTF-8

I see two options: 我看到两个选择:

1) contact the provider of the service and ask that application/json be returned 1)与服务提供商联系,并要求返回application / json

2) read the result of your request as a String and manually convert it to an object. 2)以字符串形式读取请求的结果,然后将其手动转换为对象。 Similar to this: 与此类似:

String jsonData = response.readEntity(String.class);
ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
JsonNode jsonNode= mapper.readValue(jsonData, com.fasterxml.jackson.databind.JsonNode.class);

Now, create a List from the jsonNode data... 现在,从jsonNode数据创建一个列表...

暂无
暂无

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

相关问题 org.jboss.resteasy.client.ClientResponseFailure:无法找到内容类型为文本/纯文本且类型为类java.lang.String的MessageBodyReader - org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/plain and type class java.lang.String 找不到内容类型为application / octet-stream的MessageBodyReader - Unable to find a MessageBodyReader of content-type application/octet-stream javax.ws.rs.ProcessingException:无法找到内容类型application / json的MessageBodyReader并输入类 - javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json and type class 找不到Java类java.util.List和Java类型java.util.List &lt;&gt;和MIME媒体类型text / html的消息正文阅读器 - A message body reader for Java class java.util.List, and Java type java.util.List<>, and MIME media type text/html was not found Jersey REST-Client WebTarget - 找不到内容类型的 MessageBodyReader - Jersey REST-Client WebTarget - Unable to find a MessageBodyReader of content-type 更改java.util.List的输出类型 - change type of the output of java.util.List 泛型类型java.util.List继承 - Generic type java.util.List inheritance 无法确定类型:java.util.List - Could not determine type for: java.util.List 获取 java.util.List 的泛型类型 - Get generic type of java.util.List RESTEASY003145:找不到内容类型 application/json 和类型类 org.keycloak.representations.AccessTokenResponse 的 MessageBodyReader - RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM