Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lindberg2009-05-11 07:32:42 -0400
committerHenrik Lindberg2009-05-11 07:32:42 -0400
commitfba69e0bf372a6fd292096e94631bb6293bfae98 (patch)
treefc82d9c9eb9e0d90278afad8ed975b93434a6205 /bundles/org.eclipse.equinox.p2.testserver
parentb3bbaccb618325433f6c3a6c178b5d4a2a0e1897 (diff)
downloadrt.equinox.p2-fba69e0bf372a6fd292096e94631bb6293bfae98.tar.gz
rt.equinox.p2-fba69e0bf372a6fd292096e94631bb6293bfae98.tar.xz
rt.equinox.p2-fba69e0bf372a6fd292096e94631bb6293bfae98.zip
Added redirector servlet. Available as /redirect. Added /proxy/decelerate2 as service for testing progress bars.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.testserver')
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java7
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/ChopAndDelay.java26
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java105
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/webfiles/index.html3
4 files changed, 132 insertions, 9 deletions
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
index 8882e3972..78e3b3ad1 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
@@ -18,6 +18,7 @@ import org.eclipse.equinox.p2.testserver.servlets.ChopAndDelay;
import org.eclipse.equinox.p2.testserver.servlets.ContentLengthLier;
import org.eclipse.equinox.p2.testserver.servlets.FileMolester;
import org.eclipse.equinox.p2.testserver.servlets.LastModifiedLier;
+import org.eclipse.equinox.p2.testserver.servlets.Redirector;
import org.eclipse.equinox.p2.testserver.servlets.StatusCodeResponse;
import org.eclipse.equinox.p2.testserver.servlets.TimeOut;
import org.eclipse.equinox.p2.testserver.servlets.Truncator;
@@ -67,18 +68,20 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
httpService.registerServlet("/status", new StatusCodeResponse(), null, null); //$NON-NLS-1$
httpService.registerServlet("/timeout", new TimeOut(), null, null); //$NON-NLS-1$
+ httpService.registerServlet("/redirect", new Redirector(), null, null); //$NON-NLS-1$
httpService.registerServlet("/truncated", new Truncator("/truncated", URI.create("/webfiles"), 50), null, null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
httpService.registerServlet("/molested", new FileMolester("/molested", URI.create("/webfiles"), 40), null, null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
// 8 bytes at a time, delay from 0 to 100 ms, in steps of 5
- httpService.registerServlet("/decelerate", new ChopAndDelay("/decelerate", URI.create("/webfiles"), 3, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ httpService.registerServlet("/decelerate", new ChopAndDelay("/decelerate", URI.create("/webfiles"), 3, 0, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
httpService.registerServlet("/proxy/truncated", new Truncator("/proxy/truncated", URI.create(SITE), 50), null, null); //$NON-NLS-1$//$NON-NLS-2$
httpService.registerServlet("/proxy/private", new BasicResourceDelivery("/proxy/private", URI.create(SITE)), null, secureHttpContext); //$NON-NLS-1$//$NON-NLS-2$
httpService.registerServlet("/proxy/never", new BasicResourceDelivery("/proxy/private", URI.create(SITE)), null, alwaysFail); //$NON-NLS-1$//$NON-NLS-2$
httpService.registerServlet("/proxy/flipFlop", new BasicResourceDelivery("/proxy/private", URI.create(SITE)), null, flipFlop); //$NON-NLS-1$//$NON-NLS-2$
httpService.registerServlet("/proxy/molested", new FileMolester("/proxy/molested", URI.create(SITE), 40), null, null); //$NON-NLS-1$//$NON-NLS-2$
- httpService.registerServlet("/proxy/decelerate", new ChopAndDelay("/proxy/decelerate", URI.create(SITE), 3, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$
+ httpService.registerServlet("/proxy/decelerate", new ChopAndDelay("/proxy/decelerate", URI.create(SITE), 3, 0, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$
+ httpService.registerServlet("/proxy/decelerate2", new ChopAndDelay("/proxy/decelerate2", URI.create(SITE), 3, 80, new LinearChange(100, 5, 105, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$
// lie about modified time
httpService.registerServlet("/proxy/modified/zero", new LastModifiedLier("/proxy/modified/zero", URI.create(SITE), LastModifiedLier.TYPE_ZERO), null, null); //$NON-NLS-1$//$NON-NLS-2$
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 9359eacb0..c8e823c8f 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
@@ -33,6 +33,7 @@ public class ChopAndDelay extends BasicResourceDelivery {
int chopFactor;
private LinearChange delayFunction;
private long msDelay;
+ private int fastPercent;
/**
* Create a file molester that turns content into gibberish.
@@ -42,13 +43,14 @@ public class ChopAndDelay extends BasicResourceDelivery {
* @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, LinearChange delayFunction) {
+ 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$
this.chopFactor = chopFactor;
- if (msDelay < 0)
- throw new IllegalArgumentException("msDelay must be >= 0 - was:" + Integer.valueOf(chopFactor)); //$NON-NLS-1$
+ if (fastPercent < 0 || fastPercent > 100)
+ throw new IllegalArgumentException("fastPercent must be 0-100 - was:" + Integer.valueOf(fastPercent)); //$NON-NLS-1$
+ this.fastPercent = fastPercent;
this.delayFunction = delayFunction;
msDelay = 0L;
this.delayFunction = delayFunction;
@@ -84,20 +86,25 @@ public class ChopAndDelay extends BasicResourceDelivery {
int chunksize = 1 << chopFactor;
char buffer[] = new char[4096];
int read;
+ int totalRead = 0;
+ boolean delay = fastPercent == 0 ? true : false;
while ((read = reader.read(buffer, 0, buffer.length)) != -1) {
int nChunks = read / chunksize + (read % chunksize > 0 ? 1 : 0);
for (int i = 0; i < nChunks; i++) {
writer.write(buffer, i * chunksize, Math.min(chunksize, read - i * chunksize));
writer.flush();
- if (msDelay > 0)
+ if (delay && msDelay > 0)
try {
Thread.sleep(msDelay);
} catch (InterruptedException e) {
// ignore
}
- if (delayer.hasNext())
+ if (delay && delayer.hasNext())
msDelay = delayer.next();
}
+ totalRead += read;
+ if (totalRead > contentlength * fastPercent / 100)
+ delay = true;
}
} else {
ServletOutputStream out = response.getOutputStream();
@@ -107,20 +114,25 @@ public class ChopAndDelay extends BasicResourceDelivery {
int chunksize = 1 << chopFactor;
byte buffer[] = new byte[4096];
int read;
+ int totalRead = 0;
+ boolean delay = fastPercent == 0 ? true : false;
while ((read = in.read(buffer, 0, buffer.length)) != -1) {
int nChunks = read / chunksize + (read % chunksize > 0 ? 1 : 0);
for (int i = 0; i < nChunks; i++) {
out.write(buffer, i * chunksize, Math.min(chunksize, read - i * chunksize));
out.flush();
- if (msDelay > 0)
+ if (delay && msDelay > 0)
try {
Thread.sleep(msDelay);
} catch (InterruptedException e) {
// ignore
}
- if (delayer.hasNext())
+ if (delay && delayer.hasNext())
msDelay = delayer.next();
}
+ totalRead += read;
+ if (totalRead > contentlength * fastPercent / 100)
+ delay = true;
}
}
}
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
new file mode 100644
index 000000000..ab875afb0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Redirector.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cloudsmith Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.testserver.servlets;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Redirects n times, before redirecting to final location (a path on same server).
+ *
+ */
+public class Redirector extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.setContentType("text/html"); //$NON-NLS-1$
+ PrintWriter writer = response.getWriter();
+ doStatus(request, response, writer);
+ }
+
+ protected void doStatus(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) {
+ String requestPath = request.getRequestURI();
+ 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$
+ return;
+ }
+ // get the error code
+ int iterations = 0;
+ try {
+ iterations = Integer.parseInt(result[2]);
+ } catch (NumberFormatException e) {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ getServletContext().log("Number format exception in /redirect/count path.", e); //$NON-NLS-1$
+ return;
+ }
+ String redirectPath;
+ if (iterations == 0) {
+ if (result.length > 3)
+ redirectPath = requestPath.substring("/redirect/0".length()); //$NON-NLS-1$
+ else
+ redirectPath = null;
+ } else {
+ redirectPath = "/redirect/" + Integer.valueOf(iterations - 1); //$NON-NLS-1$
+ for (int i = 3; i < result.length; i++)
+ redirectPath += "/" + result[i]; //$NON-NLS-1$
+ }
+
+ if (redirectPath != null) {
+ // perform a redirect
+ URI location = null;
+ try {
+ location = new URI(request.getScheme(), null, request.getServerName(), request.getServerPort(), //
+ redirectPath, null, null);
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ htmlPage(writer, "Internal error constructing redirect URL", false); //$NON-NLS-1$
+ return;
+ }
+
+ response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
+ response.setHeader("Location", location.toString()); //$NON-NLS-1$
+ } else {
+ // set the errorCode as the response and write a message
+ if (writer != null)
+ htmlPage(writer, "Redirected Successfully", false); //$NON-NLS-1$
+ }
+ }
+
+ public void doHead(HttpServletRequest request, HttpServletResponse response) {
+ // produce same response as for GET, but no content (writer == null)
+ doStatus(request, response, null);
+ }
+
+ private void htmlPage(PrintWriter writer, String body, boolean consoleOutput) {
+ if (consoleOutput)
+ System.err.println(body);
+
+ writer.println("<html>"); //$NON-NLS-1$
+ writer.println("<body>"); //$NON-NLS-1$
+ writer.println(body);
+ writer.println("<br/>"); //$NON-NLS-1$
+ writer.println("</body>"); //$NON-NLS-1$
+ writer.println("</html>"); //$NON-NLS-1$
+ writer.flush();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.testserver/webfiles/index.html b/bundles/org.eclipse.equinox.p2.testserver/webfiles/index.html
index 888e71d1d..6eedf01fd 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/webfiles/index.html
+++ b/bundles/org.eclipse.equinox.p2.testserver/webfiles/index.html
@@ -14,6 +14,7 @@ log in. The credentials are: user: <b>Aladdin</b>, password: <b>open sesame</b>.
<li>/proxy/truncated - goes to updates/3.4, but truncates all files</li>
<li>/proxy/molested - goes to updates/3.4, but generates gibberish for all files</li>
<li>/proxy/decelerate - goes to updates/3.4, but delivers files in very small delayed packets - delay increases.</li>
+<li>/proxy/decelerate2 - like /proxy/decelerate, but does not start delay until 80% of file has been processed. Good for progress bar testing.</li>
<li>/proxy/modified/... - goes to updates/3.4, but delivers various errors in "last modified" (see below)
<ul><li>.../zero - all times are returned as 0</li>
<li>.../old - all times are very old</li>
@@ -49,6 +50,8 @@ log in. The credentials are: user: <b>Aladdin</b>, password: <b>open sesame</b>.
<li>/timeout/ - a black hole - sleeps an our and produces no response.</li>
<li>/status/nnn/xxxxx - returns the status-code "nnn", and text/html
content, The xxxxx part is ignored. e.g. http://localhost:8080/status/500/ignored/part</li>
+<li>/redirect/nnn[/location] - redirects nnn times before redirecting to "location" - if no
+location is stated, a final page with message 'Redirected Successfully' is displayed.
</ul>
</body>
</html> \ No newline at end of file

Back to the top