Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
update Jetty server init() to activate yacy-domain and transparent proxy handler - adding domain & proxy handler to a context (as it was in inital design) (context required for dispatcher) - make handler context and servlet context parallel available (to allow use of YaCyDefaultServlet to handle legacyServlets) - set transparent proxy request handled after dispatch.forward to skip further handling for .yacy domain requests
reger272b196d05b8
diff --git a/source/net/yacy/http/HttpServer.java b/source/net/yacy/http/HttpServer.javaindex 2017f2290..2756922c6 100644--- a/source/net/yacy/http/HttpServer.java+++ b/source/net/yacy/http/HttpServer.java@@ -36,10 +36,10 @@ import net.yacy.search.Switchboard;import org.eclipse.jetty.server.Handler;import org.eclipse.jetty.server.Server;import org.eclipse.jetty.server.ServerConnector;+import org.eclipse.jetty.server.handler.ContextHandler;import org.eclipse.jetty.server.handler.ContextHandlerCollection;import org.eclipse.jetty.server.handler.DefaultHandler;import org.eclipse.jetty.server.handler.HandlerList;-import org.eclipse.jetty.server.handler.ResourceHandler;import org.eclipse.jetty.servlet.FilterHolder;import org.eclipse.jetty.servlet.ServletContextHandler;import org.eclipse.jetty.servlet.ServletHolder;@@ -67,11 +67,13 @@ public class HttpServer {YacyDomainHandler domainHandler = new YacyDomainHandler();domainHandler.setAlternativeResolver(sb.peers);+ /* this is now handled by YaCyDefaultServletResourceHandler resource_handler = new ResourceHandler();resource_handler.setDirectoriesListed(true);resource_handler.setWelcomeFiles(new String[]{"index.html"});resource_handler.setResourceBase("htroot/");-+ */+//add SolrServletServletContextHandler solrContext = new ServletContextHandler(ServletContextHandler.SESSIONS);solrContext.setContextPath("/solr");@@ -88,20 +90,35 @@ public class HttpServer {htrootContext.addServlet(sholder,"/*");//htrootContext.setInitParameter("welcomeFile", "index.html"); // default is index.html, welcome.html+ // assemble the servlet handlersContextHandlerCollection servletContext = new ContextHandlerCollection();servletContext.setHandlers(new Handler[] { solrContext, htrootContext });+ // define list of YaCy specific general handlersHandlerList handlers = new HandlerList();handlers.setHandlers(new Handler[]- {domainHandler, new ProxyCacheHandler(), new ProxyHandler(),- servletContext, resource_handler, new DefaultHandler()});-+ {domainHandler, new ProxyCacheHandler(), new ProxyHandler()+ /*, resource_handler, new DefaultHandler() */});++ // context handler for dispatcher and security (hint: dispatcher requires a context)+ ContextHandler context = new ContextHandler();+ context.setContextPath("/");+ context.setHandler(handlers);++ // make YaCy handlers (in context) and servlet context handlers available (both contain root context "/")+ // logic: 1. YaCy handlers are called if request not handled (e.g. proxy) then servlets handle it+ ContextHandlerCollection allrequesthandlers = new ContextHandlerCollection();+ allrequesthandlers.addHandler(context);+ allrequesthandlers.addHandler(servletContext);+ allrequesthandlers.addHandler(new DefaultHandler()); // if not handled by other handler++ // wrap all handlers by security handlerYaCySecurityHandler securityHandler = new YaCySecurityHandler();securityHandler.setLoginService(new YaCyLoginService());securityHandler.setRealmName("YaCy Admin Interface");- securityHandler.setHandler(new CrashProtectionHandler(handlers));-- server.setHandler(securityHandler);+ securityHandler.setHandler(new CrashProtectionHandler(allrequesthandlers));++ server.setHandler(/*securityHandler*/allrequesthandlers);}/**diff --git a/source/net/yacy/http/YacyDomainHandler.java b/source/net/yacy/http/YacyDomainHandler.javaindex 5fc870c61..b13cd1d41 100644--- a/source/net/yacy/http/YacyDomainHandler.java+++ b/source/net/yacy/http/YacyDomainHandler.java@@ -62,9 +62,10 @@ public class YacyDomainHandler extends AbstractHandler implements Handler {int posPort = hostPort.lastIndexOf(':');String newHost = hostPort.substring(0, posPort);int newPort = Integer.parseInt(hostPort.substring(posPort + 1));-- RequestDispatcher dispatcher = request.getRequestDispatcher(path + target);++ RequestDispatcher dispatcher = request.getRequestDispatcher(path + target);dispatcher.forward(new DomainRequestWrapper(request, newHost, newPort), response);+ baseRequest.setHandled(true);}}@@ -89,6 +90,12 @@ public class YacyDomainHandler extends AbstractHandler implements Handler {return newServerPort;}+ @Override+ public StringBuffer getRequestURL() {+ StringBuffer buf = new StringBuffer(this.getScheme() +"://"+ newServerName + ":" + newServerPort + this.getPathInfo());+ return buf;+ }+@Overridepublic String getHeader(String name) {if(name.equals("Host")) {