gpt4 book ai didi

java - MessageBodyProviderNotFoundException : MessageBodyReader not found for media type=text/html;charset=UTF-8

转载 作者:搜寻专家 更新时间:2023-10-31 20:32:17 25 4
gpt4 key购买 nike

我正在尝试使用 openfire REST-API-Client。我正在调用使用以下代码将用户添加到 openfire 的方法。

AuthenticationToken authenticationToken = new AuthenticationToken("username","password");

RestApiClient restApiClient = new RestApiClient("url",port, authenticationToken);

UserEntity openFireUser = restApiClient.getUser(user.getUsername());

当我调用 api 时,出现以下异常。

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class org.igniterealtime.restclient.entity.UserEntity, genericType=class org.igniterealtime.restclient.entity.UserEntity.
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.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:115)

我用谷歌搜索了一下,看起来依赖关系有问题。但没有任何效果。

下面是我的build.gradle

compile(group: 'org.igniterealtime', name :'rest-api-client', version: igniterealtime_rest_api_version){
exclude group: 'org.slf4j', module: 'slf4j-simple'
exclude group: 'org.slf4j', module: 'slf4j-api'
}

我也尝试过将以下依赖项添加到我的 build.gradle 中,但没有成功。

compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.23'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.2'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.24'
compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: '2.4.1'

最佳答案

出现问题是因为 media type text/htmlentity 不匹配。您可以使用 media type text/html 媒体类型的 restful 服务,但您需要使用 media type Application/json。并检查请求的 url 和请求和响应的媒体类型。

也用

@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)

并使用正确的状态码和Mediatype

做出响应

关于java - MessageBodyProviderNotFoundException : MessageBodyReader not found for media type=text/html;charset=UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45498887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com