Author: drobiazko
Date: Fri May 28 21:25:06 2010
New Revision: 949300

URL: http://svn.apache.org/viewvc?rev=949300&view=rev
Log:
TAP5-1174: Provide a ComponentEventResultProcessor that sends an error response 
to the client

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
   (with props)
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java?rev=949300&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
 Fri May 28 21:25:06 2010
@@ -0,0 +1,50 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.services;
+
+/**
+ * An event handler method may return an instance of this class to send an 
error response to the client.
+ * 
+ * @since 5.2.0
+ */
+public final class HttpError
+{
+    private final int statusCode;
+
+    private final String message;
+    
+    public HttpError(int statusCode, String message)
+    {
+        this.statusCode = statusCode;
+        
+        this.message = message;
+    }
+    
+
+    /**
+     * Returns the error status code.
+     */
+    public int getStatusCode()
+    {
+        return statusCode;
+    }
+
+    /**
+     * Returns error message.
+     */
+    public String getMessage()
+    {
+        return message;
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HttpError.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=949300&r1=949299&r2=949300&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Fri May 28 21:25:06 2010
@@ -1765,6 +1765,14 @@ public final class TapestryModule
             }
         });
 
+        configuration.add(HttpError.class, new 
ComponentEventResultProcessor<HttpError>()
+        {
+            public void processResultValue(HttpError value) throws IOException
+            {
+                response.sendError(value.getStatusCode(), value.getMessage());
+            }
+        });
+
         configuration.addInstance(String.class, 
PageNameComponentEventResultProcessor.class);
 
         configuration.addInstance(Class.class, ClassResultProcessor.class);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml?rev=949300&r1=949299&r2=949300&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml Fri 
May 28 21:25:06 2010
@@ -52,4 +52,11 @@
     </p>
 
 
+    <p>
+        Test
+        <a t:type="ActionLink" t:id="HttpError">http error</a>
+        return values.
+    </p>
+
+
 </html>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=949300&r1=949299&r2=949300&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 Fri May 28 21:25:06 2010
@@ -541,6 +541,13 @@ public class CoreBehaviorsTests extends 
                 "An unexpected application exception has occurred.",
                 "A component event handler method returned the value 20. 
Return type java.lang.Integer can not be handled.",
                 "context:ReturnTypes.tml, line 50");
+        goBack();
+        waitForPageToLoad();
+        
+        clickAndWait("link=http error");
+        assertTextPresent(
+                "HTTP ERROR 410",
+                "Oups! Resource disappeared!");
     }
 
     @Test

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java?rev=949300&r1=949299&r2=949300&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
 Fri May 28 21:25:06 2010
@@ -18,11 +18,14 @@ import org.apache.tapestry5.ComponentRes
 import org.apache.tapestry5.annotations.InjectPage;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.services.ComponentEventResultProcessor;
+import org.apache.tapestry5.services.HttpError;
 import org.apache.tapestry5.util.TextStreamResponse;
 
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * Tests the various event handler method return types.
  *
@@ -77,4 +80,11 @@ public class ReturnTypes
     {
         return new URL("http://google.com";);
     }
+    
+
+
+    Object onActionFromHttpError()
+    {
+        return new HttpError(HttpServletResponse.SC_GONE, "Oups! Resource 
disappeared!");
+    }
 }


Reply via email to