Skip to content

Commit

Permalink
Use 'HttpsURLConnection' when fetching the image stream. Fix #146
Browse files Browse the repository at this point in the history
  • Loading branch information
boncey committed Aug 2, 2015
1 parent cc269ff commit 82bd451
Showing 1 changed file with 45 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import org.w3c.dom.NodeList;

import javax.imageio.ImageIO;
import javax.net.ssl.HttpsURLConnection;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -188,10 +188,10 @@ public void delete(String photoId) throws FlickrException {
* @throws FlickrException
*/
public PhotoAllContext getAllContexts(String photoId) throws FlickrException {
PhotoSetList<PhotoSet> setList = new PhotoSetList<PhotoSet>();
PoolList<Pool> poolList = new PoolList<Pool>();
PhotoAllContext allContext = new PhotoAllContext();
PhotoSetList<PhotoSet> setList = new PhotoSetList<PhotoSet>();
PoolList<Pool> poolList = new PoolList<Pool>();
PhotoAllContext allContext = new PhotoAllContext();

Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_GET_ALL_CONTEXTS);

Expand All @@ -203,35 +203,35 @@ public PhotoAllContext getAllContexts(String photoId) throws FlickrException {
}
Collection<Element> photosElement = response.getPayloadCollection();

for (Element setElement : photosElement) {
if(setElement.getTagName().equals("set")){
PhotoSet pset = new PhotoSet();
pset.setTitle(setElement.getAttribute("title"));
pset.setSecret(setElement.getAttribute("secret"));
pset.setId(setElement.getAttribute("id"));
pset.setFarm(setElement.getAttribute("farm"));
pset.setPrimary(setElement.getAttribute("primary"));
pset.setServer(setElement.getAttribute("server"));
pset.setViewCount(Integer.parseInt(setElement.getAttribute("view_count")));
pset.setCommentCount(Integer.parseInt(setElement.getAttribute("comment_count")));
pset.setCountPhoto(Integer.parseInt(setElement.getAttribute("count_photo")));
pset.setCountVideo(Integer.parseInt(setElement.getAttribute("count_video")));
setList.add(pset);
allContext.setPhotoSetList(setList);
}else if(setElement.getTagName().equals("pool")){
Pool pool = new Pool();
pool.setTitle(setElement.getAttribute("title"));
pool.setId(setElement.getAttribute("id"));
pool.setUrl(setElement.getAttribute("url"));
pool.setIconServer(setElement.getAttribute("iconserver"));
pool.setIconFarm(setElement.getAttribute("iconfarm"));
pool.setMemberCount(Integer.parseInt(setElement.getAttribute("members")));
pool.setPoolCount(Integer.parseInt(setElement.getAttribute("pool_count")));
poolList.add(pool);
allContext.setPoolList(poolList);
}
}
for (Element setElement : photosElement) {
if (setElement.getTagName().equals("set")) {
PhotoSet pset = new PhotoSet();
pset.setTitle(setElement.getAttribute("title"));
pset.setSecret(setElement.getAttribute("secret"));
pset.setId(setElement.getAttribute("id"));
pset.setFarm(setElement.getAttribute("farm"));
pset.setPrimary(setElement.getAttribute("primary"));
pset.setServer(setElement.getAttribute("server"));
pset.setViewCount(Integer.parseInt(setElement.getAttribute("view_count")));
pset.setCommentCount(Integer.parseInt(setElement.getAttribute("comment_count")));
pset.setCountPhoto(Integer.parseInt(setElement.getAttribute("count_photo")));
pset.setCountVideo(Integer.parseInt(setElement.getAttribute("count_video")));
setList.add(pset);
allContext.setPhotoSetList(setList);
} else if (setElement.getTagName().equals("pool")) {
Pool pool = new Pool();
pool.setTitle(setElement.getAttribute("title"));
pool.setId(setElement.getAttribute("id"));
pool.setUrl(setElement.getAttribute("url"));
pool.setIconServer(setElement.getAttribute("iconserver"));
pool.setIconFarm(setElement.getAttribute("iconfarm"));
pool.setMemberCount(Integer.parseInt(setElement.getAttribute("members")));
pool.setPoolCount(Integer.parseInt(setElement.getAttribute("pool_count")));
poolList.add(pool);
allContext.setPoolList(poolList);
}
}

return allContext;

}
Expand Down Expand Up @@ -732,7 +732,7 @@ public Collection<Size> getSizes(String photoId) throws FlickrException {
* @throws FlickrException
*/
public Collection<Size> getSizes(String photoId, boolean sign) throws FlickrException {
SizeList<Size> sizes = new SizeList<Size>();
SizeList<Size> sizes = new SizeList<Size>();

Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_GET_SIZES);
Expand Down Expand Up @@ -1369,22 +1369,20 @@ public InputStream getImageAsStream(Photo photo, int size) throws FlickrExceptio
} else if (size == Size.MEDIUM_800) {
urlStr = photo.getMedium800Url();
} else if (size == Size.VIDEO_ORIGINAL) {
urlStr = photo.getVideoOriginalUrl();
urlStr = photo.getVideoOriginalUrl();
} else if (size == Size.VIDEO_PLAYER) {
urlStr = photo.getVideoPlayerUrl();
urlStr = photo.getVideoPlayerUrl();
} else if (size == Size.SITE_MP4) {
urlStr = photo.getSiteMP4Url();
}
else if(size == Size.MOBILE_MP4) {
urlStr = photo.getMobileMp4Url();
}
else if(size == Size.HD_MP4) {
urlStr = photo.getHdMp4Url();
} else {
urlStr = photo.getSiteMP4Url();
} else if (size == Size.MOBILE_MP4) {
urlStr = photo.getMobileMp4Url();
} else if (size == Size.HD_MP4) {
urlStr = photo.getHdMp4Url();
} else {
throw new FlickrException("0", "Unknown Photo-size");
}
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
if (transport instanceof REST) {
if (((REST) transport).isProxyAuth()) {
conn.setRequestProperty("Proxy-Authorization", "Basic " + ((REST) transport).getProxyCredentials());
Expand Down Expand Up @@ -1429,7 +1427,7 @@ public BufferedImage getImage(String urlStr) throws FlickrException {
InputStream in = null;
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
if (transport instanceof REST) {
if (((REST) transport).isProxyAuth()) {
conn.setRequestProperty("Proxy-Authorization", "Basic " + ((REST) transport).getProxyCredentials());
Expand Down

0 comments on commit 82bd451

Please sign in to comment.