-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
[1.8.0] memoryCacheExtraOptions affixes the values to the Uri (https) #188
Comments
http://stackoverflow.com/questions/14789716/android-universal-image-loader-change-hxw-url-parameters Maybe you have the problem with https, try this class: public class AuthImageDownloader extends BaseImageDownloader {
public static final String TAG = AuthImageDownloader.class.getName();
public AuthImageDownloader(Context context, int connectTimeout, int readTimeout) {
super(context, connectTimeout, readTimeout);
}
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
URL url = null;
try {
url = new URL(imageUri);
} catch (MalformedURLException e) {
Log.e(TAG, e.getMessage(), e);
}
HttpURLConnection http = null;
if (Scheme.ofUri(imageUri) == Scheme.HTTPS) {
trustAllHosts();
HttpsURLConnection https = (HttpsURLConnection) url
.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
http = https;
http.connect();
} else {
http = (HttpURLConnection) url.openConnection();
}
http.setConnectTimeout(connectTimeout);
http.setReadTimeout(readTimeout);
return new FlushedInputStream(new BufferedInputStream(
http.getInputStream()));
}
// always verify the host - dont check for certificate
final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
/**
* Trust every server - dont check for any certificate
*/
private static void trustAllHosts() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] x509Certificates,
String s) throws java.security.cert.CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] x509Certificates,
String s) throws java.security.cert.CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection
.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Nothing to do with SSL, this line actually returns an affixed Url which is why the image loader fails. @Override
protected InputStream getStreamFromNetwork(URI imageUri, Object extra) throws IOException {
Log.d(TAG, "URL="+imageUri.toString());
//...
} I will look at fixing it in my fork. Seems that a certain flow makes it prefix to the wrong parts of the request. |
Did you found the reason? |
I haven't had chance going to investigate this weekend
|
Hello @nostra13 and @chrisjenx, I have a similar problem, Universal Image Downloader and SSL. I want use the class you post before, but in the point to override getStreamFromNetwork:
Happens this error, and i'm not sure how to fix: The method getStreamFromNetwork(URI, Object) of type AuthImageDownloader must override or implement a supertype method The quick fix is remove "@OverRide" annotation. But of course don't works. Thanks. |
Just check that the correct method being overridden. If eclipse is throwing an error on the override annotation it means that you are not overriding/extending the correct class thus the error. |
|
Great, now works perfect. Thanks, Is incredible how both answer so fast. ^^ |
This is my work around to the above bug: package com.bizzby.http.requests;
import android.content.Context;
import android.text.TextUtils;
import com.bizzby.utils.QLog;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.*;
import com.nostra13.universalimageloader.core.assist.FlushedInputStream;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created with Intellij with Android, BIZZBY product.
* See licencing for usage of this code.
* <p/>
* User: chris
* Date: 01/03/2013
* Time: 15:45
*/
public class GoogleImageDownloader extends BaseImageDownloader
{
protected static final Pattern SIZE_PATTERN = Pattern.compile("(_[0-9]+(_|x)[0-9]+)$", Pattern.CASE_INSENSITIVE);
public static HttpTransport sHttpTransport;
public static HttpRequestFactory sHttpRequestFactory;
public static HttpRequest getHttpRequest(final String uri) throws IOException
{
if (sHttpTransport == null) sHttpTransport = AndroidHttp.newCompatibleTransport();
if (sHttpRequestFactory == null) sHttpRequestFactory = sHttpTransport.createRequestFactory();
return sHttpRequestFactory.buildGetRequest(new GenericUrl(uri));
}
private static String replaceLast(final String string, final String from, final String to)
{
int lastIndex = string.lastIndexOf(from);
if (lastIndex < 0) return string;
final String tail = string.substring(lastIndex).replaceFirst(from, to);
return string.substring(0, lastIndex) + tail;
}
static String stripSizeOffUrl(final String string)
{
if (TextUtils.isEmpty(string)) return string;
final Matcher matcher = SIZE_PATTERN.matcher(string);
String group = "";
while (matcher.find())
{
group = matcher.group(1);
}
return replaceLast(string, group, "");
}
public GoogleImageDownloader(final Context context)
{
super(context);
}
public GoogleImageDownloader(final Context context, final int connectTimeout, final int readTimeout)
{
super(context, connectTimeout, readTimeout);
}
@Override
protected InputStream getStreamFromContent(URI imageUri, final Object extra) throws FileNotFoundException
{
imageUri = URI.create(stripSizeOffUrl(imageUri.toString()));
return super.getStreamFromContent(imageUri, extra);
}
@Override
protected InputStream getStreamFromNetwork(final URI imageUri, final Object extra) throws IOException
{
if (null == imageUri) return null;
final String url = stripSizeOffUrl(imageUri.toString());
QLog.i("ImageLoader, Downloading [" + url + "]");
final HttpRequest request = getHttpRequest(url);
request.setConnectTimeout(connectTimeout);
request.setReadTimeout(readTimeout);
final HttpResponse response = request.execute();
if (response != null && response.isSuccessStatusCode())
{
return new FlushedInputStream(response.getContent(), BUFFER_SIZE);
}
return null;
}
} The cause of this is still on my list todo. |
Im having this issue too - this is no fun - and why is this thread marked closed? |
oh sorry, my bad |
@chrisjenx bug fix works great for
|
Still can't understand how it could happen. |
Nostra, i am having problems with https and your solution posted above (using AuthImageDownloader class).
I am missing something? What are the needed imports for above code? |
You should use this authorization only if you need. I guess you don't. I updated |
Works! I used code below to make it work:
Thank you very much for your quick answer. |
I see this is closed - does it now not append the dimensions to the end of the URL? |
It didn't append the dimensions before. I couldn't reproduce the bug and couldn't imagine why it can happen. chrisjenx promised to look into it but he didn't I guess. If you have this bug then you can send me your project with this bug so I'll look into it. |
This bug is still very active. I'm out of the county so no chance to fix. Chris.
|
Got this issue with 1.9.3 and https in link. Use AuthImageDownloader from your comment. |
As suggested, I tried to use AuthImageDownloader to ignore SSL cert error. But from log cat, it seems that AuthImageDownloader override method is not being called and i still get same ssl error. |
Got this issue with 1.9.4....How to solve it??? |
Have anyone found a fix? I need it ASAP. |
@nostra13 Your code works well, thanks |
I'm using .memoryCacheExtraOptions(512, 512)
I'm not sure if this is the desired effect but by doing this when performing webrequests it now affixes the size to the end of the image.
https://d3jpl91pxevbkh.cloudfront.net/notha/image/upload/v1360769665/1.png
becomes
https://d3jpl91pxevbkh.cloudfront.net/notha/image/upload/v1360769665/1.png_512x512
Which of course fails loading.
Cheers,
Chris
The text was updated successfully, but these errors were encountered: