igniterealtime/REST-API-Client

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException

Closed this issue · 16 comments

My java code:
`
AuthenticationToken authenticationToken = new AuthenticationToken("FQaCIpmRNBq4CfF8");
RestApiClient restApiClient = new RestApiClient("http://gaoxu", 9090,authenticationToken);

      restApiClient.getUsers();`

pom.xml:<dependency> <groupId>org.igniterealtime</groupId> <artifactId>rest-api-client</artifactId> <version>1.1.3</version> </dependency>

## When I perform an example to request all available users,Code as above, had an exception as :
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class org.igniterealtime.restclient.entity.UserEntities, genericType=class org.igniterealtime.restclient.entity.UserEntities.
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:232)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:785)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:115)
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:419)
at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:267)
at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:112)
at org.igniterealtime.restclient.RestClient.call(RestClient.java:155)
at org.igniterealtime.restclient.RestClient.get(RestClient.java:75)
at org.igniterealtime.restclient.RestApiClient.getUsers(RestApiClient.java:56)
at openfireTest.Test.main(Test.java:16)

Redor commented

The URL does not pointing to the REST API. (I guess http://gaoxu is just wrong)

The URL is correct , Has returned status 200.
The complete log is as follows:

`May 18, 2016 8:42:35 上午 org.glassfish.jersey.filter.LoggingFilter log
Info: 1 * Sending client request on thread main
1 > GET http://gaoxu:9090/plugins/restapi/v1/users
1 > Authorization: FQaCIpmRNBq4CfF8
1 > Content-Type: application/xml

May 18, 2016 8:42:35 上午 org.glassfish.jersey.filter.LoggingFilter log
info : 2 * Client response received on thread main
2 < 200
2 < Content-Language: zh-CN
2 < Content-Length: 4043
2 < Content-Type: text/html; charset=UTF-8
2 < Date: Wed, 18 May 2016 00:42:35 GMT
2 < Expires: Thu, 01 Jan 1970 00:00:00 GMT
2 < Set-Cookie: JSESSIONID=1c4j934unt7mi1m95dgc7b0jd9;Path=/;HttpOnly

Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class org.igniterealtime.restclient.entity.UserEntities, genericType=class org.igniterealtime.restclient.entity.UserEntities.
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:232)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:785)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:115)
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:419)
at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:267)
at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:112)
at org.igniterealtime.restclient.RestClient.call(RestClient.java:155)
at org.igniterealtime.restclient.RestClient.get(RestClient.java:75)
at org.igniterealtime.restclient.RestApiClient.getUsers(RestApiClient.java:56)
at openfireTest.Test.main(Test.java:16)`

I found someone else with a similar exception:
MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/json.
but my exception:
MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html.

His solution is to join the jackson package as a reader .But i don't know which package as reader for html.

Redor commented

The REST API never response with text/html. It response only with XML or JSON. I guess the call forward you to an HTML website and not to User Entities

why forward to an HTML website? Code total 3 lines.port is wrong.The port not point to console port?

Redor commented

What happens if you call http://gaoxu:9090/plugins/restapi/v1/users from your browser?

it's forward to openfire console log on page.
and browser url change to "http://gaoxu:9090/login.jsp?url=%2Fplugins%2Frestapi%2Fv1%2Fusers"

Redor commented

Try to restart the server and try again

I restart,the results the same

Redor commented

It seems to be not REST API Client specific, that's why I close this issue

Ucoon commented

I have the same problem, how to solve it?

ctp27 commented

Did you find a solution to this problem? I am getting the same error

If has same issue, you can try to this:
Step 1: Install Rest-api Plugin.
Step 2: Restart openfire.
Step 3: Enable rest-api.(Server setting -> REST API -> Enable it.)

I solved this issue by add below dependences to your project
我通过添加下面的依赖到项目中解决了这个问题:

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.24.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>2.24.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-jaxb</artifactId>
            <version>2.24.1</version>
        </dependency>

reference:
参考stackoverflow回答:
Jersey version issue: MessageBodyReader not found for media type=application/xml

I think the client API should be built using the Jersey 2 client API. For example:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.39</version>
</dependency>