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
if ( valueMap != null ) { 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) { 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.
final int protocolIndex = targetPath.indexOf(":/"); final int queryIndex = targetPath.indexOf('?'); if ( protocolIndex > -1 && (queryIndex == -1 || queryIndex > protocolIndex) ) { targetPath = "/".concat(targetPath);
targetPath = basePath.concat(targetPath);
basePath = basePath.concat(postFix);
Converts the absolute path target into a path relative to base and stores
this relative path into pathBuffer.
for (off = 0; off < (bParts.length - 1) && off < tParts.length
&& bParts[off].equals(tParts[off]); off++);
for (int i = bParts.length - off; i > 1; i--) { for (int i = off; i < tParts.length; i++) { if (jsonRendererServlet == null) { jsonRendererServlet = jrs;
return jsonRendererServlet;