diff --git a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/BridgeServlet.java b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/BridgeServlet.java index 21159ba5ac2..baa3365f918 100644 --- a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/BridgeServlet.java +++ b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/BridgeServlet.java @@ -22,11 +22,12 @@ import javax.servlet.http.*; /** - * The BridgeServlet provides a means to bridge the servlet and OSGi - * runtimes. This class has 3 main responsibilities: - * 1) Control the lifecycle of the associated FrameworkLauncher in line with its own lifecycle - * 2) Provide a servlet "hook" that allows all servlet requests to be delegated to the registered servlet - * 3) Provide means to manually control the framework lifecycle + * The BridgeServlet provides a means to bridge the servlet and OSGi runtimes. + * This class has 3 main responsibilities: 1) Control the lifecycle of the + * associated FrameworkLauncher in line with its own lifecycle 2) Provide a + * servlet "hook" that allows all servlet requests to be delegated to the + * registered servlet 3) Provide means to manually control the framework + * lifecycle */ public class BridgeServlet extends HttpServlet { @@ -42,8 +43,9 @@ public class BridgeServlet extends HttpServlet { private boolean enableFrameworkControls; /** - * init() is called by the Servlet Container and used to instantiate the frameworkLauncher which MUST be an instance of FrameworkLauncher. - * After instantiating the framework init, deploy, and start are called. + * init() is called by the Servlet Container and used to instantiate the + * frameworkLauncher which MUST be an instance of FrameworkLauncher. After + * instantiating the framework init, deploy, and start are called. */ @Override public void init() throws ServletException { @@ -51,7 +53,8 @@ public void init() throws ServletException { enableFrameworkControls = Boolean.valueOf(getServletConfig().getInitParameter("enableFrameworkControls")); //$NON-NLS-1$ - // Use with caution!! Some classes MUST be initialized with the web-app class loader + // Use with caution!! Some classes MUST be initialized with the web-app class + // loader String frameworkPreloads = getServletConfig().getInitParameter("_contextPreloads"); //$NON-NLS-1$ if (frameworkPreloads != null) { StringTokenizer st = new StringTokenizer(frameworkPreloads, ","); //$NON-NLS-1$ @@ -69,7 +72,8 @@ public void init() throws ServletException { } // Forces load of the SSLSocketFactory on the web-app context class loader - boolean initSSLSocketFactory = Optional.ofNullable(getServletConfig().getInitParameter("_initSSLSocketFactory")).map(Boolean::valueOf).orElse(true); //$NON-NLS-1$ + boolean initSSLSocketFactory = Optional.ofNullable(getServletConfig().getInitParameter("_initSSLSocketFactory")) //$NON-NLS-1$ + .map(Boolean::valueOf).orElse(true); if (initSSLSocketFactory) { try { Class> clazz = this.getClass().getClassLoader().loadClass("javax.net.ssl.SSLSocketFactory"); //$NON-NLS-1$ @@ -84,7 +88,8 @@ public void init() throws ServletException { String frameworkLauncherClassParameter = getServletConfig().getInitParameter("frameworkLauncherClass"); //$NON-NLS-1$ if (frameworkLauncherClassParameter != null) { try { - Class> frameworkLauncherClass = this.getClass().getClassLoader().loadClass(frameworkLauncherClassParameter); + Class> frameworkLauncherClass = this.getClass().getClassLoader() + .loadClass(frameworkLauncherClassParameter); framework = (FrameworkLauncher) frameworkLauncherClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new ServletException(e); @@ -107,7 +112,8 @@ public void init() throws ServletException { } /** - * destroy() is called by the Servlet Container and used to first stop and then destroy the framework. + * destroy() is called by the Servlet Container and used to first stop and then + * destroy the framework. */ @Override public void destroy() { @@ -118,9 +124,10 @@ public void destroy() { } /** - * service is called by the Servlet Container and will first determine if the request is a - * framework control and will otherwise try to delegate to the registered servlet delegate - * + * service is called by the Servlet Container and will first determine if the + * request is a framework control and will otherwise try to delegate to the + * registered servlet delegate + * */ @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -175,12 +182,12 @@ private boolean isExtensionMapping(String servletPath) { } /** - * serviceFrameworkControls currently supports the following commands (identified by the request's pathinfo) - * sp_deploy - Copies the contents of the Equinox application to the install area - * sp_undeploy - Removes the copy of the Equinox application from the install area - * sp_redeploy - Resets the platform (e.g. stops, undeploys, deploys, starts) - * sp_start - Starts a deployed platform - * sp_stop - Stops the platform + * serviceFrameworkControls currently supports the following commands + * (identified by the request's pathinfo) sp_deploy - Copies the contents of the + * Equinox application to the install area sp_undeploy - Removes the copy of the + * Equinox application from the install area sp_redeploy - Resets the platform + * (e.g. stops, undeploys, deploys, starts) sp_start - Starts a deployed + * platform sp_stop - Stops the platform */ @SuppressWarnings("resource") private boolean serviceFrameworkControls(HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -241,10 +248,11 @@ private synchronized HttpServlet acquireDelegateReference() { } /** - * registerServletDelegate is the hook method called from inside the OSGi runtime to register - * a servlet for which all future servlet calls will be delegated. If not null and no delegate - * is currently registered, init(ServletConfig) will be called on the servletDelegate before - * returning. + * registerServletDelegate is the hook method called from inside the OSGi + * runtime to register a servlet for which all future servlet calls will be + * delegated. If not null and no delegate is currently registered, + * init(ServletConfig) will be called on the servletDelegate before returning. + * * @param servletDelegate - the servlet to register for delegation */ public static synchronized void registerServletDelegate(HttpServlet servletDelegate) { @@ -271,9 +279,12 @@ public static synchronized void registerServletDelegate(HttpServlet servletDeleg } /** - * unregisterServletDelegate is the hook method called from inside the OSGi runtime to unregister a delegate. - * If the servletDelegate matches the current registered delegate destroy() is called on the servletDelegate. - * destroy() will not be called until the delegate is finished servicing any previous requests. + * unregisterServletDelegate is the hook method called from inside the OSGi + * runtime to unregister a delegate. If the servletDelegate matches the current + * registered delegate destroy() is called on the servletDelegate. destroy() + * will not be called until the delegate is finished servicing any previous + * requests. + * * @param servletDelegate - the servlet to unregister */ public static synchronized void unregisterServletDelegate(HttpServlet servletDelegate) { diff --git a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java index 464e1d68981..410d649050a 100644 --- a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java +++ b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java @@ -40,7 +40,8 @@ public class CloseableURLClassLoader extends URLClassLoader { static { boolean registeredAsParallel; try { - Method parallelCapableMetod = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", (Class[]) null); //$NON-NLS-1$ + Method parallelCapableMetod = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", //$NON-NLS-1$ + (Class[]) null); parallelCapableMetod.setAccessible(true); registeredAsParallel = ((Boolean) parallelCapableMetod.invoke(null, (Object[]) null)).booleanValue(); } catch (Throwable e) { @@ -96,8 +97,7 @@ public InputStream getInputStream() throws IOException { } /** - * @throws IOException - * Documented to avoid warning + * @throws IOException Documented to avoid warning */ @Override public JarFile getJarFile() throws IOException { @@ -173,7 +173,7 @@ public CloseableURLClassLoader(URL[] urls) { } /** - * @param urls the URLs from which to load classes and resources + * @param urls the URLs from which to load classes and resources * @param parent the parent class loader used for delegation * @see URLClassLoader */ @@ -182,14 +182,16 @@ public CloseableURLClassLoader(URL[] urls, ClassLoader parent) { } /** - * @param urls the URLs from which to load classes and resources - * @param parent the parent class loader used for delegation - * @param verifyJars flag to determine if jar file verification should be performed + * @param urls the URLs from which to load classes and resources + * @param parent the parent class loader used for delegation + * @param verifyJars flag to determine if jar file verification should be + * performed * @see URLClassLoader */ public CloseableURLClassLoader(URL[] urls, ClassLoader parent, boolean verifyJars) { super(excludeFileJarURLS(urls), parent); - this.registeredAsParallel = CLOSEABLE_REGISTERED_AS_PARALLEL && this.getClass() == CloseableURLClassLoader.class; + this.registeredAsParallel = CLOSEABLE_REGISTERED_AS_PARALLEL + && this.getClass() == CloseableURLClassLoader.class; this.context = AccessController.getContext(); this.verifyJars = verifyJars; for (URL url : urls) { @@ -202,7 +204,8 @@ public CloseableURLClassLoader(URL[] urls, ClassLoader parent, boolean verifyJar // @GuardedBy("loaders") private boolean safeAddLoader(URL url) { - //assume all illegal characters have been properly encoded, so use URI class to unencode + // assume all illegal characters have been properly encoded, so use URI class to + // unencode try { File file = new File(toURI(url)); if (file.exists()) { @@ -224,13 +227,15 @@ private static URI toURI(URL url) throws URISyntaxException { if (!SCHEME_FILE.equals(url.getProtocol())) { throw new IllegalArgumentException("bad prototcol: " + url.getProtocol()); //$NON-NLS-1$ } - //URL behaves differently across platforms so for file: URLs we parse from string form + // URL behaves differently across platforms so for file: URLs we parse from + // string form String pathString = url.toExternalForm().substring(5); - //ensure there is a leading slash to handle common malformed URLs such as file:c:/tmp + // ensure there is a leading slash to handle common malformed URLs such as + // file:c:/tmp if (pathString.indexOf('/') != 0) pathString = '/' + pathString; else if (pathString.startsWith(UNC_PREFIX) && !pathString.startsWith(UNC_PREFIX, 2)) { - //URL encodes UNC path with two slashes, but URI uses four (see bug 207103) + // URL encodes UNC path with two slashes, but URI uses four (see bug 207103) pathString = ensureUNCPath(pathString); } return new URI(SCHEME_FILE, null, pathString, null); @@ -243,7 +248,7 @@ private static String ensureUNCPath(String path) { int len = path.length(); StringBuilder result = new StringBuilder(len); for (int i = 0; i < 4; i++) { - // if we have hit the first non-slash character, add another leading slash + // if we have hit the first non-slash character, add another leading slash if (i >= len || result.length() > 0 || path.charAt(i) != '/') result.append('/'); } @@ -362,7 +367,8 @@ private void checkForSealedPackage(Package pkg, String packageName, Manifest man // previously sealed case if (!pkg.isSealed(jarFileURL)) { // this URL does not seal; ERROR - throw new SecurityException("The package '" + packageName + "' was previously loaded and is already sealed."); //$NON-NLS-1$ //$NON-NLS-2$ + throw new SecurityException( + "The package '" + packageName + "' was previously loaded and is already sealed."); //$NON-NLS-1$ //$NON-NLS-2$ } } else { // previously unsealed case @@ -378,8 +384,10 @@ private void checkForSealedPackage(Package pkg, String packageName, Manifest man sealed = mainAttributes.getValue(Name.SEALED); } if (Boolean.valueOf(sealed).booleanValue()) { - // this manifest attempts to seal when package defined previously unsealed; ERROR - throw new SecurityException("The package '" + packageName + "' was previously loaded unsealed. Cannot seal package."); //$NON-NLS-1$ //$NON-NLS-2$ + // this manifest attempts to seal when package defined previously unsealed; + // ERROR + throw new SecurityException( + "The package '" + packageName + "' was previously loaded unsealed. Cannot seal package."); //$NON-NLS-1$ //$NON-NLS-2$ } } } @@ -432,8 +440,9 @@ public Object run() { } /** - * The "close" method is called when the class loader is no longer needed and we should close any open resources. - * In particular this method will close the jar files associated with this class loader. + * The "close" method is called when the class loader is no longer needed and we + * should close any open resources. In particular this method will close the jar + * files associated with this class loader. */ @Override public void close() { diff --git a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java index effeb2a1e1b..555985cf965 100644 --- a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java +++ b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java @@ -38,10 +38,10 @@ *
<0
if left < right;
- * 0
if left == right;
- * >0
if left > right;
+ * @return result of comparison, as integer; <0
if left < right;
+ * 0
if left == right; >0
if left > right;
*/
private int compareVersion(Object[] left, Object[] right) {
@@ -942,18 +971,20 @@ private int compareVersion(Object[] left, Object[] right) {
}
/**
- * Do a quick parse of version identifier so its elements can be correctly compared.
- * If we are unable to parse the full version, remaining elements are initialized
- * with suitable defaults.
+ * Do a quick parse of version identifier so its elements can be correctly
+ * compared. If we are unable to parse the full version, remaining elements are
+ * initialized with suitable defaults.
+ *
* @param version
- * @return an array of size 4; first three elements are of type Integer (representing
- * major, minor and service) and the fourth element is of type String (representing
- * qualifier). Note, that returning anything else will cause exceptions in the caller.
+ * @return an array of size 4; first three elements are of type Integer
+ * (representing major, minor and service) and the fourth element is of
+ * type String (representing qualifier). Note, that returning anything
+ * else will cause exceptions in the caller.
*/
private Object[] getVersionElements(String version) {
if (version.endsWith(DOT_JAR))
version = version.substring(0, version.length() - 4);
- Object[] result = {Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), ""}; //$NON-NLS-1$
+ Object[] result = { Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), "" }; //$NON-NLS-1$
StringTokenizer t = new StringTokenizer(version, "."); //$NON-NLS-1$
String token;
int i = 0;
@@ -976,9 +1007,10 @@ private Object[] getVersionElements(String version) {
}
/**
- * The ChildFirstURLClassLoader alters regular ClassLoader delegation and will check the URLs
- * used in its initialization for matching classes before delegating to it's parent.
- * Sometimes also referred to as a ParentLastClassLoader
+ * The ChildFirstURLClassLoader alters regular ClassLoader delegation and will
+ * check the URLs used in its initialization for matching classes before
+ * delegating to it's parent. Sometimes also referred to as a
+ * ParentLastClassLoader
*/
protected static class ChildFirstURLClassLoader extends CloseableURLClassLoader {
private static final boolean CHILDFIRST_REGISTERED_AS_PARALLEL;
@@ -986,7 +1018,8 @@ protected static class ChildFirstURLClassLoader extends CloseableURLClassLoader
static {
boolean registeredAsParallel;
try {
- Method parallelCapableMetod = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", (Class[]) null); //$NON-NLS-1$
+ Method parallelCapableMetod = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", //$NON-NLS-1$
+ (Class[]) null);
parallelCapableMetod.setAccessible(true);
registeredAsParallel = ((Boolean) parallelCapableMetod.invoke(null, (Object[]) null)).booleanValue();
} catch (Throwable e) {