/** * Constructs a redirect url that should switch the user to the specified {@code scheme} * * @param handler * request handler being accessed * @param request * current request * @param scheme * desired scheme for the redirect url * @return url */ protected String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme) { HttpServletRequest req = (HttpServletRequest)request.getContainerRequest(); String url = scheme.urlName() + "://"; url += req.getServerName(); if (!scheme.usesStandardPort(config)) { url += ":" + scheme.getPort(config); } url += req.getRequestURI(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } return url; }
/** * @return scheme's url name */ public String urlName() { return name().toLowerCase(Locale.ROOT); }
/** * Creates a url for the handler. Modifies it with the correct {@link Scheme} if necessary. * * @param handler * @param request * @return url */ final Url mapHandler(IRequestHandler handler, Request request) { Url url = delegate.mapHandler(handler); Scheme desired = getDesiredSchemeFor(handler); Scheme current = getSchemeOf(request); if (!desired.isCompatibleWith(current)) { // the generated url does not have the correct scheme, set it (which in turn will cause // the url to be rendered in its full representation) url.setProtocol(desired.urlName()); url.setPort(desired.getPort(config)); } return url; }
private Url toHttps(Url url) { if (url != null) { url.setProtocol(Scheme.HTTPS.urlName()); } return url; }
@Override public final IRequestHandler mapRequest(Request request) { IRequestHandler handler = delegate.mapRequest(request); Scheme desired = getDesiredSchemeFor(handler); Scheme current = getSchemeOf(request); if (!desired.isCompatibleWith(current)) { // we are currently on the wrong scheme for this handler // construct a url for the handler on the correct scheme String url = createRedirectUrl(handler, request, desired); // replace handler with one that will redirect to the created url handler = createRedirectHandler(url); } return handler; }
/** * Creates a url for the handler. Modifies it with the correct {@link Scheme} if necessary. * * @param handler * @param request * @return url */ final Url mapHandler(IRequestHandler handler, Request request) { Url url = delegate.mapHandler(handler); Scheme desired = getDesiredSchemeFor(handler); Scheme current = getSchemeOf(request); if (!desired.isCompatibleWith(current)) { // the generated url does not have the correct scheme, set it (which in turn will cause // the url to be rendered in its full representation) url.setProtocol(desired.urlName()); url.setPort(desired.getPort(config)); } return url; }
private Url toHttps(Url url) { if (url != null) { url.setProtocol(Scheme.HTTPS.urlName()); } return url; }
@Override public final IRequestHandler mapRequest(Request request) { IRequestHandler handler = delegate.mapRequest(request); Scheme desired = getDesiredSchemeFor(handler); Scheme current = getSchemeOf(request); if (!desired.isCompatibleWith(current)) { // we are currently on the wrong scheme for this handler // construct a url for the handler on the correct scheme String url = createRedirectUrl(handler, request, desired); // replace handler with one that will redirect to the created url handler = createRedirectHandler(url); } return handler; }
/** * Constructs a redirect url that should switch the user to the specified {@code scheme} * * @param handler * request handler being accessed * @param request * current request * @param scheme * desired scheme for the redirect url * @return url */ protected String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme) { HttpServletRequest req = (HttpServletRequest)request.getContainerRequest(); String url = scheme.urlName() + "://"; url += req.getServerName(); if (!scheme.usesStandardPort(config)) { url += ":" + scheme.getPort(config); } url += req.getRequestURI(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } return url; }
/** * Gets the domain url. * * @param ssl * if the domain url is secure the scheme https will be added otherwise http * @param withServerPort * the with server port * @param withSlashAtTheEnd * the with slash at the end * @return the domain url */ public static String getDomainUrl(final boolean ssl, final boolean withServerPort, final boolean withSlashAtTheEnd) { return newDomainUrl(ssl ? Scheme.HTTPS.urlName() : Scheme.HTTP.urlName(), WicketUrlExtensions.getServerName(), WicketComponentExtensions.getHttpServletRequest().getServerPort(), withServerPort, withSlashAtTheEnd); }
if (!desired.isCompatibleWith(current)) {
/** * @return scheme's url name */ public String urlName() { return name().toLowerCase(Locale.ROOT); }
/** * Construts a redirect url that should switch the user to the specified * {@code scheme} * * @param handler * request handler being accessed * @param request * current request * @param scheme * desired scheme for the redirect url * @return url */ protected String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme) { HttpServletRequest req = (HttpServletRequest) ((WebRequest) request).getContainerRequest(); String url = scheme.urlName() + "://"; url += req.getServerName(); if (!scheme.usesStandardPort(config)) { url += ":" + scheme.getPort(config); } url += req.getRequestURI(); if (req.getQueryString() != null) { url += "?" + req.getQueryString(); } return url; }