implement a YaCyDefaultServlet to handle YaCy-servlets within Jetty server

- the implementation is inspired by Jetty's DefaultServlet
- handles static html content and YaCy servlets
- translates between standard servlet request/response and YaCy request/response specification
With the implementation of YaCy-servlets as servlet instead via a jetty handler it's closer to servlet standard and carries less jetty specific dependencies.
pull/1/head
reger 12 years ago
parent 9619b8743c
commit 4b77733e59

@ -9,7 +9,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer; import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.HandlerWrapper;

@ -36,7 +36,6 @@ import net.yacy.search.Switchboard;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector; 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.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.HandlerList;
@ -57,13 +56,14 @@ public class HttpServer {
*/ */
public HttpServer(int port) { public HttpServer(int port) {
Switchboard sb = Switchboard.getSwitchboard(); Switchboard sb = Switchboard.getSwitchboard();
server = new Server(); server = new Server();
ServerConnector connector = new ServerConnector(server); ServerConnector connector = new ServerConnector(server);
connector.setPort(port); connector.setPort(port);
connector.setName("httpd:"+Integer.toString(port)); connector.setName("httpd:"+Integer.toString(port));
//connector.setThreadPool(new QueuedThreadPool(20)); //connector.setThreadPool(new QueuedThreadPool(20));
server.addConnector(connector); server.addConnector(connector);
YacyDomainHandler domainHandler = new YacyDomainHandler(); YacyDomainHandler domainHandler = new YacyDomainHandler();
domainHandler.setAlternativeResolver(sb.peers); domainHandler.setAlternativeResolver(sb.peers);
@ -71,11 +71,28 @@ public class HttpServer {
resource_handler.setDirectoriesListed(true); resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[]{"index.html"}); resource_handler.setWelcomeFiles(new String[]{"index.html"});
resource_handler.setResourceBase("htroot/"); resource_handler.setResourceBase("htroot/");
//add SolrServlet
ServletContextHandler solrContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
solrContext.setContextPath("/solr/");
solrContext.addServlet(new ServletHolder(Servlet404.class),"/*");
SolrServlet.initCore(sb.index.fulltext().getDefaultEmbeddedConnector());
solrContext.addFilter(new FilterHolder(SolrServlet.class), "/*", EnumSet.of(DispatcherType.REQUEST));
ServletContextHandler htrootContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
htrootContext.setContextPath("/");
ServletHolder sholder = new ServletHolder(YaCyDefaultServlet.class);
sholder.setInitParameter("resourceBase", "htroot");
htrootContext.addServlet(sholder,"/*");
ContextHandlerCollection servletContext = new ContextHandlerCollection();
servletContext.setHandlers(new Handler[] { solrContext, htrootContext });
HandlerList handlers = new HandlerList(); HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] handlers.setHandlers(new Handler[]
{domainHandler, new ProxyCacheHandler(), new ProxyHandler(), {domainHandler, new ProxyCacheHandler(), new ProxyHandler(),
new RewriteHandler(), new SSIHandler(new TemplateHandler()), new RewriteHandler(), servletContext,
resource_handler, new DefaultHandler()}); resource_handler, new DefaultHandler()});
YaCySecurityHandler securityHandler = new YaCySecurityHandler(); YaCySecurityHandler securityHandler = new YaCySecurityHandler();
@ -83,23 +100,8 @@ public class HttpServer {
securityHandler.setRealmName("YaCy Admin Interface"); securityHandler.setRealmName("YaCy Admin Interface");
securityHandler.setHandler(new CrashProtectionHandler(handlers)); securityHandler.setHandler(new CrashProtectionHandler(handlers));
// context handler for dispatcher and security securityHandler.setHandler(new CrashProtectionHandler(servletContext));
ContextHandler context = new ContextHandler(); server.setHandler(securityHandler);
context.setContextPath("/");
context.setHandler(securityHandler);
//add SolrServlet
ServletContextHandler servletcontext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletcontext.setContextPath("/solr/");
servletcontext.addServlet(new ServletHolder(Servlet404.class),"/*");
SolrServlet.initCore(sb.index.fulltext().getDefaultEmbeddedConnector());
servletcontext.addFilter(new FilterHolder(SolrServlet.class), "/*", EnumSet.of(DispatcherType.REQUEST));
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { context, servletcontext });
server.setHandler(contexts);
} }
/** /**

@ -93,7 +93,7 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
proxyHeaders.remove(RequestHeader.KEEP_ALIVE); proxyHeaders.remove(RequestHeader.KEEP_ALIVE);
proxyHeaders.remove(RequestHeader.CONTENT_LENGTH); proxyHeaders.remove(RequestHeader.CONTENT_LENGTH);
final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent); final HTTPClient client = new HTTPClient(ClientIdentification.yacyProxyAgent);
int timeout = 60000; int timeout = 60000;
client.setTimout(timeout); client.setTimout(timeout);
client.setHeader(proxyHeaders.entrySet()); client.setHeader(proxyHeaders.entrySet());
@ -101,7 +101,7 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
// send request // send request
try { try {
String queryString = request.getQueryString()!=null ? "?" + request.getQueryString() : ""; String queryString = request.getQueryString()!=null ? "?" + request.getQueryString() : "";
String url = request.getRequestURL().toString() + queryString; String url = request.getRequestURL().toString() + queryString;
if (request.getMethod().equals("GET")) { if (request.getMethod().equals("GET")) {
client.GET(url); client.GET(url);
} else if (request.getMethod().equals("POST")) { } else if (request.getMethod().equals("POST")) {

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save