01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.weblogic;
05:
06: import com.tc.aspectwerkz.DeploymentModel;
07: import com.tc.aspectwerkz.definition.deployer.AspectDefinitionBuilder;
08: import com.tc.aspectwerkz.definition.deployer.AspectModule;
09: import com.tc.aspectwerkz.definition.deployer.AspectModuleDeployer;
10:
11: public class SessionAspectModule implements AspectModule {
12:
13: public void deploy(AspectModuleDeployer deployer) {
14: if (isWL9()) {
15: addWL9Aspect(deployer);
16: } else {
17: addWL8Aspect(deployer);
18: }
19: }
20:
21: private boolean isWL9() {
22: try {
23: Class.forName("weblogic.kernel.KernelInitializer", false,
24: ClassLoader.getSystemClassLoader());
25: } catch (ClassNotFoundException e) {
26: return false;
27: }
28: return true;
29: }
30:
31: private void addWL8Aspect(AspectModuleDeployer deployer) {
32: AspectDefinitionBuilder builder = deployer.newAspectBuilder(
33: "com.tc.weblogic.SessionAspect",
34: DeploymentModel.PER_JVM, null);
35: builder
36: .addAdvice(
37: "around",
38: "withincode(* weblogic.servlet.internal.WebAppServletContext.prepareFromDescriptors(..)) "
39: + "AND call(* weblogic.management.descriptors.webapp.WebAppDescriptorMBean.getFilters()) "
40: + "AND this(webAppServletContext)",
41: "addFilterIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.WebAppServletContext webAppServletContext)");
42:
43: builder
44: .addAdvice(
45: "around",
46: "withincode(* weblogic.servlet.internal.WebAppServletContext.prepareFromDescriptors(..)) "
47: + "AND call(* weblogic.management.descriptors.webapp.WebAppDescriptorMBean.getFilterMappings()) "
48: + "AND this(webAppServletContext)",
49: "addFilterMappingIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.WebAppServletContext webAppServletContext)");
50: }
51:
52: private void addWL9Aspect(AspectModuleDeployer deployer) {
53: AspectDefinitionBuilder builder = deployer.newAspectBuilder(
54: "com.tc.weblogic.SessionAspectWL9",
55: DeploymentModel.PER_JVM, null);
56:
57: builder
58: .addAdvice(
59: "around",
60: "withincode(* weblogic.servlet.internal.FilterManager.registerServletFilters(..)) "
61: + "AND call(* weblogic.j2ee.descriptor.WebAppBean+.getFilters()) "
62: + "AND this(filterManager)",
63: "addFilterIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.FilterManager filterManager)");
64:
65: builder
66: .addAdvice(
67: "around",
68: "withincode(* weblogic.servlet.internal.FilterManager.registerServletFilters(..)) "
69: + "AND call(* weblogic.j2ee.descriptor.WebAppBean+.getFilterMappings()) "
70: + "AND this(filterManager)",
71: "addFilterMappingIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.FilterManager filterManager)");
72:
73: }
74: }
|