// Set access logging for this request
if (path.getDatabase() != null) {
String accessLoggingEnabled = (String) path.getDatabase().getAttribute(WGACore.DBATTRIB_ENABLE_ACCESSLOGGING);
if (accessLoggingEnabled != null) {
WGARequestInformation info = (WGARequestInformation) request.getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME);
if (info != null) {
info.setLoggingEnabled(Boolean.parseBoolean(accessLoggingEnabled));
}
}
}
int iPathType = path.getPathType();
// Treatment of special URL types
String dbKey = path.getDatabaseKey();
if (iPathType == WGPRequestPath.TYPE_INVALID) {
throw new HttpErrorException(404, "Invalid path: " + path.getBasePath(), dbKey);
}
if (iPathType == WGPRequestPath.TYPE_INVALID_DB) {
throw new HttpErrorException(404, "Specified database '" + dbKey + "' is unknown", null);
}
if (iPathType == WGPRequestPath.TYPE_UNKNOWN_CONTENT) {
sendNoContentNotification(path, request, response, path.getDatabase());
return;
}
if (iPathType == WGPRequestPath.TYPE_GOTO_HOMEPAGE) {
iPathType = determineHomepage(request, path, iPathType);
}
if (iPathType == WGPRequestPath.TYPE_UNAVAILABLE_DB) {
throw new HttpErrorException(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The website is currently unavailable", path.getDatabaseKey());
}
if (iPathType == WGPRequestPath.TYPE_UNDEFINED_HOMEPAGE) {
throw new HttpErrorException(HttpServletResponse.SC_NOT_FOUND, "No home page was defined for database '" + path.getDatabaseKey() + "'. Please specify an explicit content path.", path
.getDatabaseKey());
}
if (iPathType == WGPRequestPath.TYPE_TMLDEBUG) {
_tmlDebugger.performDebugMode(request, response, session);
return;
}
if (iPathType == WGPRequestPath.TYPE_JOBLOG) {
sendJobLog(request, response, session);
return;
}
if (iPathType == WGPRequestPath.TYPE_LOGOUT) {
WGDatabase db = (WGDatabase) _core.getContentdbs().get(dbKey);
String domain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN);
_core.logout(domain, session);
removeSessionCookie(response, request.getSession(), db);
iPathType = WGPRequestPath.TYPE_REDIRECT;
}
if (iPathType == WGPRequestPath.TYPE_FAVICON) {
String faviconPath = determineFavicon(request);
if (faviconPath != null) {
iPathType = WGPRequestPath.TYPE_REDIRECT;
path.setResourcePath(faviconPath);
}
else {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Favicon not defined");
return;
}
}
// Treatment of base URL Types
if (iPathType == WGPRequestPath.TYPE_REDIRECT) {
String url = path.getResourcePath();
if (path.appendQueryString() == true && request.getQueryString() != null && !request.getQueryString().equals("")) {
if (url.indexOf("?") != -1) {
url += "&" + request.getQueryString();
}
else {
url += "?" + request.getQueryString();
}
}
if (path.isPermanentRedirect()) {
sendPermanentRedirect(response, url);
}
else {
sendRedirect(response, url);
}
}
else if (iPathType != WGPRequestPath.TYPE_RESOURCE && iPathType != WGPRequestPath.TYPE_STATICTML && !_core.getContentdbs().containsKey(path.getDatabaseKey())) {
throw new HttpErrorException(404, "Database '" + dbKey + "' is unknown", null);
}
else {
String requestMethod = request.getMethod().toLowerCase();
switch (iPathType) {
case (WGPRequestPath.TYPE_TML):
case (WGPRequestPath.TYPE_TITLE_PATH):
if (path.isCompletePath() || !(requestMethod.equals("get") || requestMethod.equals("head"))) {
if (!path.isCompletePath()) {
_log.warn("Received " + request.getMethod() + " request to incomplete URL '" + path.getCompleteURL()
+ "' which cannot be redirected. Please use complete URLs on this HTTP method for consistent behaviour.");
}
dispatchTmlRequest(path, request, response, startDate);
}
else {
sendRedirect(response, path.expandToCompletePath(request));
}
break;
case (WGPRequestPath.TYPE_FILE):
dispatchFileRequest(path, request, response);
break;
case (WGPRequestPath.TYPE_CSS):
case (WGPRequestPath.TYPE_JS):
dispatchCssjsRequest(path, request, response);
break;
case (WGPRequestPath.TYPE_RESOURCE):
dispatchResourceRequest(path, request, response);
break;
case (WGPRequestPath.TYPE_STATICTML):
dispatchStaticTmlRequest(path, request, response);
break;
default:
throw new HttpErrorException(500, "Invalid url format", dbKey);
}
}
// moved from finally block to ensure errorpage can be displayed
commitResponse(response);
}
catch (HttpErrorException exc) {
request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc);
if (!response.isCommitted()) {
// throw exception to display errorpage - with senderror() the
// applicationserver use the buildin errorpage
if (exc.getCode() == HttpServletResponse.SC_NOT_FOUND || exc.getCode() == HttpServletResponse.SC_FORBIDDEN) {
_log.warn(exc.getLogMessage(request));
response.sendError(exc.getCode(), exc.getMessage());
}
else {
throw new ServletException(exc);
}
}
else {
_log.warn(exc.getLogMessage(request));
}
}
catch (SocketException exc) {
_log.warn("Socket Exception: " + exc.getMessage());
}
catch (Exception exc) {
_log.error("Exception in processing of request URL " + String.valueOf(request.getRequestURL()), exc);
request.setAttribute(WGACore.ATTRIB_EXCEPTION, exc);
throw new ServletException(exc);
}
catch (Error err) {
_log.error("Error in processing of request URL " + String.valueOf(request.getRequestURL()), err);
request.setAttribute(WGACore.ATTRIB_EXCEPTION, err);
throw new ServletException(err);
}
finally {
WGARequestInformation reqInfo = (WGARequestInformation) request.getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME);
if (reqInfo != null) {
reqInfo.setCommited(true);
}
}
}