You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/12/15 18:43:14 UTC
svn commit: r890902 - in
/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website:
Dispatch.java InternalRedirectException.java WebHandler.java
Author: simoneg
Date: Tue Dec 15 17:43:14 2009
New Revision: 890902
URL: http://svn.apache.org/viewvc?rev=890902&view=rev
Log:
Support for simple internal redirect
Added:
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/InternalRedirectException.java
Modified:
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java
Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java?rev=890902&r1=890901&r2=890902&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java Tue Dec 15 17:43:14 2009
@@ -98,11 +98,21 @@
// try to resolve the path
try {
- Producer producer = findProducer(pathInfo);
- if (producer == null && originalPathInfo != null) {
- // Fall back, in case of resources
- producer = findProducer(originalPathInfo);
- extension = "HTML";
+ Producer producer = null;
+ try {
+ producer = findProducer(pathInfo);
+ if (producer == null && originalPathInfo != null) {
+ // Fall back, in case of resources
+ producer = findProducer(originalPathInfo);
+ extension = "HTML";
+ }
+ } catch (Throwable e) {
+ Throwable act = findInnerException(e);
+ if (act instanceof InternalRedirectException) {
+ producer = ((InternalRedirectException)act).getProducer();
+ } else {
+ throw e;
+ }
}
if (producer != null) {
if (method == null) {
@@ -144,11 +154,16 @@
return ret;
}
+ private Throwable findInnerException(Throwable t) {
+ Throwable act = t;
+ while (act.getCause() != null) act = act.getCause();
+ return act;
+ }
+
protected void handleException(Throwable t, HttpServletResponse resp) {
try {
// Find the exception hidden inside redirects
- Throwable act = t;
- while (act.getCause() != null) act = act.getCause();
+ Throwable act = findInnerException(t);
if (act instanceof HttpCodeException) {
((HttpCodeException)act).apply(resp);
return;
Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/InternalRedirectException.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/InternalRedirectException.java?rev=890902&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/InternalRedirectException.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/InternalRedirectException.java Tue Dec 15 17:43:14 2009
@@ -0,0 +1,15 @@
+package org.apache.magma.website;
+
+public class InternalRedirectException extends Error {
+
+ private HtmlProducer producer;
+
+ public InternalRedirectException(HtmlProducer producer) {
+ this.producer = producer;
+ }
+
+ public HtmlProducer getProducer() {
+ return this.producer;
+ }
+
+}
Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java?rev=890902&r1=890901&r2=890902&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java Tue Dec 15 17:43:14 2009
@@ -274,12 +274,8 @@
return rightMethod;
}
- public HtmlProducer redirect(HtmlProducer to) {
- return to;
- }
-
- public WebHandler redirect(WebHandler to) {
- return to;
+ public void redirect(HtmlProducer to) {
+ throw new InternalRedirectException(to);
}
public void redirect(String url) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org