// set default headers
response.addHeader("Cache-Control", "private, max-age=0");
response.addHeader("Server", ServerVersion.OPENCMIS_SERVER);
// create a context object, dispatch and handle exceptions
CallContext context = null;
try {
String method = request.getMethod();
if (METHOD_GET.equals(method)) {
request = new QueryStringHttpServletRequestWrapper(request);
} else if (METHOD_POST.equals(method)) {
request = new POSTHttpServletRequestWrapper(request, tempDir, memoryThreshold, maxContentSize, encrypt);
} else {
throw new CmisNotSupportedException("Unsupported method");
}
// invoke token handler, if necessary
if (request.getParameter("login") != null && callContextHandler instanceof TokenHandler) {
((TokenHandler) callContextHandler).service(getServletContext(), request, response);
return;
}
context = HttpUtils.createContext(request, response, getServletContext(), CallContext.BINDING_BROWSER,
CmisVersion.CMIS_1_1, callContextHandler, tempDir, memoryThreshold, maxContentSize, encrypt);
dispatch(context, request, response);
} catch (Exception e) {
if (e instanceof CmisPermissionDeniedException) {
if (context == null || context.getUsername() == null) {
response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
} else {
printError(e, request, response, context);
}