0

I am trying to write a pointcut to have an around advice around: com.fasterxml.jackson.databind.DeserializationContext.reportMappingException() method.

This is what I have so far and it's not working i.e. maven complains:

[WARNING] advice defined in com.charter.aesd.videocatalog.client.interceptor.ContactManagerLogger has not been applied [Xlint:adviceDidNotMatch]
    /Users/rhasija/dev/projects/video/videocatalog-middle/client/src/main/java/com/charter/aesd/videocatalog/client/interceptor/ContactManagerLogger.java:36

Trial 1:

@Pointcut("execution(* com.fasterxml.jackson.databind.DeserializationContext+.*(..))")
public void servicePointcut() {}

Trial 2:

@Pointcut("execution( * com.fasterxml.jackson.databind.*.*(..) )")
public void servicePointcut() {}

Below is my pom.xml. Is it not possible to have a pointcut to an external library via AspectJ?

<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
    </dependency>
    ....
</dependencies>

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.10</version>
    <configuration>
        <complianceLevel>1.8</complianceLevel>
        <source>1.8</source>
        <target>1.8</target>
        <includes>
            <include>**/*.java</include>
            <include>**/*.groovy</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <!--suppress MavenModelInspection -->
                <goal>compile</goal>
                <!--suppress MavenModelInspection -->
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>info.ponge.julien.hacks.guiceaspectj.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <!--suppress MavenModelInspection -->
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
kriegaex
  • 63,017
  • 15
  • 111
  • 202
user770119
  • 422
  • 1
  • 5
  • 11
  • How about a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)? For instance, I do not see your `ContactManagerLogger` and also not the code calling Jackson. The POM is also incomplete. Do you use the right Jackson version? The method you want to intercept is only available since 2.8. so many variables, I do not like to speculate wildly. – kriegaex Mar 15 '17 at 14:51

1 Answers1

0

Have you tried configuring the maven plugin? Add:

<configuration>

  ....

  <weaveDependencies>
    <weaveDependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </weaveDependency>
  <weaveDependencies>
<configuration>

Weaving already compiled JAR artifacts

The weaveDependencies corresponds to ajc -inpath and bear in mind that what it does is take the classes in the jar file, wave them, and include them in the output target/classes.

The AspectJ compiler/weaver

Maven aspectj:compile

You could use load-time weaving as well, injecting aspect instructions to the byte code during class loading.

alfcope
  • 2,327
  • 2
  • 13
  • 21