I run the following simple example for a Jersey application on a Grizzly server:
@Path("example")
public class example {
@POST
public Response someMethod(@Context Request r) {
System.out.println("Received request at : " + LocalDateTime.now());
Response response = Response.ok().build();
return response;
}
}
public class GrizzlyServerMain {
public static HttpServer startServer(String BASE_URI) throws IOException {
// Scans for JAX-RS resources and providers in the specified code-package
final ResourceConfig resourceConfig = new PackagesResourceConfig("Application");
// create and start a new instance of grizzly http server exposing the Jersey application at BASE_URI
return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
}
public static void main(String[] args) throws IOException {
String BASE_URI = "http://0.0.0.0:8000";
// Base URI the Grizzly HTTP server will listen on
startServer(BASE_URI);
//noinspection ResultOfMethodCallIgnored
System.in.read();
}
}
When I run it from IntelliJ, everything works as expected.
Connected to the target VM, address: '127.0.0.1:61163', transport: 'socket' Dec 30, 2016 4:00:07 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for root resource and provider classes in the packages: Application Dec 30, 2016 4:00:08 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class Application.Greetings class Application.example Dec 30, 2016 4:00:08 PM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found. Dec 30, 2016 4:00:08 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate INFO: Initiating Jersey application, version 'Jersey: 1.19.3 10/24/2016 03:43 PM' Dec 30, 2016 4:00:08 PM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [0.0.0.0:8000] Dec 30, 2016 4:00:08 PM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started Received request at : 2016-12-30T16:00:13.097 Received request at : 2016-12-30T16:00:14.319 Received request at : 2016-12-30T16:00:15.583 Disconnected from the target VM, address: '127.0.0.1:61163', transport: 'socket'
But when I create a JAR with all the dependencies, and as soon as I send the request from the client, I get:
WARNING: Exception during FilterChain execution java.lang.IllegalStateException at org.glassfish.grizzly.http.server.io.OutputBuffer.reset(OutputBuffer.java:217) at org.glassfish.grizzly.http.server.Response.reset(Response.java:732) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:168) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:815) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:567) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:547) at java.lang.Thread.run(Unknown Source)
Can you please tell me what could I be doing wrong?
java.lang.IllegalStateException at org.glassfish.grizzly
. You said you're trying to create a stand-alone jar, and I saw calls to Glassfish, a server. – Christopher Schneider