in src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java [267:307]
private void includeResource(
SlingHttpServletRequest request,
final Bindings bindings,
PrintWriter out,
Resource includeRes,
RequestDispatcherOptions requestDispatcherOptions) {
if (includeRes == null) {
throw new SightlyException("Resource cannot be null");
} else {
if (request.getResource().getPath().equals(includeRes.getPath())) {
String requestSelectorString = request.getRequestPathInfo().getSelectorString();
String requestDispatcherAddSelectors = requestDispatcherOptions.getAddSelectors();
if ((requestSelectorString == null
? requestDispatcherAddSelectors == null
: requestSelectorString.equals(requestDispatcherAddSelectors))
&& StringUtils.EMPTY.equals(requestDispatcherOptions.getReplaceSelectors())
&& (requestDispatcherOptions.getForceResourceType() == null
|| requestDispatcherOptions
.getForceResourceType()
.equals(request.getResource().getResourceType()))) {
LOGGER.warn(
"Will not include resource {} since this will lead to a {} exception.",
includeRes.getPath(),
"org.apache.sling.api.request.RecursionTooDeepException");
return;
}
}
SlingHttpServletResponse customResponse =
new PrintWriterResponseWrapper(out, BindingsUtils.getResponse(bindings));
RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, requestDispatcherOptions);
try {
if (dispatcher != null) {
dispatcher.include(request, customResponse);
} else {
throw new SightlyException("Failed to include resource " + includeRes.getPath());
}
} catch (Exception e) {
throw new SightlyException("Failed to include resource " + includeRes.getPath(), e);
}
}
}