diff options
author | Alexander Kurtakov | 2018-06-07 08:57:20 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-06-07 08:57:20 +0000 |
commit | 1c26af582a12646a42c7b2bd96e8fa257204d8ff (patch) | |
tree | 01c5991985c058000564d25489ed8eaa385941c8 /bundles/org.eclipse.equinox.p2.testserver/src/org | |
parent | d327fa362c43c139dee7958fb55ae76ec5a25f55 (diff) | |
download | rt.equinox.p2-1c26af582a12646a42c7b2bd96e8fa257204d8ff.tar.gz rt.equinox.p2-1c26af582a12646a42c7b2bd96e8fa257204d8ff.tar.xz rt.equinox.p2-1c26af582a12646a42c7b2bd96e8fa257204d8ff.zip |
Bug 535636 - Update bundles to Java 1.8
Take care of various modernizations and updates in p2.testserver.
Change-Id: Id5ad446c1cab4cf81702a28e976c41a41070cd58
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.testserver/src/org')
19 files changed, 318 insertions, 228 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 2a3b43c2d..8213d971e 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 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 @@ -32,9 +32,9 @@ import org.osgi.service.http.NamespaceException; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; -public class Activator implements BundleActivator, ServiceTrackerCustomizer { +public class Activator implements BundleActivator, ServiceTrackerCustomizer<HttpService, HttpService> { private static BundleContext context; - private ServiceTracker httpTracker; + private ServiceTracker<HttpService, ?> httpTracker; private SecureContext secureHttpContext; private SecuredArtifactsContext artifactSecuredHttpContext; private static Activator instance; @@ -46,21 +46,24 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { private static final String SITE2 = "http://www.eclipse.org/equinox/p2/testing/updateSite"; //$NON-NLS-1$ private static final String SITE3 = "http://download.eclipse.org/eclipse/updates/3.5-I-builds/"; //$NON-NLS-1$ + @Override public void start(BundleContext aContext) throws Exception { context = aContext; - httpTracker = new ServiceTracker(context, HttpService.class.getName(), this); + httpTracker = new ServiceTracker<>(context, HttpService.class, this); httpTracker.open(); instance = this; } + @Override public void stop(BundleContext aContext) throws Exception { httpTracker.close(); context = null; } - public Object addingService(ServiceReference reference) { - httpService = (HttpService) context.getService(reference); + @Override + public HttpService addingService(ServiceReference<HttpService> reference) { + httpService = context.getService(reference); secureHttpContext = new SecureContext(httpService.createDefaultHttpContext()); artifactSecuredHttpContext = new SecuredArtifactsContext(httpService.createDefaultHttpContext()); alwaysFail = new AlwaysFailContext(httpService.createDefaultHttpContext()); @@ -72,23 +75,33 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { httpService.registerResources("/private", "/webfiles", secureHttpContext); //$NON-NLS-1$ //$NON-NLS-2$ httpService.registerResources("/never", "/webfiles", alwaysFail); //$NON-NLS-1$ //$NON-NLS-2$ httpService.registerResources("/flipflop", "/webfiles", flipFlop); //$NON-NLS-1$ //$NON-NLS-2$ - // httpService.registerResources("/mirrorrequest", "/webfiles/emptyJarRepo", null); //$NON-NLS-1$ //$NON-NLS-2$ + // httpService.registerResources("/mirrorrequest", "/webfiles/emptyJarRepo", + // null); //$NON-NLS-1$ //$NON-NLS-2$ httpService.registerServlet("/status", new StatusCodeResponse(), null, null); //$NON-NLS-1$ httpService.registerServlet("/timeout", new TimeOut(), null, null); //$NON-NLS-1$ - httpService.registerServlet("/mirrorrequest", new IntermittentTimeout("/mirrorrequest", URI.create("http://localhost:" + System.getProperty("org.osgi.service.http.port", "8080") + "/public/emptyJarRepo")), null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + httpService.registerServlet("/mirrorrequest", //$NON-NLS-1$ + new IntermittentTimeout("/mirrorrequest", URI.create("http://localhost:" //$NON-NLS-1$ //$NON-NLS-2$ + + System.getProperty("org.osgi.service.http.port", "8080") + "/public/emptyJarRepo")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + null, null); 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$ + httpService.registerServlet("/truncated", new Truncator("/truncated", URI.create("/webfiles"), 50), null, //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + null); + httpService.registerServlet("/molested", new FileMolester("/molested", URI.create("/webfiles"), 40), null, //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + null); // 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, 0, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + httpService.registerServlet("/decelerate", //$NON-NLS-1$ + new ChopAndDelay("/decelerate", URI.create("/webfiles"), 3, 0, new LinearChange(0, 5, 100, 0)), //$NON-NLS-1$//$NON-NLS-2$ + null, null); addProxyServices(httpService, SITE, "/proxy/"); //$NON-NLS-1$ addProxyServices(httpService, SITE2, "/proxy2/"); //$NON-NLS-1$ - httpService.registerServlet("/proxy3/aprivate", new BasicResourceDelivery("/proxy3/aprivate", URI.create(SITE2)), null, artifactSecuredHttpContext); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet("/proxy4/aprivate", new BasicResourceDelivery("/proxy4/aprivate", URI.create(SITE3)), null, artifactSecuredHttpContext); //$NON-NLS-1$//$NON-NLS-2$ + httpService.registerServlet("/proxy3/aprivate", //$NON-NLS-1$ + new BasicResourceDelivery("/proxy3/aprivate", URI.create(SITE2)), null, artifactSecuredHttpContext); //$NON-NLS-1$ + httpService.registerServlet("/proxy4/aprivate", //$NON-NLS-1$ + new BasicResourceDelivery("/proxy4/aprivate", URI.create(SITE3)), null, artifactSecuredHttpContext); //$NON-NLS-1$ httpService.registerServlet("/stats", new Stats(), null, null); //$NON-NLS-1$ } catch (NamespaceException e) { @@ -103,33 +116,55 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { /** * Adds services to a location + * * @param site * @param root the "mount dir" e.g. "/proxy/" "/proxy2/" etc. - * @throws NamespaceException - * @throws ServletException + * @throws NamespaceException + * @throws ServletException */ - private void addProxyServices(HttpService httpService, String site, String root) throws ServletException, NamespaceException { - httpService.registerServlet(root + "truncated", new Truncator(root + "truncated", URI.create(site), 50), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "public", new BasicResourceDelivery(root + "public", URI.create(site)), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "private", new BasicResourceDelivery(root + "private", URI.create(site)), null, secureHttpContext); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "never", new BasicResourceDelivery(root + "private", URI.create(site)), null, alwaysFail); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "flipFlop", new BasicResourceDelivery(root + "private", URI.create(site)), null, flipFlop); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "molested", new FileMolester(root + "molested", URI.create(site), 40), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "decelerate", new ChopAndDelay(root + "decelerate", URI.create(site), 3, 0, new LinearChange(0, 5, 100, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "decelerate2", new ChopAndDelay(root + "decelerate2", URI.create(site), 3, 80, new LinearChange(100, 5, 105, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "readtimeout", new ChopAndDelay(root + "readtimeout", URI.create(site), 3, 10, new LinearChange(10 * 60 * 1000, 5, 5 + 10 * 60 * 1000, 0)), null, null); //$NON-NLS-1$//$NON-NLS-2$ + private void addProxyServices(HttpService service, String site, String root) + throws ServletException, NamespaceException { + service.registerServlet(root + "truncated", new Truncator(root + "truncated", URI.create(site), 50), null, //$NON-NLS-1$//$NON-NLS-2$ + null); + service.registerServlet(root + "public", new BasicResourceDelivery(root + "public", URI.create(site)), null, //$NON-NLS-1$//$NON-NLS-2$ + null); + service.registerServlet(root + "private", new BasicResourceDelivery(root + "private", URI.create(site)), //$NON-NLS-1$//$NON-NLS-2$ + null, secureHttpContext); + service.registerServlet(root + "never", new BasicResourceDelivery(root + "private", URI.create(site)), null, //$NON-NLS-1$//$NON-NLS-2$ + alwaysFail); + service.registerServlet(root + "flipFlop", new BasicResourceDelivery(root + "private", URI.create(site)), //$NON-NLS-1$//$NON-NLS-2$ + null, flipFlop); + service.registerServlet(root + "molested", new FileMolester(root + "molested", URI.create(site), 40), null, //$NON-NLS-1$//$NON-NLS-2$ + null); + service.registerServlet(root + "decelerate", //$NON-NLS-1$ + new ChopAndDelay(root + "decelerate", URI.create(site), 3, 0, new LinearChange(0, 5, 100, 0)), null, //$NON-NLS-1$ + null); + service.registerServlet(root + "decelerate2", //$NON-NLS-1$ + new ChopAndDelay(root + "decelerate2", URI.create(site), 3, 80, new LinearChange(100, 5, 105, 0)), null, //$NON-NLS-1$ + null); + service.registerServlet(root + "readtimeout", new ChopAndDelay(root + "readtimeout", URI.create(site), 3, //$NON-NLS-1$//$NON-NLS-2$ + 10, new LinearChange(10 * 60 * 1000, 5, 5 + 10 * 60 * 1000, 0)), null, null); // lie about modified time - httpService.registerServlet(root + "modified/zero", new LastModifiedLier(root + "modified/zero", URI.create(site), LastModifiedLier.TYPE_ZERO), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "modified/old", new LastModifiedLier(root + "modified/old", URI.create(site), LastModifiedLier.TYPE_OLD), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "modified/now", new LastModifiedLier(root + "modified/now", URI.create(site), LastModifiedLier.TYPE_NOW), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "modified/future", new LastModifiedLier(root + "modified/future", URI.create(site), LastModifiedLier.TYPE_FUTURE), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "modified/bad", new LastModifiedLier(root + "modified/bad", URI.create(site), LastModifiedLier.TYPE_BAD), null, null); //$NON-NLS-1$//$NON-NLS-2$ + service.registerServlet(root + "modified/zero", //$NON-NLS-1$ + new LastModifiedLier(root + "modified/zero", URI.create(site), LastModifiedLier.TYPE_ZERO), null, null); //$NON-NLS-1$ + service.registerServlet(root + "modified/old", //$NON-NLS-1$ + new LastModifiedLier(root + "modified/old", URI.create(site), LastModifiedLier.TYPE_OLD), null, null); //$NON-NLS-1$ + service.registerServlet(root + "modified/now", //$NON-NLS-1$ + new LastModifiedLier(root + "modified/now", URI.create(site), LastModifiedLier.TYPE_NOW), null, null); //$NON-NLS-1$ + service.registerServlet(root + "modified/future", //$NON-NLS-1$ + new LastModifiedLier(root + "modified/future", URI.create(site), LastModifiedLier.TYPE_FUTURE), null, //$NON-NLS-1$ + null); + service.registerServlet(root + "modified/bad", //$NON-NLS-1$ + new LastModifiedLier(root + "modified/bad", URI.create(site), LastModifiedLier.TYPE_BAD), null, null); //$NON-NLS-1$ // lie about length - httpService.registerServlet(root + "length/zero", new ContentLengthLier(root + "length/zero", URI.create(site), 0), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "length/less", new ContentLengthLier(root + "length/less", URI.create(site), 90), null, null); //$NON-NLS-1$//$NON-NLS-2$ - httpService.registerServlet(root + "length/more", new ContentLengthLier(root + "length/more", URI.create(site), 200), null, null); //$NON-NLS-1$//$NON-NLS-2$ + service.registerServlet(root + "length/zero", //$NON-NLS-1$ + new ContentLengthLier(root + "length/zero", URI.create(site), 0), null, null); //$NON-NLS-1$ + service.registerServlet(root + "length/less", //$NON-NLS-1$ + new ContentLengthLier(root + "length/less", URI.create(site), 90), null, null); //$NON-NLS-1$ + service.registerServlet(root + "length/more", //$NON-NLS-1$ + new ContentLengthLier(root + "length/more", URI.create(site), 200), null, null); //$NON-NLS-1$ } @@ -141,15 +176,16 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { return httpService; } - public void modifiedService(ServiceReference reference, Object service) { - // do nothing + @Override + public void modifiedService(ServiceReference<HttpService> reference, HttpService service) { + // do nothing } - public void removedService(ServiceReference reference, Object service) { - httpService = (HttpService) service; - httpService.unregister("/public"); //$NON-NLS-1$ - httpService.unregister("/private"); //$NON-NLS-1$ - httpService.unregister("/stats"); //$NON-NLS-1$ + @Override + public void removedService(ServiceReference<HttpService> reference, HttpService service) { + service.unregister("/public"); //$NON-NLS-1$ + service.unregister("/private"); //$NON-NLS-1$ + service.unregister("/stats"); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/AlwaysFailContext.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/AlwaysFailContext.java index 6d4711897..6fa5a1674 100644 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/AlwaysFailContext.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/AlwaysFailContext.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 @@ -17,16 +17,17 @@ import javax.servlet.http.HttpServletResponse; import org.osgi.service.http.HttpContext; /** - * The AlwaysFailContext can be used to add basic authentication to a path. - * This implementation will always fail (easier to test failure logic) this way. + * The AlwaysFailContext can be used to add basic authentication to a path. This + * implementation will always fail (easier to test failure logic) this way. */ public class AlwaysFailContext implements HttpContext { - private HttpContext theDefaultContext; + private final HttpContext theDefaultContext; public AlwaysFailContext(HttpContext defaultContext) { theDefaultContext = defaultContext; } + @Override public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) { // always fail response.setHeader("WWW-Authenticate", "BASIC realm=\"p2 Http Testing Server (Aladdin, open sesame)\""); //$NON-NLS-1$//$NON-NLS-2$ @@ -35,10 +36,12 @@ public class AlwaysFailContext implements HttpContext { } + @Override public String getMimeType(String name) { return theDefaultContext.getMimeType(name); } + @Override public URL getResource(String name) { return theDefaultContext.getResource(name); } diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/FlipFlopFailContext.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/FlipFlopFailContext.java index 2ac9e7d04..4d9f0acba 100644 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/FlipFlopFailContext.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/FlipFlopFailContext.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 @@ -17,18 +17,20 @@ import javax.servlet.http.HttpServletResponse; import org.osgi.service.http.HttpContext; /** - * The SecureContext can be used to add basic authentication to a path. - * It will fail on every other request to enable flaky server, or authentication testing. - * This implementation requires the user "Aladdin" to log in with the password "open sesame". + * The SecureContext can be used to add basic authentication to a path. It will + * fail on every other request to enable flaky server, or authentication + * testing. This implementation requires the user "Aladdin" to log in with the + * password "open sesame". */ public class FlipFlopFailContext implements HttpContext { - private HttpContext theDefaultContext; + private final HttpContext theDefaultContext; public static int flipFlop = 0; public FlipFlopFailContext(HttpContext defaultContext) { theDefaultContext = defaultContext; } + @Override public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) { String auth = request.getHeader("Authorization"); //$NON-NLS-1$ // Response is Aladdin:open sesame in Base64 encoding (from RFC example) @@ -42,10 +44,12 @@ public class FlipFlopFailContext implements HttpContext { } + @Override public String getMimeType(String name) { return theDefaultContext.getMimeType(name); } + @Override public URL getResource(String name) { return theDefaultContext.getResource(name); } diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/MimeLookup.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/MimeLookup.java index 71c09f80d..742ed299d 100644 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/MimeLookup.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/MimeLookup.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,22 +23,23 @@ public class MimeLookup { // treat names with multiple "." in a special way (currently only one) if (name.endsWith(JAR_PACK_GZ)) - return (String) extMap.get(JAR_PACK_GZ); + return extMap.get(JAR_PACK_GZ); int dot = name.lastIndexOf("."); //$NON-NLS-1$ - // get the suffix, use "a" for empty as this gives the default "application/octet-stream" + // get the suffix, use "a" for empty as this gives the default + // "application/octet-stream" String tmp = dot == -1 ? "a" : name.substring(dot + 1); //$NON-NLS-1$ - tmp = (String) extMap.get(tmp); + tmp = extMap.get(tmp); return tmp == null ? "application/octet-stream" : tmp; //$NON-NLS-1$ } - private static Map extMap; - private static Map mimeMap; + private static Map<String, String> extMap; + private static Map<String, String> mimeMap; public static void initNameToMime() { - extMap = new HashMap(data.length); + extMap = new HashMap<>(data.length); for (int i = 0; i < data.length; i += 2) { - Object key = data[i]; - Object val = extMap.get(key); + String key = data[i]; + String val = extMap.get(key); if (val == null) extMap.put(key, data[i]); } @@ -46,10 +47,10 @@ public class MimeLookup { } public static void initMimeToExt() { - mimeMap = new HashMap(data.length); + mimeMap = new HashMap<>(data.length); for (int i = 0; i < data.length; i += 2) { - Object key = data[i + 1]; - Object val = mimeMap.get(key); + String key = data[i + 1]; + String val = mimeMap.get(key); if (val == null) mimeMap.put(key, data[i]); } @@ -57,7 +58,7 @@ public class MimeLookup { } public final static String[] data = { // - //--- typical java related mime types - higher priority + // --- typical java related mime types - higher priority "bat", "text/plain", //$NON-NLS-1$ //$NON-NLS-2$ "batfrag", "text/plain", //$NON-NLS-1$ //$NON-NLS-2$ "class", "application/octet-stream", //$NON-NLS-1$ //$NON-NLS-2$ @@ -89,7 +90,7 @@ public class MimeLookup { "xmlfrag", "text/plain", //$NON-NLS-1$ //$NON-NLS-2$ "zip", "application/zip", //$NON-NLS-1$ //$NON-NLS-2$ - //--- misc definitions + // --- misc definitions "3dm", "x-world/x-3dmf", //$NON-NLS-1$ //$NON-NLS-2$ "3dmf", "x-world/x-3dmf", //$NON-NLS-1$ //$NON-NLS-2$ @@ -106,7 +107,7 @@ public class MimeLookup { "aifc", "audio/aiff", //$NON-NLS-1$ //$NON-NLS-2$ "aifc", "audio/x-aiff", //$NON-NLS-1$ //$NON-NLS-2$ "aiff", "audio/aiff", //$NON-NLS-1$ //$NON-NLS-2$ - "aiff", "audio/x-aiff", //$NON-NLS-1$ //$NON-NLS-2$ + "aiff", "audio/x-aiff", //$NON-NLS-1$ //$NON-NLS-2$ "aim", "application/x-aim", //$NON-NLS-1$ //$NON-NLS-2$ "aip", "text/x-audiosoft-intra", //$NON-NLS-1$ //$NON-NLS-2$ "ani", "application/x-navi-animation", //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureAction.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureAction.java index 483257843..2837d9ddd 100755 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureAction.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureAction.java @@ -26,11 +26,11 @@ import org.osgi.framework.Bundle; */ public class SecureAction { // make sure we use the correct controlContext; - private AccessControlContext controlContext; + private final AccessControlContext controlContext; /** - * Constructs a new SecureAction object. The constructed SecureAction object - * uses the caller's AccessControlContext to perform security checks + * Constructs a new SecureAction object. The constructed SecureAction object + * uses the caller's AccessControlContext to perform security checks */ public SecureAction() { // save the control context to be used. @@ -39,58 +39,48 @@ public class SecureAction { /** * Gets a resource from a bundle. + * * @param bundle the bundle to get the resource from - * @param name The name of the resource + * @param name The name of the resource * @return The URL of the resource */ - + public URL getBundleResource(final Bundle bundle, final String name) { if (System.getSecurityManager() == null) - return bundle.getResource(name); - return (URL) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return bundle.getResource(name); - } - }, controlContext); + return bundle.getResource(name); + return AccessController.doPrivileged((PrivilegedAction<URL>) () -> bundle.getResource(name), controlContext); } - + public URLConnection openURL(final URL url) throws IOException { if (System.getSecurityManager() == null) - return open(url); - try { - return (URLConnection) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { - return open(url); - } - }, controlContext); - } catch(PrivilegedActionException ex) { + return open(url); + try { + return AccessController.doPrivileged((PrivilegedExceptionAction<URLConnection>) () -> open(url), + controlContext); + } catch (PrivilegedActionException ex) { throw (IOException) ex.getException(); } - } - - URLConnection open(final URL url)throws IOException - { + } + + URLConnection open(final URL url) throws IOException { URLConnection connection = url.openConnection(); - connection.connect(); /* establish connection to check permissions */ - return connection; + connection.connect(); /* establish connection to check permissions */ + return connection; } - + /** - * Returns a system property. Same as calling - * System.getProperty(String,String). + * Returns a system property. Same as calling System.getProperty(String,String). + * * @param property the property key. - * @param def the default value if the property key does not exist. - * @return the value of the property or the def value if the property - * does not exist. + * @param def the default value if the property key does not exist. + * @return the value of the property or the def value if the property does not + * exist. */ public String getProperty(final String property, final String def) { if (System.getSecurityManager() == null) return System.getProperty(property, def); - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, def); - } - }, controlContext); + return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, def), + controlContext); } } diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureContext.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureContext.java index a9fc4e5f4..d4f295c0d 100644 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureContext.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecureContext.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 @@ -17,16 +17,18 @@ import javax.servlet.http.HttpServletResponse; import org.osgi.service.http.HttpContext; /** - * The SecureContext can be used to add basic authentication to a path. - * This implementation requires the user "Aladdin" to log in with the password "open sesame". + * The SecureContext can be used to add basic authentication to a path. This + * implementation requires the user "Aladdin" to log in with the password "open + * sesame". */ public class SecureContext implements HttpContext { - private HttpContext theDefaultContext; + private final HttpContext theDefaultContext; public SecureContext(HttpContext defaultContext) { theDefaultContext = defaultContext; } + @Override public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) { String auth = request.getHeader("Authorization"); //$NON-NLS-1$ // Response is Aladdin:open sesame in Base64 encoding (from RFC example) @@ -40,10 +42,12 @@ public class SecureContext implements HttpContext { } + @Override public String getMimeType(String name) { return theDefaultContext.getMimeType(name); } + @Override public URL getResource(String name) { return theDefaultContext.getResource(name); } diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecuredArtifactsContext.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecuredArtifactsContext.java index 4b627f6eb..9d66da4e9 100644 --- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecuredArtifactsContext.java +++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/SecuredArtifactsContext.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,8 +16,9 @@ import javax.servlet.http.HttpServletResponse; import org.osgi.service.http.HttpContext; /** - * The SecureContext can be used to add basic authentication to a path. - * This implementation requires the user "Aladdin" to log in with the password "open sesame". + * The SecureContext can be used to add basic authentication to a path. This + * implementation requires the user "Aladdin" to log in with the password "open + * sesame". */ public class SecuredArtifactsContext extends SecureContext { @@ -25,6 +26,7 @@ public class SecuredArtifactsContext extends SecureContext { super(defaultContext); } + @Override public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) { String path = request.getRequestURI(); if (path == null) 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); |