2024-08-07 11:01:45 -04:00
2024-08-07 11:14:05 -04:00
2024-08-07 11:14:05 -04:00
2024-08-07 14:40:00 -04:00
2024-08-07 15:02:58 -04:00
2023-04-04 13:59:33 -04:00
2024-08-07 14:40:00 -04:00
2024-08-07 11:01:45 -04:00

AspectJ Module for Alfresco Content Services

This module provides AspectJ support to Alfresco Content Services.

Why?

AspectJ vs AOP Alliance

Alfresco Content Services rests on top of the Spring Framework. It is an older version and the code was originally written before 2010. Although it uses the principles behind AspectJ, it does not use the modern implementation of it. It instead is using the AOP Alliance API, a stripped down version of AspectJ (aspectjrt), and spring-aop. Although these libraries seem to support annotation-based AspectJ implementations, you will quickly run into problems.

AspectJ in Spring AOP

In order to enable spring-aop for AspectJ, you typically include <aop:aspectj-autoproxy /> in the Spring context (ACS module module-context.xml). When you do this, it will try to pick up all the AOP Alliance MethodInterceptor implementations too. It winds up doing way more than it should and ACS startup errors ensue.

If you try to narrow it using <aop:include>, the problem persists. If you try to use <aop:config> you'll still have the same problem. There seems to be no way to use AspectJ annotations with ACS using the spring-aop module.

AspectJ outside Spring AOP, but in Spring

So this module enables AspectJ as if you were not using Spring. It then assumes your @Aspect objects are Spring beans and loads them dynamically. This prevents conflicts with ACS libraries while giving you the ability to use AspectJ annotations.

How?

This library will handle nearly all the requirements to get AspectJ working in ACS. The following are the exceptions and notes you need to be aware of.

@Aspect

You can use the @Aspect annotation as you would think. However, you cannot add a @Component or similar annotation to the class. The class must NOT be defined as a Spring bean. We need to let AspectJ instantiate the class; not Spring. This module will side-load the instance as a Spring bean, including any use of @PostConstruct, @Autowired, and @Value as one would expect.

You will also need to specify the base packages to scan for @Aspect classes and @. You can do that with any unique property in alfresco-global.properties (environment or module) or in the Java -D arguments. Here is an example:

inteligr8.mymodule.aspectj.basePackages=com.myco.alfresco.mymodule.aspect

Each package must have its own unique property with the suffix .aspectj.basePackages. It does not support a comma-delimited list of packages.

aop.xml

AspectJ without Spring AOP requires you to define your aspects. This is a requirement of Spring to work properly with AspectJ. It is loaded by the JVM agent (super-early), so it cannot be dynamic. This module includes an aop.xml that deals with excluding ACS libraries. You just need to define your aspects and maybe exclude some more libraries to prevent them from being picked up.

Create a file in your src/main/resources or similar path, called: META-INF/aop.xml. It should have something like the following contents. You cannot use wildcards to capture your aspects.

<aspectj>
    <aspects>
        <aspect name="com.myco.alfresco.mymodule.aspect.MyAspect" />
    </aspects>
</aspectj>

Maven Project

If you are developing your module in Maven, you can include this project as a dependency. That will get you access to the AspectJ API for compiling your module. Do not include the library in your module AMP. This is automatically handled by the Order Of The Bee SDK. The Alfresco SDK may need a scope of provided.

AspectJ Agent

This is the most complicated requirement of this module. AspectJ needs to use an agent at startup to enable its functionality. You will need the following property provided at runtime:

-javaagent:/path/to/aspectjweaver-${aspectj.version}.jar

How you do this is very highly dependent on your runtime environment. When using the OOTB SDK, you can provide the following Maven property to enable AspectJ in your RAD or IT testing:

<acs-platform.tomcat.opts>-javaagent:/var/lib/tomcat/dev/lib/aspectjweaver-${aspectj.version}.jar</acs-platform.tomcat.opts>
Description
No description provided
Readme 61 KiB
Languages
Java 57.2%
PowerShell 21.8%
Shell 21%