[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Shane Bryzak
sbryzak at redhat.com
Thu Feb 22 09:37:46 EST 2007
User: sbryzak2
Date: 07/02/22 09:37:46
Modified: src/main/org/jboss/seam/core Manager.java Pages.java
Log:
http/https redirect
Revision Changes Path
1.145 +45 -4 jboss-seam/src/main/org/jboss/seam/core/Manager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Manager.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -b -r1.144 -r1.145
--- Manager.java 13 Feb 2007 06:50:44 -0000 1.144
+++ Manager.java 22 Feb 2007 14:37:46 -0000 1.145
@@ -11,6 +11,8 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
@@ -22,6 +24,7 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
+import javax.servlet.http.HttpServletRequest;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
@@ -42,7 +45,7 @@
*
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.144 $
+ * @version $Revision: 1.145 $
*/
@Scope(ScopeType.EVENT)
@Name("org.jboss.seam.core.manager")
@@ -863,7 +866,12 @@
*/
public void redirect(String viewId)
{
- redirect(viewId, null, true);
+ redirect(viewId, null, true, null);
+ }
+
+ public void redirect(String viewId, String scheme)
+ {
+ redirect(viewId, null, true, scheme);
}
public void interpolateAndRedirect(String url)
@@ -947,7 +955,14 @@
* @param parameters request parameters to be encoded (possibly null)
* @param includeConversationId determines if the conversation id is to be encoded
*/
- public void redirect(String viewId, Map<String, Object> parameters, boolean includeConversationId)
+ public void redirect(String viewId, Map<String, Object> parameters,
+ boolean includeConversationId)
+ {
+ redirect(viewId, parameters, includeConversationId, null);
+ }
+
+ public void redirect(String viewId, Map<String, Object> parameters,
+ boolean includeConversationId, String scheme)
{
/*if ( Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE )
{
@@ -964,6 +979,15 @@
url = encodeConversationId(url);
beforeRedirect();
}
+ if (scheme != null)
+ {
+ URL u = getRequestURL(context);
+ try
+ {
+ url = new URL(scheme, u.getHost(), u.getPort(), url).toString();
+ }
+ catch (MalformedURLException ex) {}
+ }
if ( log.isDebugEnabled() )
{
log.debug("redirecting to: " + url);
@@ -985,6 +1009,23 @@
context.responseComplete(); //work around MyFaces bug in 1.1.1
}
+ private URL getRequestURL(FacesContext facesContext)
+ {
+ Object req = facesContext.getExternalContext().getRequest();
+
+ if (!(req instanceof HttpServletRequest)) return null;
+
+ try
+ {
+ URL url = new URL(((HttpServletRequest) req).getRequestURL().toString());
+ return url;
+ }
+ catch (MalformedURLException ex)
+ {
+ return null;
+ }
+ }
+
/**
* Called by the Seam Redirect Filter when a redirect is called.
* Appends the conversationId parameter if necessary.
1.90 +33 -5 jboss-seam/src/main/org/jboss/seam/core/Pages.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Pages.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pages.java,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -b -r1.89 -r1.90
--- Pages.java 22 Feb 2007 10:14:57 -0000 1.89
+++ Pages.java 22 Feb 2007 14:37:46 -0000 1.90
@@ -2,6 +2,8 @@
import static org.jboss.seam.InterceptionType.NEVER;
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -17,6 +19,8 @@
import javax.faces.application.ViewHandler;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletRequest;
+
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.jboss.seam.Component;
@@ -234,9 +238,15 @@
{
boolean result = false;
String viewId = facesContext.getViewRoot().getViewId();
+ String scheme = getRequestScheme(facesContext);
for ( Page page: getPageStack(viewId) )
{
- if ( page.isConversationRequired() && !Manager.instance().isLongRunningConversation() )
+ if ( scheme != null && !scheme.equals(page.getScheme()) )
+ {
+ Manager.instance().redirect( viewId, page.getScheme() );
+ return result;
+ }
+ else if ( page.isConversationRequired() && !Manager.instance().isLongRunningConversation() )
{
redirectToNoConversationView();
return result;
@@ -258,14 +268,31 @@
return result;
}
+ private String getRequestScheme(FacesContext facesContext)
+ {
+ Object req = facesContext.getExternalContext().getRequest();
+
+ if (!(req instanceof HttpServletRequest)) return null;
+
+ try
+ {
+ URL url = new URL(((HttpServletRequest) req).getRequestURL().toString());
+ return url.getProtocol();
+ }
+ catch (MalformedURLException ex)
+ {
+ return null;
+ }
+ }
+
public void redirectToLoginView()
{
notLoggedIn();
- String noConversationViewId = getLoginViewId();
- if (noConversationViewId!=null)
+ String loginViewId = getLoginViewId();
+ if (loginViewId!=null)
{
- Manager.instance().redirect(noConversationViewId);
+ Manager.instance().redirect(loginViewId);
}
}
@@ -747,6 +774,7 @@
page.setNoConversationViewId( element.attributeValue("no-conversation-view-id") );
page.setConversationRequired( "true".equals( element.attributeValue("conversation-required") ) );
page.setLoginRequired( "true".equals( element.attributeValue("login-required") ) );
+ page.setScheme( element.attributeValue("scheme") );
Action action = parseAction(element, "action");
if (action!=null) page.getActions().add(action);
More information about the jboss-cvs-commits
mailing list