Skip to content

Commit 3b5fbe2

Browse files
committed
Update dependencies, fix javadoc errors, OAuth refactor
1 parent f573cb9 commit 3b5fbe2

25 files changed

Lines changed: 246 additions & 149 deletions

pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535

3636
<properties>
3737
<javaVersion>1.8</javaVersion>
38-
<junitVersion>4.11</junitVersion>
39-
<slf4j.version>1.7.25</slf4j.version>
40-
<scribe.version>6.2.0</scribe.version>
38+
<junitVersion>4.13</junitVersion>
39+
<slf4j.version>1.7.30</slf4j.version>
40+
<scribe.version>6.9.0</scribe.version>
4141
</properties>
4242

4343
<dependencies>
@@ -71,7 +71,7 @@
7171
<plugin>
7272
<groupId>org.apache.maven.plugins</groupId>
7373
<artifactId>maven-release-plugin</artifactId>
74-
<version>2.1</version>
74+
<version>2.5.3</version>
7575
<configuration>
7676
<mavenExecutorId>forked-path</mavenExecutorId>
7777
<useReleaseProfile>false</useReleaseProfile>
@@ -85,7 +85,7 @@
8585
<plugin>
8686
<groupId>org.apache.maven.plugins</groupId>
8787
<artifactId>maven-compiler-plugin</artifactId>
88-
<version>2.3.2</version>
88+
<version>3.8.1</version>
8989
<configuration>
9090
<source>${javaVersion}</source>
9191
<target>${javaVersion}</target>
@@ -94,7 +94,7 @@
9494
<plugin>
9595
<groupId>org.apache.maven.plugins</groupId>
9696
<artifactId>maven-surefire-plugin</artifactId>
97-
<version>2.19.1</version>
97+
<version>2.22.2</version>
9898
<configuration>
9999
<environmentVariables>
100100
<SETUP_PROPERTIES_PATH>${setupPropertiesPath}</SETUP_PROPERTIES_PATH>
@@ -104,7 +104,7 @@
104104
<plugin>
105105
<groupId>org.apache.maven.plugins</groupId>
106106
<artifactId>maven-source-plugin</artifactId>
107-
<version>2.2.1</version>
107+
<version>3.2.1</version>
108108
<executions>
109109
<execution>
110110
<id>attach-sources</id>
@@ -118,7 +118,7 @@
118118
<plugin>
119119
<groupId>org.apache.maven.plugins</groupId>
120120
<artifactId>maven-javadoc-plugin</artifactId>
121-
<version>2.9.1</version>
121+
<version>3.2.0</version>
122122
<executions>
123123
<execution>
124124
<id>attach-javadocs</id>
@@ -202,7 +202,7 @@
202202
<plugin>
203203
<groupId>org.apache.maven.plugins</groupId>
204204
<artifactId>maven-gpg-plugin</artifactId>
205-
<version>1.1</version>
205+
<version>1.6</version>
206206
<executions>
207207
<execution>
208208
<id>sign-artifacts</id>
@@ -222,7 +222,7 @@
222222
<plugin>
223223
<groupId>org.apache.maven.plugins</groupId>
224224
<artifactId>maven-surefire-report-plugin</artifactId>
225-
<version>2.20.1</version>
225+
<version>2.22.2</version>
226226
</plugin>
227227
</plugins>
228228
</reporting>

src/main/java/com/flickr4java/flickr/Flickr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* <p>
5050
*
5151
* The user who authenticates himself, can manage this permissions at <a href="http://www.flickr.com/services/auth/list.gne">his list of Third-party
52-
* applications</a> (You -> Your account -> Extending Flickr -> Account Links -> edit).
52+
* applications</a> (You / Your account / Extending Flickr / Account Links / edit).
5353
*
5454
* @author Anthony Eden
5555
* @version $Id: Flickr.java,v 1.45 2009/06/23 21:51:25 x-mago Exp $

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

Lines changed: 14 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import com.flickr4java.flickr.uploader.UploadMetaData;
77
import com.flickr4java.flickr.util.DebugInputStream;
88
import com.flickr4java.flickr.util.IOUtilities;
9+
import com.flickr4java.flickr.util.OAuthUtilities;
910
import com.flickr4java.flickr.util.UrlUtilities;
10-
import com.github.scribejava.apis.FlickrApi;
11-
import com.github.scribejava.core.builder.ServiceBuilder;
12-
import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig;
1311
import com.github.scribejava.core.model.OAuth1AccessToken;
1412
import com.github.scribejava.core.model.OAuthRequest;
1513
import com.github.scribejava.core.model.Verb;
@@ -31,7 +29,6 @@
3129
import java.util.Base64;
3230
import java.util.HashMap;
3331
import java.util.Map;
34-
import java.util.UUID;
3532
import java.util.concurrent.ExecutionException;
3633

