package org.argeo.cms.internal.kernel;
import java.io.IOException;
-import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
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(boolean cleanState) {
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);
}
}
private String httpPortsMsg(Object httpPort, Object httpsPort) {
- return "HTTP " + httpPort + (httpsPort != null ? " - HTTPS " + httpsPort : "");
+ return (httpPort != null ? "HTTP " + httpPort + " " : " ")
+ + (httpsPort != null ? "HTTPS " + httpsPort : "");
}
}
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
- // request.setCharacterEncoding("US-ASCII");
- System.out.println("## DEFAULT CHARSET: " + Charset.defaultCharset());
- System.out.println("## Request CHARSET: " + request.getCharacterEncoding());
-
if (log.isTraceEnabled())
HttpUtils.logRequest(log, request);
RemotingServlet.super.service(request, response);