Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 69566 Details for
Bug 190279
[server] [plan] Problems cleaning up when undeploying Servletbrdige WAR
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
FrameworkLauncher using a non-locking resource ClassLoader for the framework classloader
190279.patch (text/plain), 10.63 KB, created by
Richard Backhouse
on 2007-05-31 14:01:20 EDT
(
hide
)
Description:
FrameworkLauncher using a non-locking resource ClassLoader for the framework classloader
Filename:
MIME Type:
Creator:
Richard Backhouse
Created:
2007-05-31 14:01:20 EDT
Size:
10.63 KB
patch
obsolete
>Index: src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java,v >retrieving revision 1.12 >diff -u -r1.12 FrameworkLauncher.java >--- src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java 23 May 2007 21:09:53 -0000 1.12 >+++ src/org/eclipse/equinox/servletbridge/FrameworkLauncher.java 31 May 2007 17:45:33 -0000 >@@ -104,7 +104,7 @@ > protected ServletContext context; > private File platformDirectory; > private ClassLoader frameworkContextClassLoader; >- private URLClassLoader frameworkClassLoader; >+ private ClassLoader frameworkClassLoader; > > void init(ServletConfig servletConfig) { > config = servletConfig; >@@ -245,7 +245,7 @@ > System.setProperty("osgi.framework.useSystemProperties", "false"); //$NON-NLS-1$ //$NON-NLS-2$ > > URL[] osgiURLArray = {new URL((String) initalPropertyMap.get(OSGI_FRAMEWORK))}; >- frameworkClassLoader = new ChildFirstURLClassLoader(osgiURLArray, this.getClass().getClassLoader()); >+ frameworkClassLoader = new JarEntryClassLoader(osgiURLArray, this.getClass().getClassLoader()); > Class clazz = frameworkClassLoader.loadClass(STARTER); > > Method setInitialProperties = clazz.getMethod("setInitialProperties", new Class[] {Map.class}); //$NON-NLS-1$ >Index: src/org/eclipse/equinox/servletbridge/JarEntryURLStreamHandler.java >=================================================================== >RCS file: src/org/eclipse/equinox/servletbridge/JarEntryURLStreamHandler.java >diff -N src/org/eclipse/equinox/servletbridge/JarEntryURLStreamHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/servletbridge/JarEntryURLStreamHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+package org.eclipse.equinox.servletbridge; >+ >+import java.io.IOException; >+import java.net.*; >+ >+public class JarEntryURLStreamHandler extends URLStreamHandler { >+ >+ protected URLConnection openConnection(URL url) throws IOException { >+ URLConnection connection = new JarEntryURLConnection(url); >+ connection.connect(); >+ return connection; >+ } >+ >+ protected void parseURL(URL url, String spec, int start, int limit) { >+ setURL(url, "jarentry", null, 0, null, null, spec.substring(start, limit), null, null); >+ } >+} >Index: src/org/eclipse/equinox/servletbridge/JarEntryClassLoader.java >=================================================================== >RCS file: src/org/eclipse/equinox/servletbridge/JarEntryClassLoader.java >diff -N src/org/eclipse/equinox/servletbridge/JarEntryClassLoader.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/servletbridge/JarEntryClassLoader.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,172 @@ >+package org.eclipse.equinox.servletbridge; >+ >+import java.io.*; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.security.*; >+import java.util.*; >+import java.util.jar.JarEntry; >+import java.util.jar.JarFile; >+ >+public class JarEntryClassLoader extends SecureClassLoader { >+ private List entries = null; >+ private URL osgiFrameworkURL = null; >+ private JarEntryURLStreamHandler jarEntryURLStreamHandler = null; >+ >+ public JarEntryClassLoader(URL[] osgiFrameworkURLs, ClassLoader parent) { >+ super(parent); >+ jarEntryURLStreamHandler = new JarEntryURLStreamHandler(); >+ this.osgiFrameworkURL = osgiFrameworkURLs[0]; // Expect only one framework jar >+ entries = new ArrayList(); >+ JarFile jarFile = null; >+ >+ try { >+ jarFile = new JarFile(new File(osgiFrameworkURL.toURI())); >+ JarEntry je = null; >+ Enumeration e = jarFile.entries(); >+ while (e.hasMoreElements()) { >+ je = (JarEntry)e.nextElement(); >+ if (!je.isDirectory()) { >+ entries.add(je.getName()); >+ } >+ } >+ } >+ catch (Exception e) { >+ e.printStackTrace(); >+ } >+ finally { >+ try {jarFile.close();} catch (IOException e) {} >+ } >+ } >+ >+ protected void addURL(URL url) { >+ >+ } >+ >+ protected synchronized Class findClass(String name) throws ClassNotFoundException { >+ String className = name.replace('.', '/'); >+ if (entries.contains(className+".class")) { >+ InputStream is = null; >+ try { >+ URL url = new URL("jarentry", null, 0, osgiFrameworkURL.toExternalForm()+"!/"+className+".class", jarEntryURLStreamHandler); >+ is = url.openStream(); >+ byte[] buffer = new byte[4096]; >+ ByteArrayOutputStream baos = new ByteArrayOutputStream(); >+ int len = 0; >+ while ((len = is.read(buffer, 0, 4096)) != -1) { >+ baos.write(buffer, 0, len); >+ } >+ byte[] bytes = baos.toByteArray(); >+ return defineClass(name, bytes, 0, bytes.length); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ } finally { >+ try {if (is != null) { is.close(); } }catch(IOException e){} >+ } >+ } >+ throw new ClassNotFoundException(name); >+ } >+ >+ protected URL findResource(String name) { >+ URL resource = null; >+ >+ if (entries.contains(name) || entries.contains("/"+name)) { >+ if (name.charAt(0) != '/') >+ name = "/"+name; >+ try { >+ resource = new URL("jarentry", null, 0, osgiFrameworkURL.toExternalForm()+"!"+name, jarEntryURLStreamHandler); >+ } catch (MalformedURLException e) { >+ resource = null; >+ } >+ } >+ return resource; >+ } >+ >+ public Enumeration findResources (String name) throws IOException { >+ List resources = new ArrayList(); >+ for (Iterator itr = entries.iterator(); itr.hasNext();) { >+ String resource = (String)itr.next(); >+ if (resource.endsWith(name)) { >+ if (resource.charAt(0) != '/') { >+ resource = "/"+resource; >+ } >+ URL url = new URL("jarentry", null, 0, osgiFrameworkURL.toExternalForm()+"!"+resource, jarEntryURLStreamHandler); >+ resources.add(url); >+ } >+ } >+ return Collections.enumeration(resources); >+ } >+ >+ public URL getResource(String name) { >+ URL resource = findResource(name); >+ if (resource == null) { >+ ClassLoader parent = getParent(); >+ if (parent != null) >+ resource = parent.getResource(name); >+ } >+ return resource; >+ } >+ >+ protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { >+ Class clazz = findLoadedClass(name); >+ if (clazz == null) { >+ try { >+ clazz = findClass(name); >+ } catch (ClassNotFoundException e) { >+ ClassLoader parent = getParent(); >+ if (parent != null) >+ clazz = parent.loadClass(name); >+ else >+ clazz = getSystemClassLoader().loadClass(name); >+ } >+ } >+ >+ if (resolve) >+ resolveClass(clazz); >+ >+ return clazz; >+ } >+ >+ static final PermissionCollection allPermissions = new PermissionCollection() { >+ private static final long serialVersionUID = 482874725021998286L; >+ // The AllPermission permission >+ Permission allPermission = new AllPermission(); >+ >+ // A simple PermissionCollection that only has AllPermission >+ public void add(Permission permission) { >+ // do nothing >+ } >+ >+ public boolean implies(Permission permission) { >+ return true; >+ } >+ >+ public Enumeration elements() { >+ return new Enumeration() { >+ int cur = 0; >+ >+ public boolean hasMoreElements() { >+ return cur < 1; >+ } >+ >+ public Object nextElement() { >+ if (cur == 0) { >+ cur = 1; >+ return allPermission; >+ } >+ throw new NoSuchElementException(); >+ } >+ }; >+ } >+ }; >+ >+ static { >+ // We do this to ensure the anonymous Enumeration class in allPermissions is pre-loaded >+ if (allPermissions.elements() == null) >+ throw new IllegalStateException(); >+ } >+ >+ protected PermissionCollection getPermissions(CodeSource codesource) { >+ return allPermissions; >+ } >+} >Index: src/org/eclipse/equinox/servletbridge/JarEntryURLConnection.java >=================================================================== >RCS file: src/org/eclipse/equinox/servletbridge/JarEntryURLConnection.java >diff -N src/org/eclipse/equinox/servletbridge/JarEntryURLConnection.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/servletbridge/JarEntryURLConnection.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+package org.eclipse.equinox.servletbridge; >+ >+import java.io.*; >+import java.net.URL; >+import java.net.URLConnection; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipFile; >+ >+public class JarEntryURLConnection extends URLConnection { >+ private boolean connected = false; >+ private URL url = null;; >+ >+ public JarEntryURLConnection(URL url) { >+ super(url); >+ this.url = url; >+ } >+ >+ public synchronized void connect() throws IOException { >+ if (connected) { >+ return; >+ } >+ connected = true; >+ } >+ >+ public InputStream getInputStream() { >+ ZipFile zipFile = null; >+ InputStream is = null; >+ InputStream zis = null; >+ try >+ { >+ String file = url.getFile(); >+ int bang = file.indexOf('!'); >+ String name = file.substring(bang+2); >+ file = file.substring(5, bang); >+ zipFile = new ZipFile(file); >+ ZipEntry zipEntry = zipFile.getEntry(name); >+ ByteArrayOutputStream baos = new ByteArrayOutputStream(); >+ zis = zipFile.getInputStream(zipEntry); >+ byte[] buf = new byte[4096]; >+ int len; >+ while ((len = zis.read(buf)) != -1) { >+ baos.write(buf, 0, len); >+ } >+ is = new ByteArrayInputStream(baos.toByteArray()); >+ } >+ catch ( Exception e ) { >+ e.printStackTrace(); >+ } >+ finally { >+ if (zis != null) try{zis.close();}catch(IOException e){} >+ if (zipFile != null) try{zipFile.close();}catch(IOException e){} >+ } >+ return is; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 190279
: 69566 |
115044
|
115535
|
115574
|
115926