Author: mgrigorov
Date: Sun Feb 13 13:41:34 2011
New Revision: 1070238

URL: http://svn.apache.org/viewvc?rev=1070238&view=rev
Log:
WICKET-3407 Switching from HttsRequired page to http page with forms in both 
pages

Use HttpsConfig that extracts the http port from the current http request's 
local port.
This way the example can run with Jetty (most of the time on port 8080) and in 
production eventually behind proxy (like www.wicketstuff.org and 
www.wicket-library.com)


Modified:
    
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java

Modified: 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java?rev=1070238&r1=1070237&r2=1070238&view=diff
==============================================================================
--- 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
 (original)
+++ 
wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/RequestMapperApplication.java
 Sun Feb 13 13:41:34 2011
@@ -16,12 +16,15 @@
  */
 package org.apache.wicket.examples.requestmapper;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.wicket.Page;
 import org.apache.wicket.RuntimeConfigurationType;
 import org.apache.wicket.examples.WicketExampleApplication;
 import 
org.apache.wicket.examples.requestmapper.packageMount.PackageMountedPage;
 import org.apache.wicket.protocol.https.HttpsConfig;
 import org.apache.wicket.protocol.https.HttpsMapper;
+import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.mapper.MountedMapper;
 
 /**
@@ -59,7 +62,7 @@ public class RequestMapperApplication ex
 
                mountResource("/print/${sheet}/${format}", new 
MapperDemoResourceReference());
 
-               setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), 
new HttpsConfig()));
+               setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), 
new LazyHttpsConfig()));
        }
 
        /**
@@ -70,4 +73,42 @@ public class RequestMapperApplication ex
        {
                return RuntimeConfigurationType.DEVELOPMENT;
        }
+
+       /**
+        * HttpsConfig that extracts the <i>http</i> port out of the current 
servlet request's local
+        * port. This way the demo can be used both with Jetty (port 8080) and 
at production (behind
+        * Apache proxy)
+        */
+       private static class LazyHttpsConfig extends HttpsConfig
+       {
+               @Override
+               public int getHttpPort()
+               {
+                       int port = -1;
+
+                       RequestCycle requestCycle = RequestCycle.get();
+                       if (requestCycle != null)
+                       {
+                               HttpServletRequest containerRequest = 
(HttpServletRequest)requestCycle.getRequest()
+                                       .getContainerRequest();
+                               if (containerRequest != null)
+                               {
+                                       port = containerRequest.getLocalPort();
+                               }
+                       }
+
+                       if (port == -1)
+                       {
+                               port = super.getHttpPort();
+                       }
+
+                       return port;
+               }
+
+               @Override
+               public int getHttpsPort()
+               {
+                       return 443;
+               }
+       }
 }


Reply via email to