Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets')
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/BasicResourceDelivery.java78
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java31
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ContentLengthLier.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/FileMolester.java28
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/HelloWorld.java7
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/IntermittentTimeout.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/LastModifiedLier.java41
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java28
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/StatusCodeResponse.java22
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/TimeOut.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Truncator.java19
12 files changed, 170 insertions, 120 deletions
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/BasicResourceDelivery.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/BasicResourceDelivery.java
index 13dc0cf99..7afe05a15 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/BasicResourceDelivery.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/BasicResourceDelivery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -39,9 +39,9 @@ import org.osgi.service.http.HttpService;
public class BasicResourceDelivery extends HttpServlet {
private static final long serialVersionUID = 1L;
// private static final String CHARSET = "utf-8"; //$NON-NLS-1$
- private SecureAction secureAction;
- private String alias;
- private URI path;
+ private final SecureAction secureAction;
+ private final String alias;
+ private final URI path;
protected static final String defaultMimeType = "application/octet-stream"; //$NON-NLS-1$
/**
@@ -53,6 +53,7 @@ public class BasicResourceDelivery extends HttpServlet {
path = thePath;
}
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
URI resource = null;
try {
@@ -70,7 +71,7 @@ public class BasicResourceDelivery extends HttpServlet {
}
if (url == null) {
- fileNotFound(resource, request, response);
+ fileNotFound(resource, response);
return;
}
@@ -89,7 +90,7 @@ public class BasicResourceDelivery extends HttpServlet {
try {
in = conn.getInputStream();
} catch (IOException ex) {
- fileNotFound(resource, request, response);
+ fileNotFound(resource, response);
return;
}
try {
@@ -101,23 +102,26 @@ public class BasicResourceDelivery extends HttpServlet {
}
}
- protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
this.doDeliver(conn, in, filename, request, response);
}
- /**
- * Default method delivering content from a file. Subclasses should override this method
- * to deliver "broken content" (e.g. truncated, mismatched content length etc.).
- * This default method performs the same delivery as the default "register resource" in the
- * http service.
- * @param conn - The URLConnection to the resource
- * @param in - InputStream to read from
+ /**
+ * Default method delivering content from a file. Subclasses should override
+ * this method to deliver "broken content" (e.g. truncated, mismatched content
+ * length etc.). This default method performs the same delivery as the default
+ * "register resource" in the http service.
+ *
+ * @param conn - The URLConnection to the resource
+ * @param in - InputStream to read from
* @param filename - the filename being read
- * @param request - the servlet request
+ * @param request - the servlet request
* @param response - the servlet response
* @throws IOException - on errors
*/
- protected void doDeliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ protected void doDeliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
// set when the resource was modified
addDateHeader(response, HttpConstants.LAST_MODIFIED, getLastModified(conn));
int statusCode = HttpHeaderToStatus(conn.getHeaderField(0));
@@ -160,11 +164,14 @@ public class BasicResourceDelivery extends HttpServlet {
}
}
- protected void fileNotFound(URI file, HttpServletRequest request, HttpServletResponse response) throws IOException {
- response.sendError(HttpServletResponse.SC_NOT_FOUND, (file == null ? "<no file>" : file.toString()) + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
+ protected void fileNotFound(URI file, HttpServletResponse response) throws IOException {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND,
+ (file == null ? "<no file>" : file.toString()) + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
}
- protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ @Override
+ protected void doHead(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
URI resource = null;
try {
resource = getFilename(request.getRequestURI());
@@ -181,7 +188,7 @@ public class BasicResourceDelivery extends HttpServlet {
}
if (url == null) {
- fileNotFound(resource, request, response);
+ fileNotFound(resource, response);
return;
}
URLConnection conn = secureAction.openURL(url);
@@ -190,11 +197,13 @@ public class BasicResourceDelivery extends HttpServlet {
doDeliverHead(resource.toString(), conn, request, response); // TODO: change API to use URI?
}
- protected void deliverHead(String filename, URLConnection conn, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void deliverHead(String filename, URLConnection conn, HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
this.doDeliverHead(filename, conn, request, response);
}
- protected void doDeliverHead(String filename, URLConnection conn, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doDeliverHead(String filename, URLConnection conn, HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
int contentlength = getContentLength(conn);
int statusCode = HttpHeaderToStatus(conn.getHeaderField(0));
// set status = ok if there was no http header...
@@ -226,6 +235,7 @@ public class BasicResourceDelivery extends HttpServlet {
/**
* Override to lie about last modified
+ *
* @param conn
* @return time in ms
*/
@@ -235,6 +245,7 @@ public class BasicResourceDelivery extends HttpServlet {
/**
* Override to lie about content length
+ *
* @param conn
* @return length in bytes
*/
@@ -243,14 +254,16 @@ public class BasicResourceDelivery extends HttpServlet {
}
protected URI getFilename(String filename) throws URISyntaxException {
- //If the requested URI is equal to the Registeration's alias, send the file
- //corresponding to the alias. Otherwise, we have request for a file in an
- //registered directory (the file was not directly registered itself).
+ // If the requested URI is equal to the Registeration's alias, send the file
+ // corresponding to the alias. Otherwise, we have request for a file in an
+ // registered directory (the file was not directly registered itself).
if (filename.equals(alias)) {
filename = path.getPath();
} else {
- // The file we re looking for is the registered resource (alias) + the rest of the
- // filename that is not part of the registered resource. For example, if we export
+ // The file we re looking for is the registered resource (alias) + the rest of
+ // the
+ // filename that is not part of the registered resource. For example, if we
+ // export
// /a to /tmp and we have a request for /a/b/foo.txt, then /tmp is our directory
// (file.toString()) and /b/foo.txt is the rest.
// The result is that we open the file /tmp/b/foo.txt.
@@ -280,14 +293,15 @@ public class BasicResourceDelivery extends HttpServlet {
filename = buf.toString();
}
}
- return new URI(path.getScheme(), path.getUserInfo(), path.getHost(), path.getPort(), filename, path.getQuery(), path.getFragment());
+ return new URI(path.getScheme(), path.getUserInfo(), path.getHost(), path.getPort(), filename, path.getQuery(),
+ path.getFragment());
// return (filename);
}
/**
* This method returns the correct MIME type of a given URI by first checking
- * the HttpContext::getMimeType and, if null, checking the httpservice's MIMETypes table.
- * return mimetype with charset=utf-8 for all text/... types
+ * the HttpContext::getMimeType and, if null, checking the httpservice's
+ * MIMETypes table. return mimetype with charset=utf-8 for all text/... types
*/
protected String computeMimeType(String name, URLConnection conn) {
String mimeType = computeMimeType2(name, conn);
@@ -318,7 +332,9 @@ public class BasicResourceDelivery extends HttpServlet {
public static final DateFormat PATTERN_RFC1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); //$NON-NLS-1$
/**
- * Support setting date header - in servlet > 2.1 it is possible to call this method directly on the HttpResponse.
+ * Support setting date header - in servlet > 2.1 it is possible to call this
+ * method directly on the HttpResponse.
+ *
* @param response
* @param name
* @param timestamp
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java
index c8e823c8f..4be451bad 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,29 +24,31 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.equinox.p2.testserver.LinearChange;
/**
- * The ChopAndDelay deliver the content chopped up in smaller packets and adds delay
- * between packets.
- *
+ * The ChopAndDelay deliver the content chopped up in smaller packets and adds
+ * delay between packets.
+ *
*/
public class ChopAndDelay extends BasicResourceDelivery {
int chopFactor;
private LinearChange delayFunction;
private long msDelay;
- private int fastPercent;
+ private final int fastPercent;
/**
* Create a file molester that turns content into gibberish.
- *
- * @param theAlias the path this servlet is registered under
- * @param thePath the path to use as root for the alias
- * @param chopFactor - a value between 1 and 12 where 1 is one byte, and 12 is 4k bytes at a time.
+ *
+ * @param theAlias the path this servlet is registered under
+ * @param thePath the path to use as root for the alias
+ * @param chopFactor - a value between 1 and 12 where 1 is one byte, and 12
+ * is 4k bytes at a time.
* @param delayFunction - function returning a series of delay values
*/
public ChopAndDelay(String theAlias, URI thePath, int chopFactor, int fastPercent, LinearChange delayFunction) {
super(theAlias, thePath);
if (chopFactor < 1 || chopFactor > 12)
- throw new IllegalArgumentException("chopFactor must be between 1 and 12 (inclusive) - was:" + Integer.valueOf(chopFactor)); //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "chopFactor must be between 1 and 12 (inclusive) - was:" + Integer.valueOf(chopFactor)); //$NON-NLS-1$
this.chopFactor = chopFactor;
if (fastPercent < 0 || fastPercent > 100)
throw new IllegalArgumentException("fastPercent must be 0-100 - was:" + Integer.valueOf(fastPercent)); //$NON-NLS-1$
@@ -60,12 +62,15 @@ public class ChopAndDelay extends BasicResourceDelivery {
private static final long serialVersionUID = 1L;
- protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @Override
+ protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
// chop up all files
- doChop(conn, in, filename, request, response);
+ doChop(conn, in, filename, response);
}
- protected void doChop(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ protected void doChop(URLConnection conn, InputStream in, String filename, HttpServletResponse response)
+ throws IOException {
LinearChange delayer = delayFunction.fork();
int contentlength = conn.getContentLength();
if (contentlength >= 0) {
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ContentLengthLier.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ContentLengthLier.java
index 98a037736..532e5b549 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ContentLengthLier.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ContentLengthLier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,9 +19,10 @@ public class ContentLengthLier extends BasicResourceDelivery {
double keepFactor;
/**
- * The ContentLengthLier sets the content length to a percentage of the original length.
- * Values between 0 and 200 can be used (to lie about files being both smaller < 100, or larger > 100).
- *
+ * The ContentLengthLier sets the content length to a percentage of the original
+ * length. Values between 0 and 200 can be used (to lie about files being both
+ * smaller < 100, or larger > 100).
+ *
* @param theAlias
* @param thePath
* @param keepPercent - how much to lie between 0 and 200 (inclusive)
@@ -29,12 +30,14 @@ public class ContentLengthLier extends BasicResourceDelivery {
public ContentLengthLier(String theAlias, URI thePath, int keepPercent) {
super(theAlias, thePath);
if (keepPercent < 0 || keepPercent > 200)
- throw new IllegalArgumentException("keepPercent must be between 0 and 200 - was:" + Integer.valueOf(keepPercent)); //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "keepPercent must be between 0 and 200 - was:" + Integer.valueOf(keepPercent)); //$NON-NLS-1$
keepFactor = keepPercent / 100.0;
}
private static final long serialVersionUID = 1L;
+ @Override
protected int getContentLength(URLConnection conn) {
int contentLength = conn.getContentLength();
return (contentLength >= 0) ? (int) (contentLength * keepFactor) : contentLength;
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/FileMolester.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/FileMolester.java
index 3a5485230..14b74cc83 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/FileMolester.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/FileMolester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,11 +23,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * The FileMolester will keep a certain amount of the file from the beginning, and return
- * garbage/gibberish for the rest of the file's content. The garbage is produced by shifting every
- * byte 1 bit to the left.
- *
- * The idea for keeping some percentage is to support keeping xml headers / doctype etc.
+ * The FileMolester will keep a certain amount of the file from the beginning,
+ * and return garbage/gibberish for the rest of the file's content. The garbage
+ * is produced by shifting every byte 1 bit to the left.
+ *
+ * The idea for keeping some percentage is to support keeping xml headers /
+ * doctype etc.
*/
public class FileMolester extends BasicResourceDelivery {
@@ -35,9 +36,9 @@ public class FileMolester extends BasicResourceDelivery {
/**
* Create a file molester that turns content into gibberish.
- *
- * @param theAlias the path this servlet is registered under
- * @param thePath the path to use as root for the alias
+ *
+ * @param theAlias the path this servlet is registered under
+ * @param thePath the path to use as root for the alias
* @param keepLength - how many bytes in the beginning that will be unmolested
*/
public FileMolester(String theAlias, URI thePath, int keepLength) {
@@ -49,12 +50,15 @@ public class FileMolester extends BasicResourceDelivery {
private static final long serialVersionUID = 1L;
- protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @Override
+ protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
// molest all files
- doMolest(conn, in, filename, request, response);
+ doMolest(conn, in, filename, response);
}
- protected void doMolest(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ protected void doMolest(URLConnection conn, InputStream in, String filename, HttpServletResponse response)
+ throws IOException {
int contentlength = conn.getContentLength();
if (contentlength >= 0) {
response.setContentLength(contentlength);
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/HelloWorld.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/HelloWorld.java
index 7bc682803..e50a30806 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/HelloWorld.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/HelloWorld.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,13 +18,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * Simple "smoke test" servlet - for manual testing that the http server is running and is
- * capable of running servlets.
+ * Simple "smoke test" servlet - for manual testing that the http server is
+ * running and is capable of running servlets.
*/
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html"); //$NON-NLS-1$
PrintWriter writer = response.getWriter();
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/IntermittentTimeout.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/IntermittentTimeout.java
index ac17e7ad5..f4060f8be 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/IntermittentTimeout.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/IntermittentTimeout.java
@@ -15,7 +15,7 @@ import org.eclipse.equinox.p2.testserver.HttpConstants;
public class IntermittentTimeout extends BasicResourceDelivery {
/**
- *
+ *
*/
private static final long serialVersionUID = 2216234319571297257L;
int count = 1;
@@ -24,7 +24,9 @@ public class IntermittentTimeout extends BasicResourceDelivery {
super(theAlias, thePath);
}
- protected void doDeliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @Override
+ protected void doDeliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
// set when the resource was modified
addDateHeader(response, HttpConstants.LAST_MODIFIED, getLastModified(conn));
int statusCode = HttpHeaderToStatus(conn.getHeaderField(0));
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/LastModifiedLier.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/LastModifiedLier.java
index 84d568ca1..74a95a5e8 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/LastModifiedLier.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/LastModifiedLier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,12 +16,13 @@ import java.net.URLConnection;
import javax.servlet.http.HttpServletResponse;
/**
- * Manipulates the last modified time of serviced files.
- * The manipulator will set all modified times to 0 if TYPE_ZERO is used, to 1 if TYPE_OLD is used,
- * to the current time if TYPE_NOW is used, and a value 24 hours into the future if TYPE_FUTURE is used.
- * (Future values are not allowed in HTTP - the server should guard against them and force the value
- * to be no bigger than the response date).
- * The TYPE_BAD will produce a HTTP header with wrong format for the date value (fails date parsing).
+ * Manipulates the last modified time of serviced files. The manipulator will
+ * set all modified times to 0 if TYPE_ZERO is used, to 1 if TYPE_OLD is used,
+ * to the current time if TYPE_NOW is used, and a value 24 hours into the future
+ * if TYPE_FUTURE is used. (Future values are not allowed in HTTP - the server
+ * should guard against them and force the value to be no bigger than the
+ * response date). The TYPE_BAD will produce a HTTP header with wrong format for
+ * the date value (fails date parsing).
*
*/
public class LastModifiedLier extends BasicResourceDelivery {
@@ -33,12 +34,12 @@ public class LastModifiedLier extends BasicResourceDelivery {
public static final int TYPE_BAD = 5;
private static final int TYPE_LAST = TYPE_BAD;
- private int type;
+ private final int type;
/**
- * The LastModifiedLier returns a last modified time according to the parameter timeType.
- * It can be TYPE_ZERO, TYPE_OLD, TYPE_NOW, TYPE_FUTURE, or TYPE_BAD.
- *
+ * The LastModifiedLier returns a last modified time according to the parameter
+ * timeType. It can be TYPE_ZERO, TYPE_OLD, TYPE_NOW, TYPE_FUTURE, or TYPE_BAD.
+ *
* @param theAlias
* @param thePath
* @param timeType - a TYPE_XXX constant defining what time to return
@@ -52,6 +53,7 @@ public class LastModifiedLier extends BasicResourceDelivery {
private static final long serialVersionUID = 1L;
+ @Override
protected long getLastModified(URLConnection conn) {
// ignore real value and lie based on constant
return getLastModified();
@@ -59,19 +61,20 @@ public class LastModifiedLier extends BasicResourceDelivery {
private long getLastModified() {
switch (type) {
- case TYPE_ZERO :
- return 0L;
- case TYPE_OLD :
- return 1000L;
- case TYPE_NOW :
- return System.currentTimeMillis();
- case TYPE_FUTURE :
- return System.currentTimeMillis() + 24 * 60 * 60 * 1000;
+ case TYPE_ZERO:
+ return 0L;
+ case TYPE_OLD:
+ return 1000L;
+ case TYPE_NOW:
+ return System.currentTimeMillis();
+ case TYPE_FUTURE:
+ return System.currentTimeMillis() + 24 * 60 * 60 * 1000;
}
// should not happen
return 0L;
}
+ @Override
public void addDateHeader(HttpServletResponse response, String name, long timestamp) {
if (type != TYPE_BAD)
super.addDateHeader(response, name, timestamp);
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java
index ab875afb0..c61ce7ebf 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,13 +20,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * Redirects n times, before redirecting to final location (a path on same server).
- *
+ * Redirects n times, before redirecting to final location (a path on same
+ * server).
+ *
*/
public class Redirector extends HttpServlet {
private static final long serialVersionUID = 1L;
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html"); //$NON-NLS-1$
PrintWriter writer = response.getWriter();
@@ -38,7 +40,9 @@ public class Redirector extends HttpServlet {
String[] result = requestPath.split("/"); //$NON-NLS-1$
if (result.length < 3 && !"redirect".equalsIgnoreCase(result[1])) //$NON-NLS-1$
{
- getServletContext().log("Error Servlet requires being configured to get /redirect/count paths. Example /redirect/500, got" + requestPath); //$NON-NLS-1$
+ getServletContext().log(
+ "Error Servlet requires being configured to get /redirect/count paths. Example /redirect/500, got" //$NON-NLS-1$
+ + requestPath);
return;
}
// get the error code
@@ -85,6 +89,7 @@ public class Redirector extends HttpServlet {
}
}
+ @Override
public void doHead(HttpServletRequest request, HttpServletResponse response) {
// produce same response as for GET, but no content (writer == null)
doStatus(request, response, null);
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java
index a9123506a..8039abdac 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2016 Wind River and others.
+ * Copyright (c) 2012, 2018 Wind River and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,11 +18,9 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -30,18 +28,16 @@ import org.eclipse.equinox.p2.testserver.HttpConstants;
public class Stats extends HttpServlet {
- /**
- *
- */
private static final long serialVersionUID = -3209768955270841029L;
private static final String UnkownPackage = "unkown"; //$NON-NLS-1$
private static final String PACKAGE = "package"; //$NON-NLS-1$
- private Map downloadStats = new HashMap();
+ private final Map<String, Integer> downloadStats = new HashMap<>();
public Stats() {
downloadStats.put(UnkownPackage, Integer.valueOf(0));
}
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
responseHeaderAndStatus(response);
@@ -75,15 +71,17 @@ public class Stats extends HttpServlet {
private String getStatsResult() {
StringBuffer sb = new StringBuffer();
- sb.append("It's a page to count the downloading times when heading this page with query 'package=<package name>'.\n"); //$NON-NLS-1$
- for (Iterator iter = downloadStats.keySet().iterator(); iter.hasNext();) {
- String packageName = (String) iter.next();
+ sb.append(
+ "It's a page to count the downloading times when heading this page with query 'package=<package name>'.\n"); //$NON-NLS-1$
+ for (String string : downloadStats.keySet()) {
+ String packageName = string;
sb.append(packageName).append(" download number: ").append(downloadStats.get(packageName)).append("\n"); //$NON-NLS-1$//$NON-NLS-2$
}
return sb.toString();
}
- protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ @Override
+ protected void doHead(HttpServletRequest request, HttpServletResponse response) {
String queryString = request.getQueryString();
responseHeaderAndStatus(response);
@@ -91,11 +89,11 @@ public class Stats extends HttpServlet {
boolean found = false;
if (queryString != null) {
String[] parameters = queryString.split("&"); //$NON-NLS-1$
- for (int i = 0; i < parameters.length; i++) {
- String[] paraPair = parameters[i].split("=", 2); //$NON-NLS-1$
+ for (String parameter : parameters) {
+ String[] paraPair = parameter.split("=", 2); //$NON-NLS-1$
if (paraPair.length == 2 && PACKAGE.equals(paraPair[0])) {
found = true;
- Integer count = (Integer) downloadStats.get(paraPair[1]);
+ Integer count = downloadStats.get(paraPair[1]);
if (count == null) {
count = Integer.valueOf(1);
} else
@@ -106,7 +104,7 @@ public class Stats extends HttpServlet {
}
}
if (!found) {
- Integer count = (Integer) downloadStats.get(UnkownPackage);
+ Integer count = downloadStats.get(UnkownPackage);
downloadStats.put(UnkownPackage, Integer.valueOf(1 + count.intValue()));
}
}
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/StatusCodeResponse.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/StatusCodeResponse.java
index d162dcd75..557e53841 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/StatusCodeResponse.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/StatusCodeResponse.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,18 +18,19 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * Produces a response with a status code specified in the request URI.
- * Requires to be registered for "/status" path. The request is made on the format
- * "/status/code/" where code is the HTTP integer status code. The path after /code/ can be
- * anything - it is always ignored.
- * The response to GET produces HTML text "Requested status: code".
- * The response to HEAD just produces the status header response.
- *
+ * Produces a response with a status code specified in the request URI. Requires
+ * to be registered for "/status" path. The request is made on the format
+ * "/status/code/" where code is the HTTP integer status code. The path after
+ * /code/ can be anything - it is always ignored. The response to GET produces
+ * HTML text "Requested status: code". The response to HEAD just produces the
+ * status header response.
+ *
*/
public class StatusCodeResponse extends HttpServlet {
private static final long serialVersionUID = 1L;
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html"); //$NON-NLS-1$
PrintWriter writer = response.getWriter();
@@ -41,7 +42,9 @@ public class StatusCodeResponse extends HttpServlet {
String[] result = requestPath.split("/"); //$NON-NLS-1$
if (result.length < 3 && !"status".equalsIgnoreCase(result[1])) //$NON-NLS-1$
{
- getServletContext().log("Error Servlet requires being configured to get /status/statuscode paths. Example /status/500, got" + requestPath); //$NON-NLS-1$
+ getServletContext().log(
+ "Error Servlet requires being configured to get /status/statuscode paths. Example /status/500, got" //$NON-NLS-1$
+ + requestPath);
return;
}
// get the error code
@@ -60,6 +63,7 @@ public class StatusCodeResponse extends HttpServlet {
htmlPage(writer, "Requested Status: " + Integer.valueOf(errorCode), false); //$NON-NLS-1$
}
+ @Override
public void doHead(HttpServletRequest request, HttpServletResponse response) {
// produce same reponse as for GET, but no content (writer == null)
doStatus(request, response, null);
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/TimeOut.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/TimeOut.java
index e5544cd91..5bbf3df04 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/TimeOut.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/TimeOut.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,6 +24,7 @@ public class TimeOut extends HttpServlet {
private static final long serialVersionUID = 1L;
private static long MINUTES_MS = 1000 * 60; // minutes in ms
+ @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
doDelay();
}
@@ -37,6 +38,7 @@ public class TimeOut extends HttpServlet {
}
}
+ @Override
protected void doHead(HttpServletRequest request, HttpServletResponse response) {
doDelay();
}
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Truncator.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Truncator.java
index 17c4bf636..35804b2ab 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Truncator.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Truncator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2018 Cloudsmith Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -30,18 +30,22 @@ public class Truncator extends BasicResourceDelivery {
public Truncator(String theAlias, URI thePath, int keepPercent) {
super(theAlias, thePath);
if (keepPercent < 0 || keepPercent > 100)
- throw new IllegalArgumentException("keepPercent must be between 0 and 100 - was:" + Integer.valueOf(keepPercent)); //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "keepPercent must be between 0 and 100 - was:" + Integer.valueOf(keepPercent)); //$NON-NLS-1$
keepFactor = keepPercent / 100.0;
}
private static final long serialVersionUID = 1L;
- protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @Override
+ protected void deliver(URLConnection conn, InputStream in, String filename, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
// truncate all files
- doTruncate(conn, in, filename, request, response);
+ doTruncate(conn, in, filename, response);
}
- protected void doTruncate(URLConnection conn, InputStream in, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
+ protected void doTruncate(URLConnection conn, InputStream in, String filename, HttpServletResponse response)
+ throws IOException {
int contentlength = conn.getContentLength();
if (contentlength >= 0) {
response.setContentLength(contentlength);
@@ -86,6 +90,7 @@ public class Truncator extends BasicResourceDelivery {
/**
* Returns read if entire amount should be read. Returns a lower number if
* written + read > keepPercent of total
+ *
* @param total
* @param written
* @param read
@@ -96,7 +101,9 @@ public class Truncator extends BasicResourceDelivery {
return (read + written) > cap ? cap - written : read;
}
- protected void deliverHead(String filename, URLConnection conn, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ @Override
+ protected void deliverHead(String filename, URLConnection conn, HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
// deliver normal head response
super.doDeliverHead(filename, conn, request, response);

Back to the top