/** * Constructor * * @param protocol * required protocol * @param target * target to redirect to, or {@code null} to replay the current url */ public SwitchProtocolRequestTarget(Protocol protocol, IRequestTarget target) { if (protocol == null) { throw new IllegalArgumentException("Argument 'protocol' may not be null."); } if (protocol == Protocol.PRESERVE_CURRENT) { throw new IllegalArgumentException("Argument 'protocol' may not have value '" + Protocol.PRESERVE_CURRENT.toString() + "'."); } this.protocol = protocol; this.target = target; }
if (target == null) url = getUrl(protocol.toString().toLowerCase(), port, request);
/** * Returns a target that can be used to redirect to the specified protocol. If no change is * required null will be returned. * * @param protocol * required protocol * @param target * request target to redirect to or {@code null} to redirect to current url * @return request target or null */ public static IRequestTarget requireProtocol(Protocol protocol, IRequestTarget target) { RequestCycle requestCycle = RequestCycle.get(); WebRequest webRequest = (WebRequest)requestCycle.getRequest(); HttpServletRequest request = webRequest.getHttpServletRequest(); if (protocol == null || protocol == Protocol.PRESERVE_CURRENT || request.getScheme().equals(protocol.toString().toLowerCase())) { return null; } else { return new SwitchProtocolRequestTarget(protocol, target); } } }