因此,我們正在開發一個Android應用程序。在我們的Gradle進口中有以下幾種:「MessageBodyReader not found」工作正常後
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
我強烈懷疑,這僅僅是一個更深層次問題的表現 - 正如我說,其他一些電話只是失敗了。有人知道爲什麼會發生這種情況,以及如何解決這個問題?
您在服務器上發生錯誤,這就是爲什麼您要返回HTML MessageRodyReader not found for media type = text/html'。檢查服務器日誌,檢查請求的正文。在試圖在客戶端反序列化之前,檢查狀態碼總是一個好主意,這樣你可以正確處理錯誤情況,而不僅僅是失敗並且獲得當前正在獲取的異常 –
@peeskillet好吧,對於一分鐘我以爲你瘋了,但事實證明你是對的。這顯然足以讓我們的服務器將您註銷,並且自動登錄過程無法正常工作。 (我們還必須更改重定向的狀態碼....)謝謝! ...接受答案我該怎麼辦?你想把你的評論變成答案嗎? – Erhannis