DW + Metrics + Guice + AOP (phew!)

602 views
Skip to first unread message

James Harvey

unread,
Jul 23, 2014, 7:00:20 AM7/23/14
to dropwiz...@googlegroups.com
I'm trying to re-use the (frankly, awesome) Metrics @Timed annotations and apply them to non-resource methods. We're using Guice to bind an interceptor (I think we're using metrics-guice library) which adds the metrics to the registry. Happy days, works fine.

We want to be able to use the Guice injector to create the Resource class. There looks to be an issue, however, when trying to register a resource class with Jersey if it's been wrapped in a dynamic proxy by Guice. My assumption is the Guice (or just the JVM) strips off the method annotations, which means that Jersey doesn't recognise the @GET etc on the class.

Aside from excluding resource objects from being subject to the clutches of Guice's AOP module (using metrics-guice this isn't possible), does anyone have any suggestions or ideas?

James Harvey

unread,
Aug 7, 2014, 7:46:46 PM8/7/14
to dropwiz...@googlegroups.com
Bump...

Olivier Jacquemart

unread,
Aug 8, 2014, 3:26:31 AM8/8/14
to dropwiz...@googlegroups.com
You should take a look at https://github.com/HubSpot/dropwizard-guice

It will do what you want. There is a simple project and is compatible with dropwizard 0.6 and 0.7.

steve christensen

unread,
Aug 15, 2014, 6:57:45 PM8/15/14
to dropwiz...@googlegroups.com
I'm having what might be a similar issue. I've got a working Dropwizard application (0.7.1), and we use a slightly-tweaked dropwizard-guice.  

Like you, I wanted to use @Timed in non-resource methods, and when I add metrics-guice to the application I get an exception in a JUnit test that uses ResourceTestRule

java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ser.BeanPropertyWriter.isUnwrapping()Z
at com.fasterxml.jackson.module.afterburner.ser.SerializerModifier.findProperties(SerializerModifier.java:90)
at com.fasterxml.jackson.module.afterburner.ser.SerializerModifier.changeProperties(SerializerModifier.java:49)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:380)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:268)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:213)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:152)
at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:873)
at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:833)
at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:387)
at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:478)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:97)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:494)
at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:635)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.test.framework.impl.container.inmemory.TestResourceClientHandler.handle(TestResourceClientHandler.java:119)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:193)
at [mypackagepath].PreferencesResourceTest.testQuerySpecificPref(PreferencesResourceTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [other junit/intellij]

James Harvey

unread,
Aug 16, 2014, 2:02:03 AM8/16/14
to dropwiz...@googlegroups.com
We got it working eventually with guice-metrics.

The latest module codebase allows a matcher to be specified on creation; we simply exclude our resources from being AOP wrapped.

This seems like a known limitation in Guice more than anything lib specific. 

Sent from my iPhone
--
You received this message because you are subscribed to a topic in the Google Groups "dropwizard-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dropwizard-user/WvLXXVVc-qc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steve christensen

unread,
Sep 29, 2014, 4:54:24 PM9/29/14
to dropwiz...@googlegroups.com
Got back to this today. Turns out my issue wasn't with the AOP wrapping, but an issue w/ the versions of jackson-databind brought in by the dependency from metrics-guice -> metrics-servlets -> jackson-databind.

Adding the following exclusion corrected my earlier problems:


            <dependency>
                <groupId>com.palominolabs.metrics</groupId>
                <artifactId>metrics-guice</artifactId>
                <version>3.1.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
Reply all
Reply to author
Forward
0 new messages