use of javax.servlet.Servlet in project sling by apache.
the class RequestData method initServlet.
public void initServlet(final Resource resource, final ServletResolver sr) {
// the resource and the request path info, will never be null
RequestPathInfo requestPathInfo = new SlingRequestPathInfo(resource);
ContentData contentData = setContent(resource, requestPathInfo);
requestProgressTracker.log("Resource Path Info: {0}", requestPathInfo);
// finally resolve the servlet for the resource
requestProgressTracker.startTimer("ServletResolution");
Servlet servlet = sr.resolveServlet(slingRequest);
requestProgressTracker.logTimer("ServletResolution", "URI={0} handled by Servlet={1}", getServletRequest().getRequestURI(), (servlet == null ? "-none-" : RequestUtil.getServletName(servlet)));
contentData.setServlet(servlet);
}
use of javax.servlet.Servlet in project sling by apache.
the class CallTag method doEndTag.
@Override
public int doEndTag() throws JspException {
final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
final SlingScriptHelper scriptHelper = bindings.getSling();
final ServletResolver servletResolver = scriptHelper.getService(ServletResolver.class);
final RequestProgressTracker tracker = TagUtil.getRequest(pageContext).getRequestProgressTracker();
String servletName = null;
final Servlet servlet;
if (!ignoreComponentHierarchy) {
final Resource resource = bindings.getResource();
servlet = servletResolver.resolveServlet(resource, this.script);
if (servlet != null) {
servletName = RequestUtil.getServletName(servlet);
tracker.log("Including script {0} for path={1}, type={2}: {3}", script, resource.getPath(), resource.getResourceType(), servletName);
}
} else {
final ResourceResolver resolver = bindings.getRequest().getResourceResolver();
final String scriptPath;
if (!script.startsWith("/")) {
// resolve relative script
String parentPath = ResourceUtil.getParent(scriptHelper.getScript().getScriptResource().getPath());
// check if parent resides on search path
for (String sp : resolver.getSearchPath()) {
if (parentPath.startsWith(sp)) {
parentPath = parentPath.substring(sp.length());
break;
}
}
scriptPath = parentPath + "/" + script;
} else {
scriptPath = this.script;
}
servlet = servletResolver.resolveServlet(resolver, scriptPath);
if (servlet != null) {
servletName = RequestUtil.getServletName(servlet);
tracker.log("Including script {0} (ignoring component hierarchy): {1}", script, servletName);
}
}
if (servlet == null) {
throw new JspException("Could not find script " + script);
}
try {
if (flush && !(pageContext.getOut() instanceof BodyContent)) {
// might throw an IOException of course
pageContext.getOut().flush();
}
// wrap the response to get the correct output order
SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(pageContext);
tracker.startTimer(servletName);
servlet.service(pageContext.getRequest(), response);
tracker.logTimer(servletName);
return EVAL_PAGE;
} catch (Exception e) {
throw new JspException("Error while executing script " + script, e);
}
}
use of javax.servlet.Servlet in project sling by apache.
the class DefaultGetServlet method destroy.
@Override
public void destroy() {
for (Servlet servlet : rendererMap.values()) {
try {
servlet.destroy();
} catch (Throwable t) {
logger.error("Error while destroying servlet " + servlet, t);
}
}
streamerServlet = null;
rendererMap.clear();
super.destroy();
}
use of javax.servlet.Servlet in project sling by apache.
the class DefaultGetServlet method init.
@Override
public void init() throws ServletException {
super.init();
// use the servlet for rendering StreamRendererServlet.EXT_RES as the
// streamer servlet
streamerServlet = getDefaultRendererServlet(StreamRendererServlet.EXT_RES);
// Register renderer servlets
rendererMap.put(StreamRendererServlet.EXT_RES, streamerServlet);
if (enableHtml) {
rendererMap.put(HtmlRendererServlet.EXT_HTML, getDefaultRendererServlet(HtmlRendererServlet.EXT_HTML));
}
if (enableTxt) {
rendererMap.put(PlainTextRendererServlet.EXT_TXT, getDefaultRendererServlet(PlainTextRendererServlet.EXT_TXT));
}
if (enableJson) {
rendererMap.put(JsonRendererServlet.EXT_JSON, getDefaultRendererServlet(JsonRendererServlet.EXT_JSON));
}
if (enableXml) {
rendererMap.put(XMLRendererServlet.EXT_XML, getDefaultRendererServlet(XMLRendererServlet.EXT_XML));
}
// check additional aliases
if (this.aliases != null) {
for (final String m : aliases) {
final int pos = m.indexOf(':');
if (pos != -1) {
final String type = m.substring(0, pos);
Servlet servlet = rendererMap.get(type);
if (servlet == null) {
servlet = getDefaultRendererServlet(type);
}
if (servlet != null) {
final String extensions = m.substring(pos + 1);
final StringTokenizer st = new StringTokenizer(extensions, ",");
while (st.hasMoreTokens()) {
final String ext = st.nextToken();
rendererMap.put(ext, servlet);
}
} else {
logger.warn("Unable to enable renderer alias(es) for {} - type not supported", m);
}
}
}
}
}
use of javax.servlet.Servlet in project sling by apache.
the class RedirectServlet method getJsonRendererServlet.
private Servlet getJsonRendererServlet() {
if (jsonRendererServlet == null) {
Servlet jrs = new JsonRendererServlet(jsonMaximumResults);
try {
jrs.init(getServletConfig());
} catch (Exception e) {
// don't care too much here
}
jsonRendererServlet = jrs;
}
return jsonRendererServlet;
}
Aggregations