MessageBodyProviderNotFoundException:我不知道检索数据是如何发送的

时间:2017-08-07 21:40:56

标签: java rest jersey

我解释我的问题。我发送一个来自我的班级用户的对象。我将它从我的网站发送到我的宁静服务。但是我试着拥有它,而且我在params中尝试的所有类型都不是valide或null:

发送课程:

   public String update() {
    try {
        if(mdpVerification.equals(utilisateur.getMotDePasse())){
        clientRest.setPath("user");
        clientRest.putEntity(SessionBeanEFPlanning.getAdministrateur().getLogin()
                , SessionBeanEFPlanning.getAdministrateur().getMotDePasse(), utilisateur, utilisateur.getId());
        SessionBeanEFPlanning.displayFacesMessage(FacesMessage.SEVERITY_INFO, "L'utilisateur a été modifié avec succès!");
        setUtilisateur(null);
        setUtilisateurs(null);
        super.getUtilisateurs();
        return "/utilisateurs/index?faces-redirect=true";
        }else{
        SessionBeanEFPlanning.displayFacesMessage(FacesMessage.SEVERITY_INFO, "Les mot de passes ne concordent pas !");    
        return "/utilisateur/edit?faces-redirect=true";
        }
    } catch (serverIllegalStateException exception) {
        String message = "";
        if (exception.getMessage().toLowerCase().contains("erreur : pseudo identique")) {
            message = "Ce pseudo est déjà attribué !";
        } else if (exception.getMessage().toLowerCase().contains("erreur : email identique")) {
            message = "Cet email est déjà attribué !";
        } else {
            message = exception.toString();
        }
        SessionBeanEFPlanning.displayFacesMessage(FacesMessage.SEVERITY_ERROR, message);
        return "/utilisateurs/edit?faces-redirect=true";
    }
}

我已经看到我的Object是否为null而它不是!我给你讲课如何发送信息:

public Object putEntity(String login, String password, Utilisateur JsonObject,  Long id) {
    WebTarget webTarget = client.target(URI_REST_SERVICE)
            .path(URI_PATH)
            .path(Long.toString(id))
            .queryParam("login", login)
            .queryParam("password", password);
    System.out.println(webTarget);
    return super.<Utilisateur>putEntity(webTarget, JsonObject, new GenericType<Utilisateur>() {
    });
}

及其界面:

protected <T> T putEntity(WebTarget webTarget, T entity, GenericType genericType) {
    Response response = put(webTarget, entity);
    checkStatus200(response);
    return (T) response.readEntity(genericType);
}

现在我给你接收课程:

@PUT
@Path("/{id : \\d+}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateUser(@QueryParam("login") String login,
        @QueryParam("password") String password,@PathParam("id") long id, JsonArray  utilisateur) {
    try {
        System.out.println(utilisateur);
        if (utilisateur != null) {
           // mapper.update(utilisateur);
            return Response.status(Response.Status.OK).entity(utilisateur).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).entity(
                    new MessageServiceErreur("Erreur utilisateur NULL")).build();
        }
    } catch (IllegalStateMessage exception) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
                new MessageServiceErreur(exception.toString())).build();
    } 

}

就像标题所说我的tomcat log ::

有这个错误
javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
    at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:87)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:121)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:402)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:349)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    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:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=interface javax.json.JsonArray, genericType=interface javax.json.JsonArray.
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:207)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:139)
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:72)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:139)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1109)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
    at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:262)
    at org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.provide(EntityParamValueFactoryProvider.java:96)
    at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81)
    ... 41 more

我的问题是:我如何才能正确收到信息?

新错误:

com.fasterxml.jackson.databind.JsonMappingException: Can not find a deserializer for non-concrete Map type [map type; class javax.json.JsonObject, [simple type, class java.lang.String] -> [simple type, class javax.json.JsonValue]]
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:268)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:243)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:144)
    at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:381)
    at com.fasterxml.jackson.databind.ObjectReader._findRootDeserializer(ObjectReader.java:1380)
    at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1228)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:677)
    at com.fasterxml.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:777)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:233)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:211)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:139)
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:72)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:139)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1109)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
    at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:262)
    at org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.provide(EntityParamValueFactoryProvider.java:96)
    at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:121)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:402)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:349)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    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:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

LOG JERSEY:

HTTP REQUEST : User: unknown - Path: /user - Header: {accept=[application/json], user-agent=[Jersey/2.10.4 (HttpUrlConnection 1.8.0_77)], host=[localhost:8082], connection=[keep-alive]} - Entity: 

HTTP RESPONSE : Header: {Content-Type=[application/json]} - Entity: [EJPlanning.Models.Utilisateur@6a277cb, EJPlanning.Models.Utilisateur@1fe07c0b]
HTTP REQUEST : User: unknown - Path: /user - Header: {accept=[application/json], user-agent=[Jersey/2.10.4 (HttpUrlConnection 1.8.0_77)], host=[localhost:8082], connection=[keep-alive]} - Entity: 

HTTP RESPONSE : Header: {Content-Type=[application/json]} - Entity: [EJPlanning.Models.Utilisateur@73fd68e9, EJPlanning.Models.Utilisateur@4d012aaf]
HTTP REQUEST : User: unknown - Path: /user/4601 - Header: {accept=[application/json], content-type=[application/json], user-agent=[Jersey/2.10.4 (HttpUrlConnection 1.8.0_77)], host=[localhost:8082], connection=[keep-alive], content-length=[109]} - Entity: {"id":4601,"login":"Scadra","motDePasse":"","nom":"Colart","prenom":"Pierre","typeUtilisateur":"RESPONSABLE"}

HTTP RESPONSE : Header: {Content-Type=[application/json]} - Entity: EJPlanning.Models.Utilisateur@1ac66ff1
HTTP REQUEST : User: unknown - Path: /user - Header: {accept=[application/json], user-agent=[Jersey/2.10.4 (HttpUrlConnection 1.8.0_77)], host=[localhost:8082], connection=[keep-alive]} - Entity: 

HTTP RESPONSE : Header: {Content-Type=[application/json]} - Entity: [EJPlanning.Models.Utilisateur@617845f2, EJPlanning.Models.Utilisateur@70eb5f1a]

1 个答案:

答案 0 :(得分:1)

错误消息告诉您它无法将收入JSON反序列化为JsonArray

  

&#34;我如何正确收到信息?&#34;

  1. 使用POJO代替JsonArray作为方法参数。
  2. 确保您拥有Json Provider
  3. 注意:上一个链接适用于JSON / POJO支持。如果你想坚持使用Javax.json类(即JsonArray),你也可以只包括以下依赖项(它支持JSON-P)

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-processing</artifactId>
        <version>${jersey2.version}</version>
    </dependency>
    

    Jersey docs: Support for Common Media Type Representations

    中对此进行了解释