users@jersey.java.net

Re: [Jersey] Jersey Test Framework init failures

From: Charley Robinson <c_at_wobbals.com>
Date: Mon, 2 Aug 2010 14:41:07 -0700

Those logging filters are useful for inspecting transactions *per request*,
however my troubles are rooted in the failure to start the (supposedly)
initialized the container, not issue requests to it.

Given:
1) An example web resource:
@Path("/cidrblock")
public class CidrblockResource {
    @Context UriInfo uriInfo;
    @GET
    @Produces("text/plain")
    public Response getCidrblocks() {
        Response.ResponseBuilder response = Response.status(200);
        response.entity("HAI");
        return response.build();
    }
}

2) A simple test:
@Test
public void testTopLevelGet() {
        System.out.println("HIDEO");
        ClientResponse response =
resource().path("cidrblock").get(ClientResponse.class);
        logger.debug(response.toString());
        logger.debug(response.getEntity(String.class));
}

Running mvn test shows Grizzly silently failing to init/start, so the Client
GET request gets made to a port where nothing is listening:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running IpAddressJpaTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.039 sec
Running CidrblockResourceTest
Aug 2, 2010 1:06:20 PM
com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer
<init>
INFO: Creating Grizzly Web Container configured at the base URI
http://localhost:9998/
HIDEO
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.935 sec
<<< FAILURE!
Running CidrblockJpaTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec
Running NetblockJpaTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.012 sec

Results :

Tests in error:
  testTopLevelGet(CidrblockResourceTest)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0


...Compare this to the info logs of the container when running, say,
HelloWorld 1.3:

Running com.sun.jersey.samples.helloworld.MainTest
Aug 2, 2010 1:11:26 PM
com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer
<init>
INFO: Creating Grizzly Web Container configured at the base URI
http://localhost:9998/
Aug 2, 2010 1:11:27 PM
com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer
start
INFO: Starting the Grizzly Web Container...
Aug 2, 2010 1:11:27 PM com.sun.grizzly.Controller logVersion
INFO: Starting Grizzly Framework 1.9.18-i - Mon Aug 02 13:11:27 PDT 2010
Aug 2, 2010 1:11:27 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  com.sun.jersey.samples.helloworld.resources
Aug 2, 2010 1:11:27 PM com.sun.jersey.api.core.ScanningResourceConfig
logClasses
INFO: Root resource classes found:
  class com.sun.jersey.samples.helloworld.resources.HelloWorldResource

...and so forth.

--Charley

Pavel Bucek wrote:

> Hello,
>
> you can user client and server logging filter ([1] and [2]), and set jdk
> logging to display info messages of
> "com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainer"
> logger (but there are only simple messages which state starting/stopping
> container).
>
> Additionally, you may want to check that port localhost:9998 is not used
> (netstat -aln or similar command for your OS).
>
> Or if you can share your code, I can help you with debugging.
>
> Regards,
>
> Pavel
>
> [1]
> https://jersey.dev.java.net/nonav/apidocs/1.3/jersey/com/sun/jersey/api/client/filter/LoggingFilter.html
> [2]
> https://jersey.dev.java.net/nonav/apidocs/1.3/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html
>
>
>