Author: svenmeier
Date: Thu Jul 28 20:40:16 2011
New Revision: 1151992
URL: http://svn.apache.org/viewvc?rev=1151992&view=rev
Log:
WICKET-3917 SwitchProtocolRequestHandler is never instantiated with a delegated
IRequestHandler, so I don't see why it should implement IRequestHandlerDelegate
while always returning null in #getDelegateHandler() and thus failing the
request logger.
Note that I had to revert the test in SwitchProtocolRequestHandlerTest added
for WICKET-3380, since now a SwitchProtocolRequestHandler cannot be mapped to a
Url - why should this be even possible? The quickstart attached to WICKET-3380
works without this anyway.
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandler.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandlerTest.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandler.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandler.java?rev=1151992&r1=1151991&r2=1151992&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandler.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandler.java
Thu Jul 28 20:40:16 2011
@@ -20,7 +20,6 @@ import javax.servlet.http.HttpServletReq
import org.apache.wicket.request.IRequestCycle;
import org.apache.wicket.request.IRequestHandler;
-import org.apache.wicket.request.IRequestHandlerDelegate;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebRequest;
import org.apache.wicket.request.http.WebResponse;
@@ -29,15 +28,12 @@ import org.apache.wicket.util.lang.Args;
/**
* Request handler that performs redirects across http and https
*/
-class SwitchProtocolRequestHandler implements IRequestHandlerDelegate
+class SwitchProtocolRequestHandler implements IRequestHandler
{
/** the protocol this request handler is going to switch to */
private final Protocol protocol;
- /** the original request handler */
- private final IRequestHandler handler;
-
private final HttpsConfig httpsConfig;
/**
@@ -48,23 +44,7 @@ class SwitchProtocolRequestHandler imple
* @param httpsConfig
* the https configuration
*/
- SwitchProtocolRequestHandler(Protocol protocol, HttpsConfig httpsConfig)
- {
- this(protocol, null, httpsConfig);
- }
-
- /**
- * Constructor
- *
- * @param protocol
- * required protocol
- * @param handler
- * target to redirect to, or {@code null} to replay the
current url
- * @param httpsConfig
- * the https configuration
- */
- SwitchProtocolRequestHandler(Protocol protocol, IRequestHandler handler,
- final HttpsConfig httpsConfig)
+ SwitchProtocolRequestHandler(Protocol protocol, final HttpsConfig
httpsConfig)
{
Args.notNull(protocol, "protocol");
Args.notNull(httpsConfig, "httpsConfig");
@@ -76,7 +56,6 @@ class SwitchProtocolRequestHandler imple
}
this.protocol = protocol;
- this.handler = handler;
this.httpsConfig = httpsConfig;
}
@@ -132,15 +111,7 @@ class SwitchProtocolRequestHandler imple
}
}
- final String url;
- if (handler == null)
- {
- url = getUrl(protocol.toString().toLowerCase(), port,
request);
- }
- else
- {
- url =
((RequestCycle)requestCycle).mapUrlFor(handler).toString();
- }
+ final String url = getUrl(protocol.toString().toLowerCase(),
port, request);
WebResponse response = (WebResponse)requestCycle.getResponse();
@@ -155,27 +126,9 @@ class SwitchProtocolRequestHandler imple
* required protocol
* @param httpsConfig
* the https configuration
- * @return request target or {@code null}
- */
- public static IRequestHandler requireProtocol(Protocol protocol, final
HttpsConfig httpsConfig)
- {
- return requireProtocol(protocol, null, httpsConfig);
- }
-
- /**
- * Returns a target that can be used to redirect to the specified
protocol. If no change is
- * required {@code null} will be returned.
- *
- * @param protocol
- * required protocol
- * @param handler
- * request target to redirect to or {@code null} to redirect
to current url
- * @param httpsConfig
- * the https configuration
* @return request handler or {@code null}
*/
- public static IRequestHandler requireProtocol(Protocol protocol,
IRequestHandler handler,
- final HttpsConfig httpsConfig)
+ public static IRequestHandler requireProtocol(Protocol protocol, final
HttpsConfig httpsConfig)
{
IRequestCycle requestCycle = RequestCycle.get();
WebRequest webRequest = (WebRequest)requestCycle.getRequest();
@@ -187,7 +140,7 @@ class SwitchProtocolRequestHandler imple
}
else
{
- return new SwitchProtocolRequestHandler(protocol,
handler, httpsConfig);
+ return new SwitchProtocolRequestHandler(protocol,
httpsConfig);
}
}
@@ -196,9 +149,12 @@ class SwitchProtocolRequestHandler imple
{
}
- /** {@inheritDoc} */
- public IRequestHandler getDelegateHandler()
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
{
- return handler;
+ return "SwitchProtocolRequestHandler";
}
}
Modified:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandlerTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandlerTest.java?rev=1151992&r1=1151991&r2=1151992&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandlerTest.java
(original)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/https/SwitchProtocolRequestHandlerTest.java
Thu Jul 28 20:40:16 2011
@@ -21,19 +21,15 @@ import java.net.URL;
import javax.servlet.http.HttpServletRequest;
-import org.apache.wicket.MockPage;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.apache.wicket.request.IRequestCycle;
-import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.mapper.AbstractMapperTest;
-import org.apache.wicket.request.mapper.IMapperContext;
-import org.apache.wicket.request.mapper.MountedMapper;
import org.mockito.Mockito;
/**
- * Test for SwitchProtocolRequestHandler
+ * Test for {@link SwitchProtocolRequestHandler}.
*/
public class SwitchProtocolRequestHandlerTest extends AbstractMapperTest
{
@@ -73,34 +69,4 @@ public class SwitchProtocolRequestHandle
Mockito.verify(webResponse).sendRedirect(httpsUrl.toString());
}
-
- /**
- * @see <a
href="https://issues.apache.org/jira/browse/WICKET-3380">WICKET-3380</a>
- */
- public void testMapHandler()
- {
- final MountedMapper encoder = new MountedMapper("/securedPage",
SecuredMockPage.class)
- {
- @Override
- protected IMapperContext getContext()
- {
- return context;
- }
- };
-
- Url originalUrl = Url.parse("securedPage");
- IRequestHandler handler =
encoder.mapRequest(getRequest(originalUrl));
-
- SwitchProtocolRequestHandler switchProtocolRequestHandler = new
SwitchProtocolRequestHandler(
- Protocol.HTTPS, handler, new HttpsConfig());
-
- Url mappedUrl =
encoder.mapHandler(switchProtocolRequestHandler);
- assertEquals(originalUrl, mappedUrl);
- }
-
- @RequireHttps
- private static class SecuredMockPage extends MockPage
- {
- private static final long serialVersionUID = 1L;
- }
}