remove unused options and attributes from DefaultServlet

cleanup obsolete class files
pull/1/head
reger 11 years ago
parent b1dc9a6f52
commit 444a9ae674

@ -44,12 +44,9 @@ import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.WriterOutputStream;
import org.eclipse.jetty.server.AbstractHttpConnection;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.InclusiveByteRange;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.nio.NIOConnector;
import org.eclipse.jetty.server.ssl.SslConnector;
import org.eclipse.jetty.util.MultiPartOutputStream;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.URIUtil;
@ -78,9 +75,6 @@ import org.eclipse.jetty.util.resource.Resource;
*
* resourceBase Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
@ -129,9 +123,9 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
String pathInContext = URIUtil.addPaths(servletPath, pathInfo);
boolean endsWithSlash = (pathInfo == null ? request.getServletPath() : pathInfo).endsWith(URIUtil.SLASH);
// Find the resource and content
// Find the resource
Resource resource = null;
HttpContent content = null;
try {
// find resource
resource = getResource(pathInContext);
@ -151,7 +145,7 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
}
if (ConcurrentLog.isFine("FILEHANDLER")) {
ConcurrentLog.fine("FILEHANDLER","YaCyDefaultServlet: uri=" + request.getRequestURI() + " resource=" + resource + (content != null ? " content" : ""));
ConcurrentLog.fine("FILEHANDLER","YaCyDefaultServlet: uri=" + request.getRequestURI() + " resource=" + resource);
}
// Handle resource
@ -169,23 +163,18 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
}
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(_servletContext.getContextPath(), pathInContext)));
} else {
// ensure we have content
if (content == null) {
content = new HttpContent.ResourceAsHttpContent(resource, _mimeTypes.getMimeByExtension(resource.toString()), response.getBufferSize(), _etags);
}
if (hasClass) { // this is a YaCy servlet, handle the template
handleTemplate(pathInfo, request, response);
} else {
if (included || passConditionalHeaders(request, response, resource, content)) {
sendData(request, response, included, resource, content, reqRanges);
if (included || passConditionalHeaders(request, response, resource)) {
sendData(request, response, included, resource, reqRanges);
}
}
}
} else {
String welcome = null;
} else { // resource is directory
String welcome;
if (!endsWithSlash || (pathInContext.length() == 1 && request.getAttribute("org.eclipse.jetty.server.nullPathInfo") != null)) {
if (!endsWithSlash || (pathInContext.length() == 1)) {
StringBuffer buf = request.getRequestURL();
synchronized (buf) {
int param = buf.lastIndexOf(";");
@ -212,13 +201,11 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
if (included) {
dispatcher.include(request, response);
} else {
request.setAttribute("org.eclipse.jetty.server.welcome", welcome);
dispatcher.forward(request, response);
}
}
} else {
content = new HttpContent.ResourceAsHttpContent(resource, _mimeTypes.getMimeByExtension(resource.toString()), _etags);
if (included || passConditionalHeaders(request, response, resource, content)) {
if (included || passConditionalHeaders(request, response, resource)) {
sendDirectory(request, response, resource, pathInContext);
}
}
@ -229,9 +216,7 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
response.sendError(500, e.getMessage());
}
} finally {
if (content != null) {
content.release();
} else if (resource != null) {
if (resource != null) {
resource.release();
}
}
@ -241,69 +226,11 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
/* Check modification date headers.
*/
@Override
protected boolean passConditionalHeaders(HttpServletRequest request, HttpServletResponse response, Resource resource, HttpContent content)
protected boolean passConditionalHeaders(HttpServletRequest request, HttpServletResponse response, Resource resource)
throws IOException {
try {
if (!request.getMethod().equals(HttpMethods.HEAD)) {
if (_etags) {
String ifm = request.getHeader(HttpHeaders.IF_MATCH);
if (ifm != null) {
boolean match = false;
if (content != null && content.getETag() != null) {
QuotedStringTokenizer quoted = new QuotedStringTokenizer(ifm, ", ", false, true);
while (!match && quoted.hasMoreTokens()) {
String tag = quoted.nextToken();
if (content.getETag().toString().equals(tag)) {
match = true;
}
}
}
if (!match) {
Response r = Response.getResponse(response);
r.reset(true);
r.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
return false;
}
}
String ifnm = request.getHeader(HttpHeaders.IF_NONE_MATCH);
if (ifnm != null && content != null && content.getETag() != null) {
// Look for GzipFiltered version of etag
if (content.getETag().toString().equals(request.getAttribute("o.e.j.s.GzipFilter.ETag"))) {
Response r = Response.getResponse(response);
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
r.getHttpFields().put(HttpHeaders.ETAG_BUFFER, ifnm);
return false;
}
// Handle special case of exact match.
if (content.getETag().toString().equals(ifnm)) {
Response r = Response.getResponse(response);
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
r.getHttpFields().put(HttpHeaders.ETAG_BUFFER, content.getETag());
return false;
}
// Handle list of tags
QuotedStringTokenizer quoted = new QuotedStringTokenizer(ifnm, ", ", false, true);
while (quoted.hasMoreTokens()) {
String tag = quoted.nextToken();
if (content.getETag().toString().equals(tag)) {
Response r = Response.getResponse(response);
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
r.getHttpFields().put(HttpHeaders.ETAG_BUFFER, content.getETag());
return false;
}
}
return true;
}
}
HttpContent content = new HttpContent.ResourceAsHttpContent(resource, _mimeTypes.getMimeByExtension(resource.toString()), response.getBufferSize());
String ifms = request.getHeader(HttpHeaders.IF_MODIFIED_SINCE);
if (ifms != null) {
@ -316,9 +243,6 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
if (ifms.equals(mdlm.toString())) {
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
if (_etags) {
r.getHttpFields().add(HttpHeaders.ETAG_BUFFER, content.getETag());
}
r.flushBuffer();
return false;
}
@ -330,9 +254,6 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
if (resource.lastModified() / 1000 <= ifmsl / 1000) {
r.reset(true);
r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
if (_etags) {
r.getHttpFields().add(HttpHeaders.ETAG_BUFFER, content.getETag());
}
r.flushBuffer();
return false;
}
@ -348,7 +269,7 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
return false;
}
}
if (content != null) content.release();
}
} catch (IllegalArgumentException iae) {
if (!response.isCommitted()) {
@ -365,19 +286,10 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
HttpServletResponse response,
boolean include,
Resource resource,
HttpContent content,
Enumeration reqRanges)
throws IOException {
boolean direct;
long content_length;
if (content == null) {
direct = false;
content_length = resource.length();
} else {
Connector connector = AbstractHttpConnection.getCurrentConnection().getConnector();
direct = connector instanceof NIOConnector && ((NIOConnector) connector).getUseDirectBuffers() && !(connector instanceof SslConnector);
content_length = content.getContentLength();
}
final long content_length = resource.length();
// Get the output stream (or writer)
OutputStream out;
@ -399,33 +311,8 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
if (include) {
resource.writeTo(out, 0, content_length);
} else {
// See if a direct methods can be used?
if (content != null && !written && out instanceof HttpOutput) {
if (response instanceof Response) {
writeOptionHeaders(response);
((AbstractHttpConnection.Output) out).sendContent(content);
} else {
Buffer buffer = direct ? content.getDirectBuffer() : content.getIndirectBuffer();
if (buffer != null) {
writeHeaders(response, content, content_length);
((AbstractHttpConnection.Output) out).sendContent(buffer);
} else {
writeHeaders(response, content, content_length);
resource.writeTo(out, 0, content_length);
}
}
} else {
// Write headers normally
writeHeaders(response, content, written ? -1 : content_length);
// Write content normally
Buffer buffer = (content == null) ? null : content.getIndirectBuffer();
if (buffer != null) {
buffer.writeTo(out);
} else {
resource.writeTo(out, 0, content_length);
}
}
writeHeaders(response, resource, written ? -1 : content_length);
resource.writeTo(out, 0, content_length);
}
} else {
// Parse the satisfiable ranges
@ -433,7 +320,7 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
// if there are no satisfiable ranges, send 416 response
if (ranges == null || ranges.size() == 0) {
writeHeaders(response, content, content_length);
writeHeaders(response, resource, content_length);
response.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
response.setHeader(HttpHeaders.CONTENT_RANGE,
InclusiveByteRange.to416HeaderRangeString(content_length));
@ -447,7 +334,7 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
InclusiveByteRange singleSatisfiableRange =
(InclusiveByteRange) ranges.get(0);
long singleLength = singleSatisfiableRange.getSize(content_length);
writeHeaders(response, content, singleLength);
writeHeaders(response, resource, singleLength);
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
response.setHeader(HttpHeaders.CONTENT_RANGE,
singleSatisfiableRange.toHeaderRangeString(content_length));
@ -459,8 +346,8 @@ public class Jetty8YaCyDefaultServlet extends YaCyDefaultServlet {
// 216 response which does not require an overall
// content-length header
//
writeHeaders(response, content, -1);
String mimetype = (content.getContentType() == null ? null : content.getContentType().toString());
writeHeaders(response, resource, -1);
String mimetype = response.getContentType();
if (mimetype == null) {
ConcurrentLog.warn("FILEHANDLER","YaCyDefaultServlet: Unknown mimetype for " + request.getRequestURI());
}

@ -1,49 +0,0 @@
//
// RewriteHandler
// Copyright 2011 by Florian Richter
// First released 2011 at http://yacy.net
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program in the file lgpl21.txt
// If not, see <http://www.gnu.org/licenses/>.
//
package net.yacy.http;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
public class RewriteHandler extends AbstractHandler implements Handler {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
if(target.equals("/")) {
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.html");
dispatcher.forward(request, response);
}
}
}

@ -1,131 +0,0 @@
//
// SSIHandler
// Copyright 2011 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// First released 13.04.2011 at http://yacy.net
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program in the file lgpl21.txt
// If not, see <http://www.gnu.org/licenses/>.
//
package net.yacy.http;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.yacy.cora.util.ByteBuffer;
import net.yacy.cora.util.CommonPattern;
import net.yacy.cora.util.ConcurrentLog;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
/**
* Jetty Http HandlerWrapper applying server-side includes,
* used for trickling display of search results
*/
public class SSIHandler extends ContentModHandler implements Handler, HandlerContainer {
/**
* constructor
* @param h Handler to wrap (it's output is scanned for SSI-marks)
*/
public SSIHandler(Handler h) {
super(h);
}
@Override
protected void doContentMod(final byte[] in, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
ByteBuffer buffer = new ByteBuffer(in);
OutputStream out = response.getOutputStream();
int off = 0; // starting offset
int p = buffer.indexOf("<!--#".getBytes(), off);
int q;
while (p >= 0) {
q = buffer.indexOf("-->".getBytes(), p + 10);
out.write(in, off, p - off);
out.flush();
parseSSI(buffer, p, request, response);
off = q + 3;
p = buffer.indexOf("<!--#".getBytes(), off);
}
out.write(in, off, in.length - off);
out.flush();
}
private void parseSSI(final ByteBuffer in, final int off, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (in.startsWith("<!--#include virtual=\"".getBytes(), off)) {
final int q = in.indexOf("\"".getBytes(), off + 22);
if (q > 0) {
final String path = in.toString(off + 22, q - off - 22);
try {
//RequestDispatcher dispatcher = request.getRequestDispatcher("/"+path);
//
//TODO: dispatcher.include did not work in testing, temporarely added old writeContent -
//
//dispatcher.include(request, response);
writeContent(path,request,response);
response.flushBuffer();
} catch (Exception e) {
ConcurrentLog.logException(e);
throw new ServletException();
}
}
}
}
/**
* temporarly added old writeContent for SSI to output include files
* as request.parameter is not modifyable used quickfix to add parameter via request.setAttribute
* and added temporarely the code in handler (TemplateHandler.handle) to read the request.attribute
* TODO: should finally be implementend otherwise eg. via HttpServletRequestWrapper
*/
public void writeContent(final String path, HttpServletRequest request, HttpServletResponse response) {
// check if there are arguments in path string
String args;
String fname = path;
final int argpos = path.indexOf('?');
if (argpos > 0) {
fname = path.substring(0, argpos);
args = path.substring(argpos + 1);
String[] arglist = CommonPattern.AMP.split(args);
for (String arg : arglist) {
String[] argnv = arg.split("=");
if (argnv.length > 1) {
request.setAttribute(argnv[0], argnv[1]);
} else {
request.setAttribute(arg, null);
}
}
}
try {
Handler h = this.getHandler();
h.handle(fname, null, request, response);
} catch (IOException ex) {
ConcurrentLog.logException(ex);
} catch (ServletException ex) {
ConcurrentLog.logException(ex);
}
}
}

@ -69,7 +69,6 @@ import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.eclipse.jetty.http.HttpContent;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
@ -99,9 +98,6 @@ import org.eclipse.jetty.util.resource.Resource;
*
* resourceBase Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
@ -121,7 +117,6 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
protected boolean _acceptRanges = true;
protected boolean _dirAllowed = true;
protected boolean _pathInfoOnly = false;
protected boolean _etags = false;
protected Resource _resourceBase;
protected MimeTypes _mimeTypes;
protected String[] _welcomes;
@ -164,14 +159,12 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
}
try {
_resourceBase = Resource.newResource(rb);
} catch (Exception e) {
} catch (IOException e) {
ConcurrentLog.logException(e);
throw new UnavailableException(e.toString());
}
}
_etags = getInitBoolean("etags", _etags);
if (ConcurrentLog.isFine("FILEHANDLER")) {
ConcurrentLog.fine("FILEHANDLER","YaCyDefaultServlet: resource base = " + _resourceBase);
}
@ -277,7 +270,7 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
/* ------------------------------------------------------------ */
/* Check modification date headers.
*/
abstract protected boolean passConditionalHeaders(HttpServletRequest request, HttpServletResponse response, Resource resource, HttpContent content)
abstract protected boolean passConditionalHeaders(HttpServletRequest request, HttpServletResponse response, Resource resource)
throws IOException;
/* ------------------------------------------------------------------- */
@ -300,7 +293,7 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
}
byte[] data = dir.getBytes("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.setContentType(MimeTypes.TEXT_HTML_UTF_8);
response.setContentLength(data.length);
response.getOutputStream().write(data);
}
@ -310,17 +303,17 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
HttpServletResponse response,
boolean include,
Resource resource,
HttpContent content,
Enumeration<String> reqRanges)
throws IOException;
/* ------------------------------------------------------------ */
protected void writeHeaders(HttpServletResponse response, HttpContent content, long count) {
if (content.getContentType() != null && response.getContentType() == null) {
response.setContentType(content.getContentType().toString());
protected void writeHeaders(HttpServletResponse response, Resource resource, long count) {
if (response.getContentType() == null) {
String mime = _mimeTypes.getMimeByExtension(resource.getName()).toString();
response.setContentType(mime);
}
long lml = content.getResource().lastModified();
long lml = resource.lastModified();
if (lml >= 0) {
response.setDateHeader(HeaderFramework.LAST_MODIFIED, lml);
}
@ -333,21 +326,12 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
}
}
writeOptionHeaders(response);
if (_etags) {
response.setHeader(HeaderFramework.ETAG, content.getETag().toString());
}
}
/* ------------------------------------------------------------ */
protected void writeOptionHeaders(HttpServletResponse response) {
if (_acceptRanges) {
response.setHeader(HeaderFramework.ACCEPT_RANGES, "bytes");
}
}
protected Object invokeServlet(final File targetClass, final RequestHeader request, final serverObjects args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
return rewriteMethod(targetClass).invoke(null, new Object[]{request, args, Switchboard.getSwitchboard()}); // add switchboard
}
@ -523,7 +507,7 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
result = RasterPlotter.exportImage(bi, targetExt);
}
final String mimeType = Classification.ext2mime(targetExt, "text/html");
final String mimeType = Classification.ext2mime(targetExt, MimeTypes.TEXT_HTML);
response.setContentType(mimeType);
response.setContentLength(result.length());
response.setStatus(HttpServletResponse.SC_OK);
@ -577,7 +561,7 @@ public abstract class YaCyDefaultServlet extends HttpServlet {
templatePatterns.put("p2p", sb.getConfigBool(SwitchboardConstants.DHT_ENABLED, true) || !sb.isRobinsonMode() ? 1 : 0);
if (targetFile.exists() && targetFile.isFile() && targetFile.canRead()) {
String mimeType = Classification.ext2mime(targetExt, "text/html");
String mimeType = Classification.ext2mime(targetExt, MimeTypes.TEXT_HTML);
InputStream fis;
long fileSize = targetFile.length();

@ -1,8 +0,0 @@
package net.yacy.http;
import org.eclipse.jetty.server.handler.ErrorHandler;
public class YaCyErrorHandler extends ErrorHandler {
}
Loading…
Cancel
Save