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分钟没有进行web客户端调用后,下一个要进行的调用失败。在第一个示例中,它无声地失败,不引发异常,但在第三个示例中,它引发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
我强烈怀疑这只是一个更深层次问题的表现——正如我所说,其他一些调用只是默默地失败了。有人知道为什么会发生这种情况,以及如何修复它吗?