无法找到内容类型text / html的MessageBodyReader并键入interface java.util.List

时间:2017-10-31 16:51:42

标签: java jboss jax-rs wildfly-10 javax

请不要将其视为重复请求,因为我已经完成了所有操作    在stackoverflow中发帖,没有人回答。我发现没有回应。

问题是:

我面临一个非常奇怪的问题,即使用相同的代码发出GET请求    通过独立应用程序(在main()内)。它的工作原理就像是一样    代码放在Java EE应用程序中并部署在wildfly 10服务器上,    它给出了错误

“无法找到内容类型text / html的MessageBodyReader并输入    接口java.util.List“

代码:

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());

必需的jar(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>

模型类: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;
    }

}

错误:

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)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。它是由服务器引起的,它没有按预期返回内容类型:application / json,但它返回了:

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

我看到两个选项:

1)联系服务提供商并要求返回application / json

2)以String形式读取请求的结果并手动将其转换为对象。与此类似:

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);

现在,从jsonNode数据创建一个List ...