在 APIHealthCheck 上获取 Dropwizard 客户端和 Jersey/HTTP I/O 错误

Getting Dropwizard Client And Jersey/HTTP I/O Error on APIHealthCheck

我目前正在做一项 class 的作业,该作业要求我在 eclipse 上开发一个使用 Dropwizard 身份验证和 Jersey HTTP 的 Maven 项目。我在互联网上到处寻找解决方案,包括 Whosebug。当我 运行 本地计算机上的服务器时,它似乎 运行 正常。但是当我在 http://localhost:8080/status 上做简单的健康检查时,它给了我这个错误信息。

127.0.0.1 - - [04/Jun/2021:21:25:52 +0000] "GET /gameusers HTTP/1.1" 404 43 "-" "GameAuthApplication (GameUserRESTClient)" 17
[0:0:0:0:0:0:0:1] - - [04/Jun/2021:21:25:52 +0000] "GET /status HTTP/1.1" 200 21845 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36" 143
ERROR [2021-06-04 21:25:52,503] org.glassfish.jersey.server.ServerRuntime$Responder: An I/O error has occurred while writing a response message entity to the container output stream.
! com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet[0]->java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry["APIHealthCheck"]->com.codahale.metrics.health.HealthCheck$Result["error"]->javax.ws.rs.ProcessingException["cause"]->com.fasterxml.jackson.databind.exc.MismatchedInputException["location"]->com.fasterxml.jackson.core.JsonLocation["sourceRef"])
! at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
! at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1276)
! at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400)
! at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71)
! at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33)
! at com.fasterxml.jackson.module.blackbird.ser.ObjectPropertyWriter.serializeAsField(ObjectPropertyWriter.java:95)
! at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
! at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
! at com.fasterxml.jackson.module.blackbird.ser.ObjectPropertyWriter.serializeAsField(ObjectPropertyWriter.java:95)
! at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
! at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
! at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728)
! at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
! at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
! at com.fasterxml.jackson.module.blackbird.ser.ObjectPropertyWriter.serializeAsField(ObjectPropertyWriter.java:95)
! at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
! at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
! at com.fasterxml.jackson.databind.ser.impl.MapEntrySerializer.serializeDynamic(MapEntrySerializer.java:407)
! at com.fasterxml.jackson.databind.ser.impl.MapEntrySerializer.serialize(MapEntrySerializer.java:341)
! at com.fasterxml.jackson.databind.ser.impl.MapEntrySerializer.serialize(MapEntrySerializer.java:24)
! at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145)
! at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107)
! at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)
! at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
! at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400)
! at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1510)
! at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1006)
! at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:626)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:242)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:227)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
! at io.dropwizard.jersey.errors.EofExceptionWriterInterceptor.aroundWriteTo(EofExceptionWriterInterceptor.java:39)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
! at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:85)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
! at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:61)
! ... 54 common frames omitted
! Causing: org.glassfish.jersey.server.internal.process.MappableException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet[0]->java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry["APIHealthCheck"]->com.codahale.metrics.health.HealthCheck$Result["error"]->javax.ws.rs.ProcessingException["cause"]->com.fasterxml.jackson.databind.exc.MismatchedInputException["location"]->com.fasterxml.jackson.core.JsonLocation["sourceRef"])
! at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:67)
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:139)
! at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1116)
! at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:635)
! at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:373)
! at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:363)
! at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:258)
! at org.glassfish.jersey.internal.Errors.call(Errors.java:248)
! at org.glassfish.jersey.internal.Errors.call(Errors.java:244)
! at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
! at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
! at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
! at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
! at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
! at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
! at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
! at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
! at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:791)
! at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1626)
! at io.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:35)
! at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
! at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.handle(AllowedMethodsFilter.java:47)
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.doFilter(AllowedMethodsFilter.java:41)
! at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
! at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601)
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1435)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
! at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1350)
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
! at com.codahale.metrics.jetty9.InstrumentedHandler.handle(InstrumentedHandler.java:313)
! at io.dropwizard.jetty.RoutingHandler.handle(RoutingHandler.java:52)
! at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:763)
! at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:54)
! at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:179)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
! at org.eclipse.jetty.server.Server.handle(Server.java:516)
! at org.eclipse.jetty.server.HttpChannel.lambda$handle(HttpChannel.java:388)
! at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633)
! at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)
! at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
! at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
! at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
! at org.eclipse.jetty.io.ChannelEndPoint.run(ChannelEndPoint.java:104)
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:882)
! at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1036)
! at java.base/java.lang.Thread.run(Thread.java:832)

我尝试逐字按照 https://howtodoinjava.com/dropwizard/dropwizard-basic-auth-security-example/

上的教程进行操作

代码在 git 仓库中... https://github.com/RedJaVa68/GameAuth.git

这是一个序列化问题。根据您共享的 github 存储库,似乎没有与 /gameusers 路径关联的端点。但是它在健康检查回调中被调用。因此调用失败并且无法将错误响应反序列化为 ArrayList。在GameUserRESTController.java中需要添加如下路径:

@Produces({"application/json"})
@Path("/gameusers") // this might be missing
public class GameUserRESTController {