FELIX-2276: Authentication credentials for proxies are not set when retrieving resources
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@933677 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
index 4411dff..7e86c81 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
@@ -94,24 +94,9 @@
try
{
- // Do it the manual way to have a chance to
- // set request properties as proxy auth (EW).
- URLConnection conn = url.openConnection();
-
- // Support for http proxy authentication
- String auth = System.getProperty("http.proxyAuth");
- if ((auth != null) && (auth.length() > 0))
- {
- if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol()))
- {
- String base64 = Base64Encoder.base64Encode(auth);
- conn.setRequestProperty("Proxy-Authorization", "Basic " + base64);
- }
- }
-
if (url.getPath().endsWith(".zip"))
{
- ZipInputStream zin = new ZipInputStream(conn.getInputStream());
+ ZipInputStream zin = new ZipInputStream(FileUtil.openURL(url));
ZipEntry entry = zin.getNextEntry();
while (entry != null)
{
@@ -125,7 +110,7 @@
}
else
{
- is = conn.getInputStream();
+ is = FileUtil.openURL(url);
}
if (is != null)
@@ -464,7 +449,7 @@
}
private byte[] loadEntry(String name) throws IOException
{
- InputStream is = bundleUrl.openStream();
+ InputStream is = FileUtil.openURL(bundleUrl);
try
{
ZipInputStream jis = new ZipInputStream(is);
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FileUtil.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FileUtil.java
index e0cc607..17a18d0 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FileUtil.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FileUtil.java
@@ -18,7 +18,14 @@
*/
package org.apache.felix.bundlerepository.impl;
-import java.io.*;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.jar.JarEntry;
@@ -48,6 +55,7 @@
OutputStream os = new FileOutputStream(file);
URLConnection conn = srcURL.openConnection();
+ FileUtil.setProxyAuth(conn);
int total = conn.getContentLength();
InputStream is = conn.getInputStream();
@@ -167,4 +175,32 @@
}
bos.close();
}
+
+ public static void setProxyAuth(URLConnection conn) throws IOException {
+ // Support for http proxy authentication
+ String auth = System.getProperty("http.proxyAuth");
+ if ((auth != null) && (auth.length() > 0))
+ {
+ if ("http".equals(conn.getURL().getProtocol()) || "https".equals(conn.getURL().getProtocol()))
+ {
+ String base64 = Base64Encoder.base64Encode(auth);
+ conn.setRequestProperty("Proxy-Authorization", "Basic " + base64);
+ }
+ }
+
+ }
+
+ public static InputStream openURL(final URL url) throws IOException {
+ // Do it the manual way to have a chance to
+ // set request properties as proxy auth (EW).
+ return openURL(url.openConnection());
+ }
+
+ public static InputStream openURL(final URLConnection conn) throws IOException {
+ // Do it the manual way to have a chance to
+ // set request properties as proxy auth (EW).
+ setProxyAuth(conn);
+ return conn.getInputStream();
+ }
+
}
\ No newline at end of file
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
index 5d394e4..45ef6dc 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
@@ -560,7 +560,7 @@
localResource.getBundle().stop();
}
- localResource.getBundle().update(new URL(deployResources[i].getURI()).openStream());
+ localResource.getBundle().update(FileUtil.openURL(new URL(deployResources[i].getURI())));
// If necessary, save the updated bundle to be
// started later.
@@ -599,7 +599,7 @@
"obr://"
+ deployResources[i].getSymbolicName()
+ "/-" + System.currentTimeMillis(),
- url.openStream());
+ FileUtil.openURL(url));
// If necessary, save the installed bundle to be
// started later.