-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WW-4901 Decouples from URL.openConnection implementation of container #190
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.opensymphony.xwork2.util.fs; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.JarURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedActionException; | ||
import java.security.PrivilegedExceptionAction; | ||
import java.util.jar.JarFile; | ||
|
||
/** | ||
* WW-4901 Decouples Struts from {@link URL#openConnection()} implementation of container (e.g. IBM WebSphere com.ibm.ws.classloader.Handler$ClassLoaderURLConnection) | ||
* @since 2.5.15 | ||
*/ | ||
class StrutsJarURLConnection extends JarURLConnection { | ||
private JarFile jarFile; | ||
|
||
StrutsJarURLConnection(URL url) throws MalformedURLException { | ||
super(url); | ||
} | ||
|
||
@Override | ||
public JarFile getJarFile() throws IOException { | ||
connect(); | ||
return jarFile; | ||
} | ||
|
||
@Override | ||
public void connect() throws IOException { | ||
if (connected) | ||
return; | ||
|
||
try (final InputStream in = getJarFileURL().openConnection().getInputStream()) { | ||
jarFile = AccessController.doPrivileged( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much for your attention 👍 fixed :) |
||
new PrivilegedExceptionAction<JarFile>() { | ||
public JarFile run() throws IOException { | ||
Path tmpFile = Files.createTempFile("jar_cache", null); | ||
try { | ||
Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING); | ||
JarFile jarFile = new JarFile(tmpFile.toFile(), true, JarFile.OPEN_READ); | ||
tmpFile.toFile().deleteOnExit(); | ||
return jarFile; | ||
} catch (Throwable thr) { | ||
try { | ||
Files.delete(tmpFile); | ||
} catch (IOException ioe) { | ||
thr.addSuppressed(ioe); | ||
} | ||
throw thr; | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
}); | ||
connected = true; | ||
} catch (PrivilegedActionException pae) { | ||
throw (IOException) pae.getException(); | ||
} | ||
} | ||
|
||
void disconnect() { | ||
if (connected) { | ||
connected = false; | ||
try { | ||
jarFile.close(); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