cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r682355 - in /cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon: callstack/environment/ servletservice/ servletservice/url/
Date Mon, 04 Aug 2008 12:16:13 GMT
Author: reinhard
Date: Mon Aug  4 05:16:12 2008
New Revision: 682355

URL: http://svn.apache.org/viewvc?rev=682355&view=rev
Log:
. make the CallFramehelper more defensive -> check for null references
. throw exceptions in the case of a SSF self-reference or relative reference because this
always requires a calling SSF request. Only an absolute reference can work without a stand-alone
reference

Added:
    cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
  (with props)
Modified:
    cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
    cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/url/ServletURLConnection.java

Modified: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java?rev=682355&r1=682354&r2=682355&view=diff
==============================================================================
--- cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
(original)
+++ cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
Mon Aug  4 05:16:12 2008
@@ -33,7 +33,7 @@
  *
  * @version $Id$
  */
-public final class CallFrameHelper {
+public abstract class CallFrameHelper {
 
     /** Key for the environment {@link HttpServletRequest} in the call frame. */
     public final static String REQUEST_OBJECT  = "request";
@@ -44,10 +44,6 @@
     /** Key for the environment {@link ServletContext} in the call frame. */
     public final static String CONTEXT_OBJECT  = "context";
 
-    private CallFrameHelper() {
-        // Forbid instantiation
-    }
-
     public static final void setEnvironment(HttpServletRequest request, HttpServletResponse
response, ServletContext context) {
         CallFrame frame = CallStack.getCurrentFrame();
         frame.setAttribute(REQUEST_OBJECT, request);
@@ -56,7 +52,13 @@
     }
 
     public static final HttpServletRequest getRequest() {
-        return (HttpServletRequest) CallStack.getCurrentFrame().getAttribute(REQUEST_OBJECT);
+        CallFrame currentCallFrame = CallStack.getCurrentFrame();
+        
+        if(currentCallFrame == null) {
+            return null;
+        }
+        
+        return (HttpServletRequest) currentCallFrame.getAttribute(REQUEST_OBJECT);
     }
 
     public static final void setRequest(HttpServletRequest request) {
@@ -64,7 +66,13 @@
     }
 
     public static final HttpServletResponse getResponse() {
-        return (HttpServletResponse) CallStack.getCurrentFrame().getAttribute(RESPONSE_OBJECT);
+        CallFrame currentCallFrame = CallStack.getCurrentFrame();
+        
+        if(currentCallFrame == null) {
+            return null;
+        }
+        
+        return (HttpServletResponse) currentCallFrame.getAttribute(RESPONSE_OBJECT);
     }
 
     public static final void setResponse(HttpServletResponse response) {
@@ -72,11 +80,16 @@
     }
 
     public static final ServletContext getContext() {
-        return (ServletContext) CallStack.getCurrentFrame().getAttribute(CONTEXT_OBJECT);
+        CallFrame currentCallFrame = CallStack.getCurrentFrame();
+        
+        if(currentCallFrame == null) {
+            return null;
+        }        
+        
+        return (ServletContext) currentCallFrame.getAttribute(CONTEXT_OBJECT);
     }
 
     public static final void setContext(ServletContext context) {
         CallStack.getCurrentFrame().setAttribute(CONTEXT_OBJECT, context);
     }
-
 }

Added: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java?rev=682355&view=auto
==============================================================================
--- cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
(added)
+++ cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
Mon Aug  4 05:16:12 2008
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+package org.apache.cocoon.servletservice;
+
+public class NoCallingServletServiceRequestAvailableException extends RuntimeException {
+
+    public NoCallingServletServiceRequestAvailableException(String message) {
+        super(message);
+    }
+}

Propchange: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/NoCallingServletServiceRequestAvailableException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/url/ServletURLConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/url/ServletURLConnection.java?rev=682355&r1=682354&r2=682355&view=diff
==============================================================================
--- cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/url/ServletURLConnection.java
(original)
+++ cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/url/ServletURLConnection.java
Mon Aug  4 05:16:12 2008
@@ -31,6 +31,7 @@
 import org.apache.cocoon.servletservice.AbsoluteServletConnection;
 import org.apache.cocoon.servletservice.Absolutizable;
 import org.apache.cocoon.servletservice.CallStackHelper;
+import org.apache.cocoon.servletservice.NoCallingServletServiceRequestAvailableException;
 import org.apache.cocoon.servletservice.ServletConnection;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -63,12 +64,22 @@
         // find out the type of the reference and create a service name
         if (servletReference == null) {
             // self-reference
+            if (absolutizable == null) {
+                throw new NoCallingServletServiceRequestAvailableException(
+                        "A self-reference requires an active servlet request.");
+            }
+
             servletName = absolutizable.getServiceName();
         } else if (servletReference.endsWith(AbsoluteServletConnection.ABSOLUTE_SERVLET_SOURCE_POSTFIX))
{
             // absolute reference
             servletName = servletReference.substring(0, servletReference.length() - 1);
         } else {
             // relative reference
+            if (absolutizable == null) {
+                throw new NoCallingServletServiceRequestAvailableException(
+                        "A relative servlet call requires an active servlet request.");
+            }
+
             servletName = absolutizable.getServiceName(servletReference);
         }
 



Mime
View raw message