problem using Grizzly as the test container

542 views
Skip to first unread message

Shengjie Min

unread,
Mar 14, 2013, 3:20:06 PM3/14/13
to dropwiz...@googlegroups.com
Hi guys,

I am trying to get this https://gist.github.com/igstan/3016987 working with dropwizard v0.6.1. The reason I want to use grizzly as the test container is because InMemoryTestContainer does not support Resource with injectable constructor, see this issue in details: http://java.net/jira/browse/JERSEY-623?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel.

GrizzlyResourceTest.java looks like:  https://gist.github.com/igstan/3016987 . Since com.yammer.dropwizard.json.Json and com.yammer.dropwizard.bundles.JavaBundle are not in v0.6.1 anymore, I simply just comment out the lines related to these class.

  @Before
  public void setUpJersey() throws Exception {
    setUpResources();
    this.test = new JerseyTest(new GrizzlyWebTestContainerFactory()) {
      @Override
      protected AppDescriptor configure() {
        ClientConfig config = new DefaultClientConfig();

        // taken from DropwizardResourceConfig
        config.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
        config.getSingletons().add(new LoggingExceptionMapper<Throwable>() { }); // create a subclass to pin it to Throwable
        config.getClasses().add(InstrumentedResourceMethodDispatchAdapter.class);
        config.getClasses().add(CacheControlledResourceMethodDispatchAdapter.class);

        for (Class<?> provider : providers) {
          config.getClasses().add(provider);
        }

        config.getSingletons().addAll(singletons);

        return new WebAppDescriptor.Builder("com.example.helloworld.resources").clientConfig(config).build();
      }
    };
    test.setUp();
  }

My case is more complex since I have HttpServletRequest injected to my resource class like myMethod(@Context HttpServletRequest request). So here I just use PersonResource under  dropwizard-example.


QuickTest.java looks like:
public class QuickTest extends GrizzlyResourceTest{
    @Test
    public void testGrizzly() throws Exception {
        ClientResponse rsp = client()
            .resource("http://localhost:9998/people").get(ClientResponse.class);
        Assert.assertEquals(200, rsp.getStatus());
    }
    @Override
    protected void setUpResources() throws Exception {
    }
}

When I run QuickTest, The error I am getting from Console is this:

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Mar 14, 2013 7:14:11 PM com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer <init>
INFO: Creating Grizzly2 Web Container configured at the base URI http://localhost:9998/
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Starting application [TestContext] ...
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext initServlets
INFO: [TestContext] Servlet [com.sun.jersey.spi.container.servlet.ServletContainer] registered for url pattern(s) [[/*]].
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Application [TestContext] is ready to service requests.  Root: [].
Mar 14, 2013 7:14:11 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for field: private javax.servlet.http.HttpServletRequest com.yammer.dropwizard.jersey.LoggingExceptionMapper.request

Any ideas?
--
All the best,
Shengjie Min

Chris Micali

unread,
Sep 14, 2013, 2:34:05 PM9/14/13
to dropwiz...@googlegroups.com
I'm seeing the same issue - 

ERROR [2013-09-14 14:27:39,186] com.sun.jersey.spi.inject.Errors: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for field: protected javax.ws.rs.core.UriInfo com.sagedevices.platform.jersey.core.ResourceBase.uriInfo
  SEVERE: Missing dependency for field: protected com.sun.jersey.api.core.HttpContext com.sagedevices.platform.jersey.core.ResourceBase.context


Has anyone successfully gotten grizzly to work with dropwizard?  Is it a Jersey 1.x problem?
Reply all
Reply to author
Forward
0 new messages