package org.apache.sling.servlets.get.impl;
The
RedirectServlet implements support for GET requests to
resources of type
sling:redirect. This servlet tries to get the
redirect target by
- first adapting the resource to a
org.apache.sling.api.resource.ValueMap and trying to get the
property sling:target.
- The second attempt is to access the resource
sling:target
below the requested resource and attapt this to a string.
If there is no value found for sling:target a 404 (NOT FOUND)
status is sent by this servlet. Otherwise a 302 (FOUND, temporary redirect)
status is sent where the target is the relative URL from the current resource
to the target resource. Selectors, extension, suffix and query string are
also appended to the redirect URL.
- Scr.component:
- immediate="true" metatype="no"
- Scr.service:
- interface="javax.servlet.Servlet"
- Scr.property:
- name="service.description" value="Request Redirect Servlet"
- Scr.property:
- name="service.vendor" value="The Apache Software Foundation"
- Scr.property:
- name="sling.servlet.resourceTypes" value="sling:redirect"
- Scr.property:
- name="sling.servlet.methods" value="GET"
- Scr.property:
- name="sling.servlet.prefix" value="-1" type="Integer"
private="true"
The name of the target property
log.warn("RedirectServlet: Response is already committed, not redirecting"); "RedirectServlet: Response is already committed, not redirecting");
} else if (request.getAttribute(SlingConstants.ATTR_REQUEST_SERVLET) != null) { log.warn("RedirectServlet: Servlet is included, not redirecting"); "RedirectServlet: Servlet is included, not redirecting");
targetPath = valueMap.get(TARGET_PROP, String.class);
if (targetPath == null) { if (targetResource == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND,
"Missing target for redirection");
if (targetPath != null) { if (!isUrl(targetPath)) { response.sendError(HttpServletResponse.SC_NOT_FOUND,
"Cannot redirect to target resource " + targetPath);
Create a relative redirect URL for the targetPath relative to the given
request. The URL is relative to the request's resource and will include
the selectors, extension, suffix and query string of the request.
if (jsonRendererServlet == null) { jsonRendererServlet = jrs;
return jsonRendererServlet;
Returns
true if the path is potentially an URL. This
simplistic check looks for a ":/" string in the path assuming that this
is a separator to separate the scheme from the scheme-specific part. If
the separator occurs after a query separator ("?"), though, it is not
assumed to be a scheme-separator.
final int protocolIndex = path.indexOf(":/"); final int queryIndex = path.indexOf('?'); return protocolIndex > -1
&& (queryIndex == -1 || queryIndex > protocolIndex);