aspectj

Implementing a wormhole pattern using AspectJ

空扰寡人 提交于 2019-11-28 12:32:30
I'm looking for an example to a wormhole pattern implementation using AspectJ (would be interested if Guice AOP has the power to implement this). A worm hole essentially allows you to pass additional parameters along the call flow for example: // say we have class foo { public int m0 int a, int b) { return m1(a,b); } public int m1 int a, int b) { return m2(a,b); } public int m2 int a, int b) { return a+b; } } // and I wanted in a non-invasive manner to pass a third parameter of type class context { String userName; long timeCalled; String path; } // I could use an advise to say print the

aspectj-maven-plugin, declare soft how to compile

耗尽温柔 提交于 2019-11-28 10:52:51
问题 Is it possible to compile project with softened Exceptions (e.g.: declare soft: Exception : execution(* *.*()); ) aspects in it using only aspectj-maven-plugin ? I can't handle it... I am still getting compilation error unreported exception Exception; must be caught or declared to be thrown So it is compiled without taking aspects in account. I am using this command to compile: mvn clean aspectj:compile and my pom.xml is: <project> <modelVersion>4.0.0</modelVersion> <groupId>pl.group.id<

Get value of a parameter of an annotation in Java

大兔子大兔子 提交于 2019-11-28 10:42:14
So I've got a code: @Path("/foo") public class Hello { @GET @Produces("text/html") public String getHtml(@Context Request request, @Context HttpServletRequest requestss){ ... } I am using AspectJ to catch all calls to getHtml method. I would like to get parameters passed to @Produces and to @Path in my advice, i.e. "/foo" and "text/html" in this case. How can I do it using reflection ? harsh To get value of the @Path parameter: String path = Hello.class.getAnnotation(Path.class).value(); Similarly, Once you have hold of Method getHtml Method m = Hello.class.getMethod("getHtml", ..); String

Adding AspectJ to pom.xml changed Java version with Maven, why?

寵の児 提交于 2019-11-28 09:48:22
UPDATE: here is my maven-compiler-plugin configuration: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> I work on a multi-project application that I build with Maven. We decided to add AspectJ so I added the following code to pom.xml in the top level project: (from the official documentation) <project> ... <dependencies> ... <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.3</version> </dependency> ...

AspectJ pointcut on constructor object

偶尔善良 提交于 2019-11-28 08:49:33
I need to inject few methods to every initialized object using AspectJ. I thought using this : pointcut vistaInjection(Object o) : initialization(java.lang.Object.new() ) && target(o) && !within(objectAspect); before(Object o): methodInjection(o){System.err.println("INIT");} to pointcut initialization of object, so I can inject these methods directly into the object that is part of every other object. However, it does't work. Do you have any idea why? Or what may be an other way how to make 100% sure that every single initialized object will be pointcut? *.new does not work for stuff such

AspectJ AOP LTW not working with dynamic loading of javaagent

﹥>﹥吖頭↗ 提交于 2019-11-28 08:48:18
问题 Here is my sample non-working project. It contains 2 modules: aop-lib - Aspects used as lib. It contains the following classes Wrap.java - It's the annotation used to attach advice WrapDef.java - It is the definition of the above mentioned Wrap annotation. aop-app - Uses the above aspect lib DynamicLoad.java - class to load javaagent dynamically Main.java - Main class which uses Wrap annotation. Dir structure is as follows: . ├── README.md ├── aop-app │ ├── pom.xml │ └── src │ └── main │ └──

How to enable aspectj compile time weaving with Java 7 and maven

天大地大妈咪最大 提交于 2019-11-28 04:34:14
I have a project which currently works with java 6 and compile time weaving. We use the following pom to enable spring aspects and our own ones: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <showWeaveInfo>true</showWeaveInfo> <source>1.6</source> <target>1.6</target> <Xlint>ignore</Xlint> <complianceLevel>1.6</complianceLevel> <encoding>UTF-8</encoding> <verbose>false</verbose> <aspectLibraries> <aspectLibrary> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </aspectLibrary> <

Maven + AspectJ - all steps to configure it

烈酒焚心 提交于 2019-11-28 03:57:33
I have a problem with applying aspects to my maven project. Probably I am missing something, so I've made a list of steps. Could you please check if it is correct? Let say in projectA is an aspect class and in projectB classes, which should be changed by aspects. Create maven project ProjectA with AspectJ class add Aspectj plugin and dependency Add ProjectA as a dependency to projectB pom.xml Add to projectB pom.xml plugin <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <goals> <goal>compile</goal>

What is AspectJ good for? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-28 03:12:08
First let me note, that I use AspectJ and I like it, but what else can I do with it. I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes with (code-generated) methods, like Spring Roo does. But I believe AspectJ and AOP in general, can be used for more than: logging, transaction controlling, and simulation partial classes. So what are other useful use cases for AspectJ and AOP? permission check interrupt action that takes too long run action in separate

spring aspectj - compile time weaving external jar

一曲冷凌霜 提交于 2019-11-28 01:30:21
问题 I have a project which uses compile time weaving of aspects. this project depends on another project, which is a included as a jar. I want to weave a class in the jar file while compiling. How can i achieve this. Thanks 回答1: This jar needs to be added to the inpath of the project being compiled. The result will be a new set of class files. These new class files are the woven ones and should be used at runtime instead of the original jar. How to set the in path is dependent on how you compile