3734
/**
@@ -144,7 +141,7 @@ public com.flickr4java.flickr.Response get(String path, Map<String, Object> para
144141

145142
RequestContext requestContext = RequestContext.getRequestContext();
146143
Auth auth = requestContext.getAuth();
147-
OAuth10aService service = createOAuthService(apiKey, sharedSecret);
144+
OAuth10aService service = OAuthUtilities.createOAuthService(apiKey, sharedSecret, connectTimeoutMs, readTimeoutMs);
148145
if (auth != null) {
149146
OAuth1AccessToken requestToken = new OAuth1AccessToken(auth.getToken(), auth.getTokenSecret());
150147
service.signRequest(requestToken, request);
@@ -162,7 +159,7 @@ public com.flickr4java.flickr.Response get(String path, Map<String, Object> para
162159

163160
try {
164161
return handleResponse(request, service);
165-
} catch (IllegalAccessException | InstantiationException | SAXException | IOException | InterruptedException | ExecutionException | ParserConfigurationException e) {
162+
} catch (ReflectiveOperationException | SAXException | IOException | InterruptedException | ExecutionException | ParserConfigurationException e) {
166163
throw new FlickrRuntimeException(e);
167164
}
168165
}
@@ -177,15 +174,13 @@ public com.flickr4java.flickr.Response get(String path, Map<String, Object> para
177174
@Override
178175
public com.flickr4java.flickr.Response post(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException {
179176

180-
OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));
181-
182-
buildNormalPostRequest(parameters, request);
177+
OAuthRequest request = OAuthUtilities.buildNormalPostRequest(parameters, buildUrl(path));
183178

184179
OAuth10aService service = createAndSignRequest(apiKey, sharedSecret, request);
185180

186181
try {
187182
return handleResponse(request, service);
188-
} catch (IllegalAccessException | InterruptedException | ExecutionException | InstantiationException | IOException | SAXException | ParserConfigurationException e) {
183+
} catch (ReflectiveOperationException | InterruptedException | ExecutionException | IOException | SAXException | ParserConfigurationException e) {
189184
throw new FlickrRuntimeException(e);
190185
}
191186
}
@@ -201,58 +196,41 @@ public com.flickr4java.flickr.Response post(String path, Map<String, Object> par
201196
@Override
202197
public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData metaData, Payload payload, String apiKey, String sharedSecret) throws FlickrException {
203198

204-
OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));
205199
Map<String, String> uploadParameters = new HashMap<>(metaData.getUploadParameters());
206-
207-
buildMultipartRequest(uploadParameters, request);
200+
OAuthRequest request = OAuthUtilities.buildMultipartRequest(uploadParameters, buildUrl(path));
208201

209202
OAuth10aService service = createAndSignRequest(apiKey, sharedSecret, request);
210203

211204
// Ensure all parameters (including oauth) are added to payload so signature matches
212205
uploadParameters.putAll(request.getOauthParameters());
213206

214-
request.addMultipartPayload(String.format("form-data; name=\"photo\"; filename=\"%s\"", metaData.getFilename()), metaData.getFilemimetype(), payload.getPayload());
207+
request.addFileByteArrayBodyPartPayloadInMultipartPayload(metaData.getFilemimetype(), payload.getPayload());
215208
uploadParameters.entrySet().forEach(e ->
216-
request.addMultipartPayload(String.format("form-data; name=\"%s\"", e.getKey()), null, e.getValue().getBytes()));
209+
request.addFileByteArrayBodyPartPayloadInMultipartPayload(null, e.getValue().getBytes()));
217210

218211
try {
219212
return handleResponse(request, service);
220-
} catch (IllegalAccessException | InterruptedException | ExecutionException | InstantiationException | IOException | SAXException | ParserConfigurationException e) {
213+
} catch (ReflectiveOperationException | InterruptedException | ExecutionException | IOException | SAXException | ParserConfigurationException e) {
221214
throw new FlickrRuntimeException(e);
222215
}
223216
}
224217

225218
private OAuth10aService createAndSignRequest(String apiKey, String sharedSecret, OAuthRequest request) {
226-
RequestContext requestContext = RequestContext.getRequestContext();
227-
Auth auth = requestContext.getAuth();
228-
OAuth10aService service = createOAuthService(apiKey, sharedSecret);
229-
if (auth != null) {
230-
OAuth1AccessToken requestToken = new OAuth1AccessToken(auth.getToken(), auth.getTokenSecret());
231-
service.signRequest(requestToken, request);
232-
}
233-
234-
if (proxyAuth) {
235-
request.addHeader("Proxy-Authorization", "Basic " + getProxyCredentials());
236-
}
237-
238-
if (Flickr.debugRequest) {
239-
logger.debug("POST: " + request.getCompleteUrl());
240-
}
241-
242-
return service;
219+
OAuth10aService service = OAuthUtilities.createOAuthService(apiKey, sharedSecret, connectTimeoutMs, readTimeoutMs);
220+
OAuthUtilities.signRequest(service, request, proxyAuth ? getProxyCredentials() : null);
221+
return service;
243222
}
244223

245224
private String buildUrl(String path) {
246225
return String.format("%s://%s%s", getScheme(), getHost(), path);
247226
}
248227

249-
private Response handleResponse(OAuthRequest request, OAuth10aService service) throws InterruptedException, ExecutionException, IOException, SAXException, InstantiationException, IllegalAccessException, ParserConfigurationException, FlickrException {
228+
private Response handleResponse(OAuthRequest request, OAuth10aService service) throws InterruptedException, ExecutionException, IOException, SAXException, ParserConfigurationException, FlickrException, ReflectiveOperationException {
250229
com.github.scribejava.core.model.Response scribeResponse = service.execute(request);
251230

252231
if (!scribeResponse.isSuccessful()) {
253232
throw new FlickrException(FLICKR_SERVICE_UNAVAILABLE, String.format("Received '%s' error from Flickr with status %d", scribeResponse.getMessage(), scribeResponse.getCode()));
254233
}
255-
Response f4jResponse;
256234
String strXml = scribeResponse.getBody().trim();
257235
if (Flickr.debugStream) {
258236
logger.debug(strXml);
@@ -263,7 +241,7 @@ private Response handleResponse(OAuthRequest request, OAuth10aService service) t
263241

264242
DocumentBuilder builder = getDocumentBuilder();
265243
Document document = builder.parse(new InputSource(new StringReader(strXml)));
266-
f4jResponse = (Response) responseClass.newInstance();
244+
Response f4jResponse = (Response) responseClass.getConstructor().newInstance();
267245
f4jResponse.parse(document);
268246

269247
return f4jResponse;
@@ -314,55 +292,6 @@ public Response getNonOAuth(String path, Map<String, String> parameters) {
314292
}
315293
}
316294

317-
/**
318-
* @param sharedSecret
319-
* @return
320-
*/
321-
private OAuth10aService createOAuthService(String apiKey, String sharedSecret) {
322-
JDKHttpClientConfig config = JDKHttpClientConfig.defaultConfig();
323-
if (connectTimeoutMs != null) {
324-
config.setConnectTimeout(connectTimeoutMs);
325-
}
326-
if (readTimeoutMs != null) {
327-
config.setReadTimeout(readTimeoutMs);
328-
}
329-
ServiceBuilder serviceBuilder = new ServiceBuilder(apiKey).apiKey(apiKey).apiSecret(sharedSecret).httpClientConfig(config);
330-
331-
if (Flickr.debugRequest) {
332-
serviceBuilder = serviceBuilder.debug();
333-
}
334-
335-
return serviceBuilder.build(FlickrApi.instance());
336-
}
337-
338-
/**
339-
* @param parameters
340-
* @param request
341-
*/
342-
private void buildNormalPostRequest(Map<String, Object> parameters, OAuthRequest request) {
343-
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
344-
request.addBodyParameter(entry.getKey(), String.valueOf(entry.getValue()));
345-
}
346-
}
347-
348-
/**
349-
* @param parameters
350-
* @param request
351-
*/
352-
private void buildMultipartRequest(Map<String, String> parameters, OAuthRequest request) {
353-
String multipartBoundary = getMultipartBoundary();
354-
request.initMultipartBoundary(multipartBoundary);
355-
356-
request.addHeader("Content-Type", "multipart/form-data; boundary=" + multipartBoundary);
357-
for (Map.Entry<String, String> entry : parameters.entrySet()) {
358-
request.addQuerystringParameter(entry.getKey(), entry.getValue());
359-
}
360-
}
361-
362-
private String getMultipartBoundary() {
363-
return "---------------------------" + UUID.randomUUID();
364-
}
365-
366295
public boolean isProxyAuth() {
367296
return proxyAuth;
368297
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void setScheme(String scheme) {
132132
* @param parameters
133133
* The parameters
134134
* @return The Response
135-
* @throws FlickrException
135+
* @throws FlickrRuntimeException
136136
*/
137137
public abstract Response getNonOAuth(String path, Map<String, String> parameters) throws FlickrRuntimeException;
138138

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void setIconServer(String iconServer) {
159159

160160
/**
161161
* Get the contact's path alias, which may appear instead of nsid in urls published by Flickr. For example feeds have urls of the form
162-
* .../photos/${NSID_OR_PATHALIAS}/${PHOTO_ID} & .../people/${NSID_OR_PATHALIAS}. This allows clients to look up a {@link Contact} given such a url. (Note
162+
* .../photos/${NSID_OR_PATHALIAS}/${PHOTO_ID} and .../people/${NSID_OR_PATHALIAS}. This allows clients to look up a {@link Contact} given such a url. (Note
163163
* that <code>&lt;author&gt;</code> elements in feeds have a <code>&lt;flickr:nsid&gt;</code> child which could be used instead of the lookup this method
164164
* enables.)
165165
*

src/main/java/com/flickr4java/flickr/contacts/ContactsInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Collection<Contact> getList() throws FlickrException {
9494
* Limits the resultset to contacts that have uploaded photos since this date. The date should be in the form of a Unix timestamp. The default,
9595
* and maximum, offset is (1) hour. (Optional, can be null)
9696
* @param filter
97-
* Limit the result set to all contacts or only those who are friends or family.<br/>
97+
* Limit the result set to all contacts or only those who are friends or family.<br>
9898
* Valid options are: <b>ff</b> -&gt; friends and family, <b>all</b> -&gt; all your contacts. (Optional, can be null)
9999
*
100100
* @return List of Contacts

src/main/java/com/flickr4java/flickr/favorites/FavoritesInterface.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public void add(String photoId) throws FlickrException {
7575
* @param userId
7676
* The optional user ID. Null value will be ignored.
7777
* @param perPage
78-
* The optional per page value. Values <= 0 will be ignored.
78+
* The optional per page value. Values {@code <= 0} will be ignored.
7979
* @param page
80-
* The page to view. Values <= 0 will be ignored.
80+
* The page to view. Values {@code <= 0} will be ignored.
8181
* @param extras
8282
* a Set Strings representing extra parameters to send
8383
* @return The Collection of Photo objects
@@ -128,9 +128,9 @@ public PhotoList<Photo> getList(String userId, int perPage, int page, Set<String
128128
* @param userId
129129
* The user ID
130130
* @param perPage
131-
* The optional per page value. Values <= 0 will be ignored.
131+
* The optional per page value. Values {@code <= 0} will be ignored.
132132
* @param page
133-
* The optional page to view. Values <= 0 will be ignored
133+
* The optional page to view. Values {@code <= 0} will be ignored
134134
* @param extras
135135
* A Set of extra parameters to send
136136
* @return A Collection of Photo objects

src/main/java/com/flickr4java/flickr/galleries/GalleriesInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public GalleriesInterface(String apiKey, String sharedSecret, Transport transpor
7777
* @return gallery
7878
* @throws FlickrException
7979
*
80-
* @see <a hrerf="http://www.flickr.com/services/api/flickr.galleries.getList.html">flickr.galleries.getList</a>
80+
* @see <a href="https://www.flickr.com/services/api/flickr.galleries.getList.html">flickr.galleries.getList</a>
8181
*/
8282
public List<Gallery> getList(String userId, int perPage, int page) throws FlickrException {
8383
Map<String, Object> parameters = new HashMap<String, Object>();

src/main/java/com/flickr4java/flickr/groups/discuss/GroupDiscussInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GroupDiscussInterface(String apiKey, String sharedSecret, Transport trans
4242
* Get a list of topics from a group.
4343
*
4444
* @param groupId
45-
* Unique identifier of a group returns a list of topics for a given group {@link Group}.
45+
* Unique identifier of a group returns a list of topics for a given group {@link com.flickr4java.flickr.groups.Group}.
4646
* @param perPage
4747
* Number of records per page.
4848
* @param page

0 commit comments

Comments
 (0)