]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-182: Added an AOP (AspectJ) around aspect to intercept the marshaling by the...
authorremillet <remillet@yahoo.com>
Fri, 15 Dec 2017 04:58:18 +0000 (20:58 -0800)
committerremillet <remillet@yahoo.com>
Fri, 15 Dec 2017 04:58:18 +0000 (20:58 -0800)
pom.xml
services/JaxRsServiceProvider/pom.xml
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/aspect/HyperJaxb3TimezoneAspect.java [new file with mode: 0644]
services/JaxRsServiceProvider/src/main/resources/META-INF/aop.xml [new file with mode: 0644]
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml
services/common/build.xml
services/common/lib/aspectj/aspectjrt-1.7.4.jar [new file with mode: 0644]
services/common/lib/aspectj/aspectjtools-1.7.4.jar [new file with mode: 0644]
services/common/lib/aspectj/aspectjweaver-1.7.4.jar [new file with mode: 0644]
services/common/lib/spring/spring-instrument-4.3.1.RELEASE.jar [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 0119afe1f666159462983720ba46423804c1bdcd..4b4c781c55e744a1ac0133dfeb34cb966c6fdb53 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,7 @@
                <spring.version>4.3.1.RELEASE</spring.version>
                <spring.security.version>4.1.1.RELEASE</spring.security.version>
                <spring.security.oauth2.version>2.0.10.RELEASE</spring.security.oauth2.version>
+               <aspectj.version>1.7.4</aspectj.version>
        </properties>
 
        <distributionManagement>
index 9c8f180e6fe2a27a6065f94e1b4d718d01f3a70a..76070e3e5e74608451d78670f602bdb930765435 100644 (file)
                </exclusion>
             </exclusions>
         </dependency>
+        
+               <!-- AspectJ dependencies -->
+               <dependency>
+                       <groupId>org.aspectj</groupId>
+                       <artifactId>aspectjrt</artifactId>
+                       <version>${aspectj.version}</version>
+                       <scope>runtime</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.aspectj</groupId>
+                       <artifactId>aspectjtools</artifactId>
+                       <version>${aspectj.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.aspectj</groupId>
+                       <artifactId>aspectjweaver</artifactId>
+                       <version>${aspectj.version}</version>
+               </dependency>        
 
         <!-- javax -->
         <dependency>
diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/aspect/HyperJaxb3TimezoneAspect.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/aspect/HyperJaxb3TimezoneAspect.java
new file mode 100644 (file)
index 0000000..34e2bf7
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * An AOP (AspectJ) aspect to resolve the timezone related issue https://issues.collectionspace.org/browse/DRYD-182.
+ * 
+ * See related config in files: src/main/resources/META-INF/aop.xml, src/main/webapp/WEB-INF/applicationContext-security.xml
+ * 
+ */
+package org.collectionspace.services.aspect;
+
+import java.util.Date;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect
+public class HyperJaxb3TimezoneAspect {
+
+       @Around("methodsToBeProfiled()")
+    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
+        try {
+               Date fromDate = (Date)pjp.getArgs()[0];
+               XMLGregorianCalendar toDate = (XMLGregorianCalendar)pjp.getArgs()[1];
+                        
+            Object result = pjp.proceed();
+            //
+            // Marshal the timezone info from the 'fromDate' Date instance into the XMLGregorianCalendar 'toDate' instance
+            //
+            toDate.setTimezone(fromDate.getTimezoneOffset());
+
+            return result;
+        } finally {
+            // No cleanup needed.
+        }
+    }
+
+    /**
+     * Intercept all calls to the createCalendar() method of the XMLGregorianCalendarAsDateTime class.  This is how HyperJaxb3 marshals datetime info from Hibernate/JPA into
+     * out AuthN/AuthZ class instances.
+     */
+    @Pointcut("execution(* org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XMLGregorianCalendarAsDateTime.createCalendar(java.util.Date, javax.xml.datatype.XMLGregorianCalendar))")
+    public void methodsToBeProfiled() {}
+}
\ No newline at end of file
diff --git a/services/JaxRsServiceProvider/src/main/resources/META-INF/aop.xml b/services/JaxRsServiceProvider/src/main/resources/META-INF/aop.xml
new file mode 100644 (file)
index 0000000..c1069b6
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE aspectj PUBLIC
+        "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
+<aspectj>
+    <weaver>
+        <!-- only weave classes in our application-specific packages -->
+        <include within="org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.*"/> 
+        <include within="org.collectionspace.services.aspect.*"/>
+    </weaver>
+    
+    <aspects>        
+        <!-- weave in just this aspect -->        
+        <aspect name="org.collectionspace.services.aspect.HyperJaxb3TimezoneAspect"/>
+    </aspects>
+</aspectj>
\ No newline at end of file
index 6587e9e35a96be9e4ee4d9438b06e9368d15675f..5d7733340c44c124298c55af328b17229d482668 100644 (file)
     <bean id="userAttributeFilter"
         class="org.collectionspace.authentication.spring.CSpaceUserAttributeFilter">
     </bean>
+    
+    <!-- Switches on the AOP (AspectJ) load-time weaving -->
+    <context:load-time-weaver/>
+    
 </beans>
index d631e58197057f8cbd97f25dd944c7db7a7122ce..e62c3dfffe896702b0c66e0a62bc11bc4ec89000 100644 (file)
             <fileset dir="${basedir}/lib/spring"/>
         </copy>
     </target>
+       
+       <target name="deploy_aspectj"
+            description="deploy AspectJ binaries in ${jee.server.cspace}">
+        <copy todir="${jee.server.cspace}/lib">
+            <fileset dir="${basedir}/lib/aspectj"/>
+        </copy>
+    </target>
 
     <target name="deploy_slf4j"
             description="deploy spring binaries in ${jee.server.cspace}">
         <copy todir="${jee.server.cspace}/conf"
               file="${src}/main/cspace/config/log/jboss-log4j-release.xml"/>
                -->
+               <antcall target="deploy_aspectj" />
         <antcall target="deploy_spring" />
         <antcall target="deploy_slf4j" />
         <antcall target="deploy_xmlmerge" />
 
     <target name="undeploy"
             description="undeploy common elements from ${jee.server.cspace}">
-        <antcall target="undeploy_spring" />
+        <antcall target="undeploy_aspectj" />
+               <antcall target="undeploy_spring" />
                <antcall target="undeploy_slf4j" />
                <antcall target="undeploy_xmlmerge" />
                <!--
         </delete>
     </target>
        
+       <target name="undeploy_aspectj"
+            description="undeploy AspectJ binaries from ${jee.server.cspace}">
+        <delete>
+            <fileset dir="${jee.server.cspace}/lib" includes="aspectj*-*.jar"/>
+        </delete>
+    </target>
+       
     <target name="undeploy_slf4j"
             description="undeploy SLF4J binaries from ${jee.server.cspace}">
         <delete>
diff --git a/services/common/lib/aspectj/aspectjrt-1.7.4.jar b/services/common/lib/aspectj/aspectjrt-1.7.4.jar
new file mode 100644 (file)
index 0000000..dc30b02
Binary files /dev/null and b/services/common/lib/aspectj/aspectjrt-1.7.4.jar differ
diff --git a/services/common/lib/aspectj/aspectjtools-1.7.4.jar b/services/common/lib/aspectj/aspectjtools-1.7.4.jar
new file mode 100644 (file)
index 0000000..4f9afb0
Binary files /dev/null and b/services/common/lib/aspectj/aspectjtools-1.7.4.jar differ
diff --git a/services/common/lib/aspectj/aspectjweaver-1.7.4.jar b/services/common/lib/aspectj/aspectjweaver-1.7.4.jar
new file mode 100644 (file)
index 0000000..0c155a9
Binary files /dev/null and b/services/common/lib/aspectj/aspectjweaver-1.7.4.jar differ
diff --git a/services/common/lib/spring/spring-instrument-4.3.1.RELEASE.jar b/services/common/lib/spring/spring-instrument-4.3.1.RELEASE.jar
new file mode 100644 (file)
index 0000000..73d9d57
Binary files /dev/null and b/services/common/lib/spring/spring-instrument-4.3.1.RELEASE.jar differ