I have a Factory<T>
that uses the InputStream
from ContainerRequestContext
to create T
. In my factory I mark and reset the InputStream
so that Jersey can then inject the body into the endpoint parameter. This works fine
problem: if I swap the ordering of these parameters (String body
first, then @Context T t
) it breaks. Jersey has closed the InputStream
before my Factory<T>
tries to read from the InputStream.
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
endpoint (works):
@POST
public Response getBodyDouble(@Context T t, String body) {}
ResourceConfig
endpoint (creating T fails):
@POST
public Response getBodyDouble(String body, @Context T t) {}
Stack trace:
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)
Is there a way to prevent Jersey from closing the InputStream when it injects the body? Or some way to re-open it? Thanks