因此,我们正在开发Android应用程序。我们的gradle进口包括以下内容:
compile 'org.glassfish.jersey.core:jersey-client:2.25'
compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.3'
我们使用它们在我们的一台服务器上调用REST端点。例如:
enterSpaceTarget.path(Long.toString(skId)).request(MediaType.APPLICATION_JSON).get();
或
Form form = new Form();
form = form.param("username", username);
form = form.param("password", password);
form = form.param("rememberMe", Boolean.toString(true));
loginWebTarget.request().post(Entity.form(form), String.class);
或
long before = System.currentTimeMillis();
Long server = pingTarget.request(MediaType.APPLICATION_JSON).get(Long.class);
long after = System.currentTimeMillis();
我将继续使用最后一个作为示例。看,它效果很好......大约45分钟。在这个时间尺度上运行很多测试很困难,但是当你第一次启动应用程序时一切正常,如果你继续按下按钮几个小时,但是在没有网络客户端调用大约45分钟之后,下次通话失败。在第一个示例中,它以静默方式失败,不会抛出任何异常,但在第三个示例中,它会抛出MessageBodyProviderNotFoundException,如下所示:
javax.ws.rs.client.ResponseProcessingException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html, type=class java.lang.Long, genericType=class java.lang.Long.
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:811)
at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
at com.....RestClient.ping(RestClient.java:126)
at com.....VPBCommunicator.lambda$new$3$VPBCommunicator(VPBCommunicator.java:196)
at com.....VPBCommunicator$$Lambda$5.run(Unknown Source)
at java.lang.Thread.run(Thread.java:762)
Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html, type=class java.lang.Long, genericType=class java.lang.Long.
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:231)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:806)
... 13 common frames omitted
我强烈怀疑这只是一个更深层次问题的表现 - 正如我所说,其他一些电话只是默默地失败了。有谁知道为什么会这样,以及如何解决它?
答案 0 :(得分:0)
找不到媒体类型= text / html
的MessageBodyReader
除非text / html是您请求的类型,否则几乎所有时间都意味着服务器端出现错误,以及您获取服务器错误页面的内容。您应该检查服务器日志以查看问题所在。
顺便说一下,首先检查响应的状态总是一个好主意,你可以正确处理错误,而不是自动尝试反序列化错误响应并最终得到你当前获得的异常< / p>
Response response = target().request().get();
if (isError(response)) {
handleError(response);
} else {
Long result = response.readEntity(Long.class);
}