diff --git a/source/net/yacy/http/Jetty8HttpServerImpl.java b/source/net/yacy/http/Jetty8HttpServerImpl.java index 141f55944..ee0d45d3a 100644 --- a/source/net/yacy/http/Jetty8HttpServerImpl.java +++ b/source/net/yacy/http/Jetty8HttpServerImpl.java @@ -32,19 +32,15 @@ import java.net.InetSocketAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.security.KeyStore; -import java.util.EnumSet; import java.util.Enumeration; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; -import javax.servlet.DispatcherType; - import net.yacy.cora.util.ConcurrentLog; import net.yacy.http.servlets.GSAsearchServlet; import net.yacy.http.servlets.SolrServlet; import net.yacy.http.servlets.YaCyDefaultServlet; import net.yacy.http.servlets.YaCyProxyServlet; -import net.yacy.http.servlets.SolrServlet.Servlet404; import net.yacy.search.Switchboard; import net.yacy.utils.PKCS12Tool; @@ -57,7 +53,6 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSelectChannelConnector; -import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -101,13 +96,6 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer { YacyDomainHandler domainHandler = new YacyDomainHandler(); domainHandler.setAlternativeResolver(sb.peers); - - //add SolrServlet - ServletContextHandler solrContext = new ServletContextHandler(ServletContextHandler.SESSIONS); - solrContext.setContextPath("/solr"); - solrContext.addServlet(new ServletHolder(Servlet404.class),"/*"); - - solrContext.addFilter(new FilterHolder(SolrServlet.class), "/*", EnumSet.of(DispatcherType.REQUEST)); // configure root context ServletContextHandler htrootContext = new ServletContextHandler(ServletContextHandler.SESSIONS); @@ -117,13 +105,14 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer { //sholder.setInitParameter("welcomeFile", "index.html"); // default is index.html, welcome.html htrootContext.addServlet(sholder,"/*"); + //add SolrServlet + htrootContext.addServlet(SolrServlet.class,"/solr/select"); + // add proxy?url= servlet - ServletHolder proxyholder= new ServletHolder(YaCyProxyServlet.class); - htrootContext.addServlet(proxyholder,"/proxy.html"); + htrootContext.addServlet(YaCyProxyServlet.class,"/proxy.html"); // add GSA servlet - ServletHolder gsaholder = new ServletHolder (GSAsearchServlet.class); - htrootContext.addServlet(gsaholder,"/gsa/search"); + htrootContext.addServlet(GSAsearchServlet.class,"/gsa/search"); // define list of YaCy specific general handlers HandlerList handlers = new HandlerList(); @@ -139,7 +128,6 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer { // 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(solrContext); allrequesthandlers.addHandler(htrootContext); allrequesthandlers.addHandler(new DefaultHandler()); // if not handled by other handler diff --git a/source/net/yacy/http/servlets/SolrServlet.java b/source/net/yacy/http/servlets/SolrServlet.java index 9122d06f6..57a7dc9e2 100644 --- a/source/net/yacy/http/servlets/SolrServlet.java +++ b/source/net/yacy/http/servlets/SolrServlet.java @@ -31,9 +31,6 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; @@ -81,8 +78,10 @@ import org.apache.solr.util.FastWriter; /* * taken from the Solr 3.6.0 code, which is now deprecated; * this is now done in Solr 4.x.x with org.apache.solr.servlet.SolrDispatchFilter + * implemented as servlet (we don't use multicore) */ -public class SolrServlet implements Filter { +public class SolrServlet extends HttpServlet { + private static final long serialVersionUID = 1L; public final static Map RESPONSE_WRITER = new HashMap(); static { @@ -102,50 +101,14 @@ public class SolrServlet implements Filter { RESPONSE_WRITER.put("gsa", new GSAResponseWriter()); } - public SolrServlet() { - } - - @Override - public void init(FilterConfig config) throws ServletException { - } - @Override - public void destroy() { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - - if (!(request instanceof HttpServletRequest)) { - if (chain != null) chain.doFilter(request, response); - return; - } + public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { HttpServletRequest hrequest = (HttpServletRequest) request; HttpServletResponse hresponse = (HttpServletResponse) response; SolrQueryRequest req = null; - // check if this servlet was called correctly - String pathInfo = hrequest.getPathInfo(); - String path = pathInfo == null ? hrequest.getServletPath() : hrequest.getServletPath() + pathInfo; // should be "/select" after this - - if (!EmbeddedSolrConnector.SELECT.equals(path)) { - // this is not for this servlet - if (chain != null) chain.doFilter(request, response); - return; - } - if (!EmbeddedSolrConnector.CONTEXT.equals(hrequest.getContextPath())) { - // this is not for this servlet - if (chain != null) chain.doFilter(request, response); - return; - } - - // reject POST which is not supported here final Method reqMethod = Method.getMethod(hrequest.getMethod()); - if (reqMethod == null || (reqMethod != Method.GET && reqMethod != Method.HEAD)) { - throw new ServletException("Unsupported method: " + hrequest.getMethod()); - } Writer out = null; try { @@ -263,15 +226,15 @@ public class SolrServlet implements Filter { if (Method.HEAD == reqMethod) { return; } - - // write response body - if (responseWriter instanceof BinaryResponseWriter) { - ((BinaryResponseWriter) responseWriter).write(response.getOutputStream(), req, rsp); - } else { - out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); - responseWriter.write(out, req, rsp); - out.flush(); - } + + // write response body + if (responseWriter instanceof BinaryResponseWriter) { + ((BinaryResponseWriter) responseWriter).write(response.getOutputStream(), req, rsp); + } else { + out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); + responseWriter.write(out, req, rsp); + out.flush(); + } } catch (final Throwable ex) { sendError(hresponse, ex);