我有一个Factory<T>
,它使用InputStream
中的ContainerRequestContext
来创建T
。在我的工厂中,我标记并重置InputStream
,以便Jersey可以将主体注入到端点参数中。效果很好
问题:如果我交换这些参数的顺序(先交换String body
,然后交换@Context T t
),它将中断。在我的InputStream
尝试从InputStream读取之前,Jersey已关闭Factory<T>
。
Factory<T>
:
@Override
public T provide() {
InputStream inputStream = containerRequestContext.getEntityStream();
inputStream.mark(Integer.MAX_VALUE);
T t = new T(inputStream);
inputStream.reset();
return t;
}
ResourceConfig
端点(有效):
@POST
public Response getBodyDouble(@Context T t, String body) {}
ResourceConfig
端点(创建T失败):
@POST
public Response getBodyDouble(String body, @Context T t) {}
堆栈跟踪:
java.lang.IllegalStateException: Entity input stream has already been closed.
at org.glassfish.jersey.message.internal.EntityInputStream.ensureNotClosed(EntityInputStream.java:225)
at org.glassfish.jersey.message.internal.InboundMessageContext.getEntityStream(InboundMessageContext.java:762)
at com.-.TFactory.provide(TFactory.java:xx)
有没有一种方法可以防止Jersey在注入主体时关闭InputStream?或者以某种方式重新打开它?谢谢