aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2015-11-06 14:33:27 +0300
committerGravatar Vitaly Takmazov2015-11-06 14:33:27 +0300
commitc6e5f4092997365a36b2acd8d2c445714e36c6a1 (patch)
treea0e3e2db7857604c1df3f41092fc73bf975cf5ea /src
parentcd5d2934288b03c7af6da2480f4b392498e77724 (diff)
try https downloads
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/http/www/NewMessage.java10
-rw-r--r--src/main/java/com/juick/http/www/Utils.java4
2 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java
index e2fe9629..d6ef22ee 100644
--- a/src/main/java/com/juick/http/www/NewMessage.java
+++ b/src/main/java/com/juick/http/www/NewMessage.java
@@ -33,6 +33,7 @@ import com.juick.xmpp.extensions.XOOB;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URL;
import java.net.URLEncoder;
import java.sql.Connection;
import java.util.ArrayList;
@@ -169,9 +170,10 @@ public class NewMessage {
}
String paramImg = request.getParameter("img");
- if (attachmentFName == null && paramImg != null && paramImg.length() > 12 && paramImg.startsWith("http://") && !paramImg.equals("http://")) {
+ if (attachmentFName == null && paramImg != null) {
try {
- attachmentFName = Utils.downloadImage(paramImg);
+ URL imgUrl = new URL(paramImg);
+ attachmentFName = Utils.downloadImage(imgUrl);
} catch (Exception e) {
System.out.println("DOWNLOAD ERROR: " + e.toString());
response.sendError(500);
@@ -326,9 +328,9 @@ public class NewMessage {
}
String paramImg = request.getParameter("img");
- if (attachmentFName == null && paramImg != null && paramImg.length() > 12 && paramImg.startsWith("http://") && !paramImg.equals("http://")) {
+ if (attachmentFName == null && paramImg != null) {
try {
- attachmentFName = Utils.downloadImage(paramImg);
+ attachmentFName = Utils.downloadImage(new URL(paramImg));
} catch (Exception e) {
System.out.println("DOWNLOAD ERROR: " + e.toString());
response.sendError(500);
diff --git a/src/main/java/com/juick/http/www/Utils.java b/src/main/java/com/juick/http/www/Utils.java
index afaf131e..e6fcad72 100644
--- a/src/main/java/com/juick/http/www/Utils.java
+++ b/src/main/java/com/juick/http/www/Utils.java
@@ -193,14 +193,14 @@ public class Utils {
}
}
- public static String downloadImage(String url) throws Exception {
+ public static String downloadImage(URL url) throws Exception {
String attachmentFName = null;
Exception ex = null;
InputStream is = null;
FileOutputStream fos = null;
try {
- URLConnection urlConn = new URL(url).openConnection();
+ URLConnection urlConn = url.openConnection();
is = urlConn.getInputStream();
String mime = urlConn.getContentType();