Index: tool-impl/impl/src/java/org/sakaiproject/tool/impl/SessionComponent.java =================================================================== --- tool-impl/impl/src/java/org/sakaiproject/tool/impl/SessionComponent.java (revision 32630) +++ tool-impl/impl/src/java/org/sakaiproject/tool/impl/SessionComponent.java (working copy) @@ -3,18 +3,18 @@ * $Id$ *********************************************************************************** * - * Copyright (c) 2005, 2006 The Sakai Foundation. - * - * Licensed under the Educational Community License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. + * Copyright (c) 2005, 2006, 2007 The Sakai Foundation. + * + * Licensed under the Educational Community License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.opensource.org/licenses/ecl1.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * **********************************************************************************/ @@ -70,6 +70,9 @@ /** Key in the ThreadLocalManager for binding our current tool session. */ protected final static String CURRENT_TOOL_SESSION = "org.sakaiproject.api.kernel.session.current.tool"; + /** Key in the ThreadLocalManager for access to the current servlet context (from tool-util/servlet/RequestFilter). */ + protected final static String CURRENT_SERVLET_CONTEXT = "org.sakaiproject.util.RequestFilter.servlet_context"; + /********************************************************************************************************************************************************************************************************************************************************** * Dependencies *********************************************************************************************************************************************************************************************************************************************************/ @@ -93,7 +96,7 @@ /** * Configuration - set the default inactive period for sessions. - * + * * @param value * The default inactive period for sessions. */ @@ -114,7 +117,7 @@ /** * Configuration: set how often to check for inactive sessions (seconds). - * + * * @param value * The how often to check for inactive sessions (seconds) value. */ @@ -558,10 +561,10 @@ { // add Object old = m_attributes.put(name, value); - + // bind event bind(name, value); - + // unbind event if old exiss if (old != null) { @@ -632,7 +635,7 @@ /** * Check if the session has become inactive - * + * * @return true if the session is capable of becoming inactive and has done so, false if not. */ protected boolean isInactive() @@ -666,7 +669,7 @@ */ public ServletContext getServletContext() { - throw new UnsupportedOperationException(); + return (ServletContext) threadLocalManager().get(CURRENT_SERVLET_CONTEXT); } /** @@ -719,7 +722,7 @@ /** * Unbind the value if it's a SessionBindingListener. Also does the HTTP unbinding if it's a HttpSessionBindingListener. - * + * * @param name * The attribute name bound. * @param value @@ -743,7 +746,7 @@ /** * Bind the value if it's a SessionBindingListener. Also does the HTTP binding if it's a HttpSessionBindingListener. - * + * * @param name * The attribute name bound. * @param value @@ -783,7 +786,7 @@ /** * Construct. - * + * * @param name * The name. * @param session @@ -1005,7 +1008,7 @@ /** * Unbind the value if it's a SessionBindingListener. Also does the HTTP unbinding if it's a HttpSessionBindingListener. - * + * * @param name * The attribute name bound. * @param value @@ -1029,7 +1032,7 @@ /** * Bind the value if it's a SessionBindingListener. Also does the HTTP binding if it's a HttpSessionBindingListener. - * + * * @param name * The attribute name bound. * @param value @@ -1071,7 +1074,7 @@ */ public ServletContext getServletContext() { - throw new UnsupportedOperationException(); + return (ServletContext) threadLocalManager().get(CURRENT_SERVLET_CONTEXT); } /** Index: tool-util/servlet/src/java/org/sakaiproject/util/RequestFilter.java =================================================================== --- tool-util/servlet/src/java/org/sakaiproject/util/RequestFilter.java (revision 32630) +++ tool-util/servlet/src/java/org/sakaiproject/util/RequestFilter.java (working copy) @@ -3,18 +3,18 @@ * $Id$ *********************************************************************************** * - * Copyright (c) 2005, 2006 The Sakai Foundation. - * - * Licensed under the Educational Community License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. + * Copyright (c) 2005, 2006, 2007 The Sakai Foundation. + * + * Licensed under the Educational Community License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.opensource.org/licenses/ecl1.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. * **********************************************************************************/ @@ -33,6 +33,7 @@ import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; @@ -157,6 +158,9 @@ /** Key in the ThreadLocalManager for access to the current http response object. */ public final static String CURRENT_HTTP_RESPONSE = "org.sakaiproject.util.RequestFilter.http_response"; + /** Key in the ThreadLocalManager for access to the current servlet context. */ + public final static String CURRENT_SERVLET_CONTEXT = "org.sakaiproject.util.RequestFilter.servlet_context"; + /** The "." character */ protected static final String DOT = "."; @@ -191,6 +195,9 @@ protected boolean m_displayModJkWarning = true; + /** The servlet context for the filter. */ + protected ServletContext m_servletContext = null; + /** * Wraps a request object so we can override some standard behavior. */ @@ -335,7 +342,7 @@ /** * Rewrites the given URL to insert the current tool placement id, if any, as the start of the path - * + * * @param url * The url to rewrite. */ @@ -402,7 +409,7 @@ /** * Constructs a wrapped response that exposes the given map of parameters. - * + * * @param req * The request to wrap. * @param paramMap @@ -467,6 +474,9 @@ ThreadLocalManager.set(CURRENT_HTTP_SESSION, new Integer(m_sakaiHttpSession)); ThreadLocalManager.set(CURRENT_CONTEXT, m_contextId); + // make the servlet context available + ThreadLocalManager.set(CURRENT_SERVLET_CONTEXT, m_servletContext); + // we are expecting HTTP stuff if (!((requestObj instanceof HttpServletRequest) && (responseObj instanceof HttpServletResponse))) { @@ -562,12 +572,15 @@ /** * Place this filter into service. - * + * * @param filterConfig * The filter configuration object */ public void init(FilterConfig filterConfig) throws ServletException { + // capture the servlet context for later user + m_servletContext = filterConfig.getServletContext(); + if (filterConfig.getInitParameter(CONFIG_SESSION) != null) { String s = filterConfig.getInitParameter(CONFIG_SESSION); @@ -609,7 +622,7 @@ } else { - m_contextId = filterConfig.getServletContext().getServletContextName(); + m_contextId = m_servletContext.getServletContextName(); if (m_contextId == null) { m_contextId = toString(); @@ -675,7 +688,7 @@ /** * if the filter is configured to parse file uploads, AND the request is multipart (typically a file upload), then parse the request. - * + * * @return If there is a file upload, and the filter handles it, return the wrapped request that has the results of the parsed file upload. Parses the files using Apache commons-fileuplaod. Exposes the results through a wrapped request. Files are * available like: fileItem = (FileItem) request.getAttribute("myHtmlFileUploadId"); */ @@ -801,7 +814,7 @@ /** * Make sure we have a Sakai session. - * + * * @param req * The request object. * @param res @@ -940,7 +953,7 @@ /** * Detect a tool placement from the URL, and if found, setup the placement attribute and current tool session based on that id. - * + * * @param s * The sakai session. * @param req @@ -973,7 +986,7 @@ /** * Pre-process the request, returning a possibly wrapped req for further processing. - * + * * @param s * The Sakai Session. * @param req @@ -989,7 +1002,7 @@ /** * Pre-process the response, returning a possibly wrapped res for further processing. - * + * * @param s * The Sakai Session. * @param req @@ -1007,7 +1020,7 @@ /** * Post-process the response. - * + * * @param s * The Sakai Session. * @param req @@ -1021,7 +1034,7 @@ /** * Find a cookie by this name from the request; one with a value that has the specified suffix. - * + * * @param req * The servlet request. * @param name @@ -1052,7 +1065,7 @@ /** * Compute the URL that would return to this server based on the current request. Note: this method is a duplicate of one in the util/Web.java - * + * * @param req * The request. * @return The URL back to this server based on the current request.