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 weblogic.j2ee.descriptor.FilterBean;
07: import weblogic.j2ee.descriptor.FilterMappingBean;
08: import weblogic.servlet.internal.WebAppServletContext;
09:
10: import com.tc.aspectwerkz.joinpoint.StaticJoinPoint;
11: import com.tc.object.bytecode.hook.impl.ClassProcessorHelper;
12:
13: public class SessionAspectWL9 {
14:
15: /**
16: * Used in WL 9.2 to insert the Terracotta SessionFilter.
17: * @param jp The Aspectwerkz join point
18: * @param filterManager The Weblogic 9.2 FilterManager - does not exist in WL 8.
19: * @return The FilterMBean[] expected to be returned from the original call.
20: */
21: public Object addFilterIfNeeded(StaticJoinPoint jp,
22: weblogic.servlet.internal.FilterManager filterManager)
23: throws Throwable {
24:
25: FilterBean[] filters = (FilterBean[]) jp.proceed();
26: if (filters == null) {
27: filters = new FilterBean[] {};
28: }
29:
30: WebAppServletContext context = filterManager.__tc_getContext();
31: if (isDSOSessions(context)) {
32:
33: FilterBean filter = new DSOFilterBean();
34: FilterBean[] withDSO = new FilterBean[filters.length + 1];
35: System.arraycopy(filters, 0, withDSO, 1, filters.length);
36: withDSO[0] = filter;
37: filters = withDSO;
38: }
39:
40: return filters;
41: }
42:
43: /**
44: * Used in WL 9.2 to insert the Terracotta SessionFilter.
45: * @param jp The Aspectwerkz join point
46: * @param filterManager The Weblogic 9.2 FilterManager - does not exist in WL 8.
47: * @return The FilterMappingMBean[] expected to be returned from the original call.
48: */
49: public Object addFilterMappingIfNeeded(StaticJoinPoint jp,
50: weblogic.servlet.internal.FilterManager filterManager)
51: throws Throwable {
52: FilterMappingBean[] mappings = (FilterMappingBean[]) jp
53: .proceed();
54: if (mappings == null) {
55: mappings = new FilterMappingBean[] {};
56: }
57:
58: WebAppServletContext context = filterManager.__tc_getContext();
59: if (isDSOSessions(context)) {
60: FilterMappingBean[] withDSO = new FilterMappingBean[mappings.length + 1];
61: System.arraycopy(mappings, 0, withDSO, 1, mappings.length);
62: withDSO[0] = new DSOFilterMappingBean(new DSOFilterBean());
63: mappings = withDSO;
64: }
65: return mappings;
66: }
67:
68: private static boolean isDSOSessions(WebAppServletContext context) {
69: // Get context path and strip leading /
70: String appName = context.getContextPath();
71: if (appName.startsWith("/")) {
72: appName = appName.substring(1, appName.length());
73: }
74:
75: boolean rv = ClassProcessorHelper.isDSOSessions(appName);
76: return rv;
77: }
78:
79: }
|