private ServiceTracker<Repository, Repository> repositories;
private final ServiceTracker<HttpService, HttpService> httpServiceTracker;
- private static String httpRealm = "Argeo";
+ private String httpRealm = "Argeo";
+ private String webDavConfig = HttpUtils.WEBDAV_CONFIG;
+ private final boolean cleanState;
- public NodeHttp() {
+ public NodeHttp(boolean cleanState) {
+ this.cleanState = cleanState;
httpServiceTracker = new PrepareHttpStc();
// httpServiceTracker.open();
KernelUtils.asyncOpen(httpServiceTracker);
repositories.close();
}
- public static void registerRepositoryServlets(HttpService httpService, String alias, Repository repository) {
+ public void registerRepositoryServlets(HttpService httpService, String alias, Repository repository) {
if (httpService == null)
throw new CmsException("No HTTP service available");
try {
registerRemotingServlet(httpService, alias, repository);
if (NodeConstants.HOME.equals(alias))
registerFilesServlet(httpService, alias, repository);
- if (log.isDebugEnabled())
- log.debug("Registered servlets for repository '" + alias + "'");
+ if (log.isTraceEnabled())
+ log.trace("Registered servlets for repository '" + alias + "'");
} catch (Exception e) {
throw new CmsException("Could not register servlets for repository '" + alias + "'", e);
}
httpService.unregister(remotingPath(alias));
if (NodeConstants.HOME.equals(alias))
httpService.unregister(filesPath(alias));
- if (log.isDebugEnabled())
- log.debug("Unregistered servlets for repository '" + alias + "'");
+ if (log.isTraceEnabled())
+ log.trace("Unregistered servlets for repository '" + alias + "'");
} catch (Exception e) {
log.error("Could not unregister servlets for repository '" + alias + "'", e);
}
}
- static void registerWebdavServlet(HttpService httpService, String alias, Repository repository)
+ void registerWebdavServlet(HttpService httpService, String alias, Repository repository)
throws NamespaceException, ServletException {
// WebdavServlet webdavServlet = new WebdavServlet(repository, new
// OpenInViewSessionProvider(alias));
WebdavServlet webdavServlet = new WebdavServlet(repository, new CmsSessionProvider(alias));
String path = webdavPath(alias);
Properties ip = new Properties();
- ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_CONFIG, HttpUtils.WEBDAV_CONFIG);
+ ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_CONFIG, webDavConfig);
ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, path);
httpService.registerServlet(path, webdavServlet, ip, new DataHttpContext(httpRealm));
}
- static void registerFilesServlet(HttpService httpService, String alias, Repository repository)
+ void registerFilesServlet(HttpService httpService, String alias, Repository repository)
throws NamespaceException, ServletException {
WebdavServlet filesServlet = new WebdavServlet(repository, new CmsSessionProvider(alias));
String path = filesPath(alias);
Properties ip = new Properties();
- ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_CONFIG, HttpUtils.WEBDAV_CONFIG);
+ ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_CONFIG, webDavConfig);
ip.setProperty(WebdavServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, path);
httpService.registerServlet(path, filesServlet, ip, new PrivateHttpContext(httpRealm, true));
}
- static void registerRemotingServlet(HttpService httpService, String alias, Repository repository)
+ void registerRemotingServlet(HttpService httpService, String alias, Repository repository)
throws NamespaceException, ServletException {
RemotingServlet remotingServlet = new RemotingServlet(repository, new CmsSessionProvider(alias));
String path = remotingPath(alias);
return NodeConstants.PATH_FILES;
}
- // private Subject subjectFromRequest(HttpServletRequest request,
- // HttpServletResponse response) {
- // Authorization authorization = (Authorization)
- // request.getAttribute(HttpContext.AUTHORIZATION);
- // if (authorization == null)
- // throw new CmsException("Not authenticated");
- // try {
- // LoginContext lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER,
- // new HttpRequestCallbackHandler(request, response));
- // lc.login();
- // return lc.getSubject();
- // } catch (LoginException e) {
- // throw new CmsException("Cannot login", e);
- // }
- // }
-
- static class RepositoriesStc extends ServiceTracker<Repository, Repository> {
+ class RepositoriesStc extends ServiceTracker<Repository, Repository> {
private final HttpService httpService;
private final BundleContext bc;
}
private class PrepareHttpStc extends ServiceTracker<HttpService, HttpService> {
- // private DataHttp dataHttp;
- // private NodeHttp nodeHttp;
-
public PrepareHttpStc() {
super(bc, HttpService.class, null);
}
@Override
public void removedService(ServiceReference<HttpService> reference, HttpService service) {
- // if (dataHttp != null)
- // dataHttp.destroy();
- // dataHttp = null;
- // if (nodeHttp != null)
- // nodeHttp.destroy();
- // nodeHttp = null;
- // destroy();
repositories.close();
repositories = null;
}
try {
httpService.registerServlet("/!", new LinkServlet(), null, null);
httpService.registerServlet("/robots.txt", new RobotServlet(), null, null);
+ // httpService.registerServlet("/html", new HtmlServlet(), null, null);
} catch (Exception e) {
throw new CmsException("Cannot register filters", e);
}
throw new CmsException("An http service is already configured");
repositories = new RepositoriesStc(bc, httpService);
// repositories.open();
- KernelUtils.asyncOpen(repositories);
+ if (cleanState)
+ KernelUtils.asyncOpen(repositories);
log.info(httpPortsMsg(httpPort, httpsPort));
// httpAvailable = true;
// checkReadiness();
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
- // try {
- // Subject subject = subjectFromRequest(request, response);
- // Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
- // @Override
- // public Void run() throws Exception {
if (log.isTraceEnabled())
HttpUtils.logRequest(log, request);
RemotingServlet.super.service(request, response);
- // return null;
- // }
- // });
- // } catch (PrivilegedActionException e) {
- // throw new CmsException("Cannot process JCR remoting request",
- // e.getException());
- // }
}
}