Hi,
I'm using a grizzly HTTP server to run a Jersey application where I try to
write to the NIOOutputStream.
I'm injecting org.glassfish.grizzly.http.server.Request and
org.glassfish.grizzly.http.server.Response instances into the Jersey
application resource like this:
@Path("test")
public class TestResource
{
@Inject
private Provider<org.glassfish.grizzly.http.server.Request>
requestProvider;
@Inject
private org.glassfish.grizzly.http.server.Response response;
@GET
@Produces("text/html")
public void test()
{
final NIOOutputStream out = response.getNIOOutputStream();
response.suspend();
out.notifyCanWrite(new WriteHandler()
{
long now = System.currentTimeMillis();
long waitTime = new Random().nextInt(500);
@Override
public void onWritePossible() throws Exception
{
if (now + waitTime < System.currentTimeMillis())
{
out.write(new String("done").getBytes());
response.resume();
}
else
{
out.notifyCanWrite(this);
}
}
}
}
}
When executing a request against /test I'm getting following exception from
grizzly framework:
*Dec 08, 2015 2:02:10 PM org.glassfish.grizzly.http.server.HttpHandler
doHandle*
*WARNING: GRIZZLY0200: Service exceptionjava.lang.IllegalStateException:
Internal org.glassfish.grizzly.http.server.Response has not been setat
org.glassfish.grizzly.http.server.Response.checkResponse(Response.java:1951)at
org.glassfish.grizzly.http.server.Response.setStatus(Response.java:1587)at
org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer$ResponseWriter.writeResponseStatusAndHeaders(GrizzlyHttpContainer.java:266)at
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:683)at
org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)at
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)at
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)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)*
*WARNING: GRIZZLY0013: Exception during FilterChain
executionjava.lang.NullPointerExceptionat
org.glassfish.grizzly.http.server.HttpServerFilter.afterService(HttpServerFilter.java:380)*
*at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:260)at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)*
I'm also getting following warning from jersey when starting the HTTP
server:
*WARNING: The following warnings have been detected: HINT: A HTTP GET
method, public void TestResource.test(), returns a void type. It can be
intentional and perfectly fine, but it is a little uncommon that GET method
returns always "204 No Content".*
The same code is working as expected when running in a
org.glassfish.grizzly.http.server.HttpHandler implementation.
public class TestHandler extends HttpHandler
{
@Override
public void service(Request request, Response response) throws
Exception
{
...
}
}
Is there anything I can do to get this working using a Jersey resource?
It seems to be related to
https://java.net/jira/browse/JERSEY-2462 but the
problem should be resolved.
I'm using jersey 2.22.1 (jersey-container-grizzly2-http) and grizzly 2.3.23.
Any help would be appreciated.
Thanks,
Soeren