io.dropwizard.jersey.errors.LoggingExceptionMapper:处理请求时出错:5a81495aefe8fa44! java.lang.NullPointerException:null

时间:2017-07-12 16:48:10

标签: jersey dropwizard

我正在尝试在dropwizard中创建一个休息Api,它将消耗MULTIPART FORM_DATA并将对其执行某些操作返回响应但是如果用户不传递多部分文件而不是系统返回响应

{
"code": 500,
"message": "There was an error processing your request. It has been logged (ID dd0ffe2edbe69923)."`}`

除此之外,我想在那里做自己的回应。这是客户得到的回应

@POST

@Path("/upload")
@CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.DAYS)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({"application/json", "application/xml", 
            "application/OCTET_STREAM", "application/x-protobuf", 
            "application/PLAIN.TEXT"})
public Response start(@FormDataParam("file") InputStream inputStream,
                      @FormDataParam("file") FormDataContentDisposition fileDetail
                      )throws NullPointerException,Exception{




    return Response.ok("anything").build( );

}

并且请求

    curl -X POST \
  http://localhost:3013/not \
  -H 'cache-control: no-cache' \
  -H 'postman-token: 8214d505-55a4-c13d-80df-896582a6cff0'

这是服务器上显示的错误

ERROR [2017-07-12 16:38:02,543] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: dd0ffe2edbe69923
! java.lang.NullPointerException: null
! at org.glassfish.jersey.media.multipart.internal.FormDataParamValueFactoryProvider$FormDataParamValueFactory.provide(FormDataParamValueFactoryProvider.java:282)
! at org.glassfish.jersey.server.spi.internal.ParamValueFactoryWithSource.provide(ParamValueFactoryWithSource.java:71)
! at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:90)
! at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:127)
! at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
! at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
! 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:317)
! at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
! at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
! at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
! at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
! at io.dropwizard.jetty.NonblockingServletHolder.handle(NonblockingServletHolder.java:49)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
! at io.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:34)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.handle(AllowedMethodsFilter.java:50)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.doFilter(AllowedMethodsFilter.java:44)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:541)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1239)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1141)
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
! at com.codahale.metrics.jetty9.InstrumentedHandler.handle(InstrumentedHandler.java:241)
! at io.dropwizard.jetty.RoutingHandler.handle(RoutingHandler.java:51)
! at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:494)
! at io.dropwizard.jetty.BiDiGzipHandler.handle(BiDiGzipHandler.java:68)
! at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:56)
! at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:169)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
! at org.eclipse.jetty.server.Server.handle(Server.java:564)
! at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
! at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
! at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
! at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
! at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
! at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
! at java.lang.Thread.run(Thread.java:745)

和依赖关系是

  <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
     <version>2.17</version>
    <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
</dependency>

2 个答案:

答案 0 :(得分:0)

实际问题是org.glassfish.jersey.media版本将其更改为2.23,现在工作正常

答案 1 :(得分:0)

在我的Dropwizard-Swagger集成项目中,我遇到以下问题:

> ERROR ... io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: ****** !
> freemarker.template.TemplateNotFoundException: Template not found for name "/com/......./swagger/index.ftl".

按照https://github.com/smoketurner/dropwizard-swagger上的有效dropwizard-swagger示例,将index.ftl文件放在资源或招摇包中可以解决该问题。