Merge branch 'master' of github.com:mike10004/Flickr4Java into mike10… · fstudy817/Flickr4Java@42b0c84 · GitHub
Skip to content

Commit 42b0c84

Browse files
author
boncey
committed
Merge branch 'master' of github.com:mike10004/Flickr4Java into mike10004-master
2 parents f10fd8a + 030a5fe commit 42b0c84

10 files changed

Lines changed: 184 additions & 28 deletions

File tree

Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java

Lines changed: 4 additions & 3 deletions

Flickr4Java/src/main/java/com/flickr4java/flickr/Transport.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public abstract class Transport {
1818

1919
public static final String SOAP = "SOAP";
2020

21-
protected static final String API_HOST = "http://api.flickr.com";
21+
protected static final String API_HOST = "api.flickr.com";
2222

23+
protected static final String DEFAULT_SCHEME = "https";
24+
2325
private String transportType;
2426

2527
protected Class<?> responseClass;
@@ -28,7 +30,9 @@ public abstract class Transport {
2830

2931
private String host;
3032

31-
private int port = 80;
33+
private int port = 443;
34+
35+
private String scheme;
3236

3337
public String getHost() {
3438
return host;
@@ -62,6 +66,14 @@ public void setPath(String path) {
6266
this.path = path;
6367
}
6468

69+
public String getScheme() {
70+
return scheme;
71+
}
72+
73+
public void setScheme(String scheme) {
74+
this.scheme = scheme;
75+
}
76+
6577
/**
6678
* Invoke an HTTP GET request on a remote host. You must close the InputStream after you are done with.
6779
*

Flickr4Java/src/main/java/com/flickr4java/flickr/contacts/Contact.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,25 @@ public void setAwayMessage(String awayMessage) {
116116
*
117117
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
118118
* @return The BuddyIconUrl
119+
* @deprecated use {@link #getSecureBuddyIconUrl() }
119120
*/
121+
@Deprecated
120122
public String getBuddyIconUrl() {
121123
return UrlUtilities.createBuddyIconUrl(iconFarm, iconServer, id);
122124
}
123125

126+
/**
127+
* Construct the BuddyIconUrl using {@code https} scheme.
128+
* <p>
129+
* If none available, return the <a href="https://www.flickr.com/images/buddyicon.jpg">default</a>, or an URL assembled from farm, iconserver and nsid.
130+
*
131+
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
132+
* @return The BuddyIconUrl
133+
*/
134+
public String getSecureBuddyIconUrl() {
135+
return UrlUtilities.createSecureBuddyIconUrl(iconFarm, iconServer, id);
136+
}
137+
124138
public int getIconFarm() {
125139
return iconFarm;
126140
}

Flickr4Java/src/main/java/com/flickr4java/flickr/groups/Group.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,25 @@ public void setIconServer(String iconServer) {
287287
*
288288
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
289289
* @return The BuddyIconUrl
290+
* @deprecated use {@link #getSecureBuddyIconUrl() }
290291
*/
292+
@Deprecated
291293
public String getBuddyIconUrl() {
292294
return UrlUtilities.createBuddyIconUrl(iconFarm, iconServer, id);
293295
}
294296

297+
/**
298+
* Construct the BuddyIconUrl using {@code https} scheme.
299+
* <p>
300+
* If none available, return the <a href="https://www.flickr.com/images/buddyicon.jpg">default</a>, or an URL assembled from farm, iconserver and nsid.
301+
*
302+
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
303+
* @return The BuddyIconUrl
304+
*/
305+
public String getSecureBuddyIconUrl() {
306+
return UrlUtilities.createSecureBuddyIconUrl(iconFarm, iconServer, id);
307+
}
308+
295309
public Throttle getThrottle() {
296310
return throttle;
297311
}

Flickr4Java/src/main/java/com/flickr4java/flickr/people/User.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,26 @@ public String getLocation() {
159159
*
160160
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
161161
* @return The BuddyIconUrl
162+
* @deprecated use {@link #getSecureBuddyIconUrl() }
162163
*/
164+
@Deprecated
163165
public String getBuddyIconUrl() {
164166
return UrlUtilities.createBuddyIconUrl(iconFarm, iconServer, id);
165167
}
166168

169+
/**
170+
* Construct the BuddyIconUrl using {@code https} scheme.
171+
* <p>
172+
* If none available, return the <a href="https://www.flickr.com/images/buddyicon.jpg">default</a>, or an URL assembled from farm, iconserver and nsid.
173+
*
174+
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
175+
* @return The BuddyIconUrl
176+
*/
177+
public String getSecureBuddyIconUrl() {
178+
return UrlUtilities.createSecureBuddyIconUrl(iconFarm, iconServer, id);
179+
}
180+
181+
167182
public void setLocation(String location) {
168183
this.location = location;
169184
}

Flickr4Java/src/main/java/com/flickr4java/flickr/util/UrlUtilities.java

Lines changed: 111 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import java.net.URLEncoder;
1111
import java.util.Map;
1212

13-
/** @author Anthony Eden */
13+
/**
14+
* @author Anthony Eden
15+
* @author Mike Chaberski
16+
*/
1417
public class UrlUtilities {
1518

1619
public static final String UTF8 = "UTF-8";
@@ -28,14 +31,33 @@ public class UrlUtilities {
2831
* The parameters
2932
* @return The URL
3033
* @throws MalformedURLException
34+
* @deprecated use {@link #buildSecureUrl(java.lang.String, int, java.lang.String, java.util.Map) }
3135
*/
36+
@Deprecated
3237
public static URL buildUrl(String host, int port, String path, Map<String, String> parameters) throws MalformedURLException {
33-
// see: AuthUtilities.getSignature()
34-
// AuthUtilities.addAuthToken(parameters);
35-
36-
StringBuffer buffer = new StringBuffer();
37-
if (!host.startsWith("http://")) {
38-
buffer.append("http://");
38+
return buildUrl("http", port, path, parameters);
39+
}
40+
41+
/**
42+
* Build a request URL using a given scheme.
43+
*
44+
* @param scheme the scheme, either {@code http} or {@code https}
45+
* @param host
46+
* The host
47+
* @param port
48+
* The port
49+
* @param path
50+
* The path
51+
* @param parameters
52+
* The parameters
53+
* @return The URL
54+
* @throws MalformedURLException
55+
*/
56+
public static URL buildUrl(String scheme, String host, int port, String path, Map<String, String> parameters) throws MalformedURLException {
57+
checkSchemeAndPort(scheme, port);
58+
StringBuilder buffer = new StringBuilder();
59+
if (!host.startsWith(scheme + "://")) {
60+
buffer.append(scheme).append("://");
3961
}
4062
buffer.append(host);
4163
if (port > 0) {
@@ -77,9 +99,64 @@ public static URL buildUrl(String host, int port, String path, Map<String, Strin
7799
return new URL(buffer.toString());
78100
}
79101

102+
/**
103+
* Build a request URL.
104+
*
105+
* @param host
106+
* The host
107+
* @param port
108+
* The port
109+
* @param path
110+
* The path
111+
* @param parameters
112+
* The parameters
113+
* @return The URL
114+
* @throws MalformedURLException
115+
*/
116+
public static URL buildSecureUrl(String host, int port, String path, Map<String, String> parameters) throws MalformedURLException {
117+
return buildUrl("https", host, port, path, parameters);
118+
}
119+
120+
public static URL buildSecurePostUrl(String host, int port, String path) throws MalformedURLException {
121+
return buildPostUrl("https", host, port, path);
122+
}
123+
124+
private static void checkScheme(String scheme) {
125+
if (scheme == null || !("http".equals(scheme) || "https".equals(scheme))) {
126+
throw new IllegalArgumentException("scheme must be http or https");
127+
}
128+
}
129+
130+
private static void checkSchemeAndPort(String scheme, int port) {
131+
checkScheme(scheme);
132+
/*
133+
* Be liberal about accepting non-default ports, but strict
134+
* about mismatching scheme and default port.
135+
*/
136+
if ("http".equals(scheme) && port == 443) {
137+
throw new IllegalArgumentException("port 443 is invalid with http scheme");
138+
}
139+
if ("https".equals(scheme) && port == 80) {
140+
throw new IllegalArgumentException("port 80 is invalid with https scheme");
141+
}
142+
}
143+
144+
/**
145+
* Build a POST URL with {@code http} scheme.
146+
* @param host the host
147+
* @param port the port
148+
* @param path the path
149+
* @return
150+
* @throws MalformedURLException
151+
*/
80152
public static URL buildPostUrl(String host, int port, String path) throws MalformedURLException {
81-
StringBuffer buffer = new StringBuffer();
82-
buffer.append("http://");
153+
return buildPostUrl("http", host, port, path);
154+
}
155+
156+
public static URL buildPostUrl(String scheme, String host, int port, String path) throws MalformedURLException {
157+
checkSchemeAndPort(scheme, port);
158+
StringBuilder buffer = new StringBuilder();
159+
buffer.append(scheme).append("://");
83160
buffer.append(host);
84161
if (port > 0) {
85162
buffer.append(':');
@@ -93,7 +170,7 @@ public static URL buildPostUrl(String host, int port, String path) throws Malfor
93170
}
94171

95172
/**
96-
* Construct the BuddyIconUrl.
173+
* Construct the BuddyIconUrl with {@code http} scheme.
97174
* <p>
98175
* If none available, return the <a href="http://www.flickr.com/images/buddyicon.jpg">default</a>, or an URL assembled from farm, iconserver and nsid.
99176
*
@@ -102,14 +179,36 @@ public static URL buildPostUrl(String host, int port, String path) throws Malfor
102179
* @param iconServer
103180
* @param id
104181
* @return The BuddyIconUrl
182+
* @deprecated use {@link #createSecureBuddyIconUrl(int, int, java.lang.String) }
105183
*/
184+
@Deprecated
106185
public static String createBuddyIconUrl(int iconFarm, int iconServer, String id) {
186+
return createBuddyIconUrl("http", iconFarm, iconServer, id);
187+
}
188+
189+
/**
190+
* Construct the BuddyIconUrl with {@code https} scheme.
191+
* <p>
192+
* If none available, return the <a href="https://www.flickr.com/images/buddyicon.jpg">default</a>, or an URL assembled from farm, iconserver and nsid.
193+
*
194+
* @see <a href="http://flickr.com/services/api/misc.buddyicons.html">Flickr Documentation</a>
195+
* @param iconFarm
196+
* @param iconServer
197+
* @param id
198+
* @return The BuddyIconUrl
199+
*/
200+
public static String createSecureBuddyIconUrl(int iconFarm, int iconServer, String id) {
201+
return createBuddyIconUrl("https", iconFarm, iconServer, id);
202+
}
203+
204+
public static String createBuddyIconUrl(String scheme, int iconFarm, int iconServer, String id) {
205+
checkScheme(scheme);
107206
/**
108207
* The default-URL, if the iconServer equals 0.
109208
*/
110-
String iconUrl = "http://www.flickr.com/images/buddyicon.jpg";
209+
String iconUrl = scheme + "://www.flickr.com/images/buddyicon.jpg";
111210
if (iconServer > 0) {
112-
iconUrl = "http://farm" + iconFarm + ".static.flickr.com/" + iconServer + "/buddyicons/" + id + ".jpg";
211+
iconUrl = scheme + "://farm" + iconFarm + ".static.flickr.com/" + iconServer + "/buddyicons/" + id + ".jpg";
113212
}
114213
return iconUrl;
115214
}

Flickr4Java/src/test/java/com/flickr4java/flickr/test/GalleriesInterfaceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void tearDown() {
2828
flickr = null;
2929
}
3030

31+
@Ignore
3132
@Test
3233
public void testGetList() throws FlickrException {
3334
GalleriesInterface iface = flickr.getGalleriesInterface();

Flickr4Java/src/test/java/com/flickr4java/flickr/test/GroupsInterfaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testGetInfo() throws FlickrException {
7373
assertEquals("34427469792@N01", group.getId());
7474
assertEquals("FlickrCentral", group.getName());
7575
assertTrue(group.getMembers() > 0);
76-
assertTrue(group.getBuddyIconUrl().startsWith("http://farm"));
76+
assertTrue(group.getBuddyIconUrl().startsWith("https://farm"));
7777

7878
// System.out.println("group members: " + group.getMembers());
7979
}

Flickr4Java/src/test/java/com/flickr4java/flickr/test/PeopleInterfaceTest.java

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)