use of com.developmentontheedge.be5.components.TemplateProcessor in project be5 by DevelopmentOnTheEdge.
the class MainServlet method runTemplateProcessor.
private void runTemplateProcessor(String componentId, Request req, Response res) {
if (UserInfoHolder.getUserInfo() == null) {
injector.get(UserHelper.class).initGuest(req);
}
try {
runRequestPreprocessors(componentId, req, res);
new TemplateProcessor(servletContext).generate(req, res, injector);
} catch (Be5Exception ex) {
if (ex.getCode().isInternal() || ex.getCode().isAccessDenied()) {
log.log(Level.SEVERE, ex.getMessage(), ex);
}
res.sendError(ex);
} catch (Throwable e) {
log.log(Level.SEVERE, e.getMessage(), e);
res.sendError(Be5Exception.internal(e));
}
}
use of com.developmentontheedge.be5.components.TemplateProcessor in project be5 by DevelopmentOnTheEdge.
the class MainServlet method respond.
/**
* The general routing method. Tries to determine and find a component using a given request URI.
* Generation of response is delegated to a found component.
*/
private boolean respond(HttpServletRequest request, HttpServletResponse response, String method, String requestUri, Map<String, String[]> parameters) {
String origin = request.getHeader("Origin");
// TODO test origin
response.addHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Allow-Origin", origin);
response.addHeader("Access-Control-Allow-Methods", "POST, GET");
response.addHeader("Access-Control-Max-Age", "1728000");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
Response res = new ResponseImpl(response);
Matcher matcher = uriPattern.matcher(requestUri);
if (!matcher.matches()) {
// This prevents triggering engine executions for resource URLs
// todo remove
log.log(Level.INFO, requestUri + " ContextPath=" + request.getContextPath());
String contextPath = request.getContextPath();
if (requestUri.startsWith(contextPath + (contextPath.endsWith("/") ? "" : "/") + "static/") || // || requestUri.startsWith("/static/")
requestUri.contains("favicon.ico")) {
return false;
}
String templateComponentID = "templateProcessor";
if (!injector.hasComponent(templateComponentID)) {
templateComponentID = "defaultTemplateProcessor";
}
RequestImpl req = new RequestImpl(request, requestUri, simplify(parameters));
UserInfoHolder.setRequest(req);
runTemplateProcessor(templateComponentID, req, res);
return true;
}
String[] uriParts = requestUri.split("/");
int ind = 1;
while (!"api".equals(uriParts[ind]) && ind + 1 < uriParts.length) {
ind++;
}
String subRequestUri = Joiner.on('/').join(Iterables.skip(Arrays.asList(uriParts), ind + 2));
String componentId = uriParts[ind + 1];
Request req = new RequestImpl(request, subRequestUri, simplify(parameters));
UserInfoHolder.setRequest(req);
runComponent(componentId, req, res);
return true;
}
Aggregations