Skip to content

Commit d55d1fa

Browse files
author
boncey
committed
Merge branch 'don-vip-update_deps'
2 parents f573cb9 + aef7cf5 commit d55d1fa

54 files changed

Lines changed: 434 additions & 334 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 13 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,10 @@
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>
122+
<configuration>
123+
<source>8</source>
124+
</configuration>
122125
<executions>
123126
<execution>
124127
<id>attach-javadocs</id>
@@ -202,7 +205,7 @@
202205
<plugin>
203206
<groupId>org.apache.maven.plugins</groupId>
204207
<artifactId>maven-gpg-plugin</artifactId>
205-
<version>1.1</version>
208+
<version>1.6</version>
206209
<executions>
207210
<execution>
208211
<id>sign-artifacts</id>
@@ -222,7 +225,7 @@
222225
<plugin>
223226
<groupId>org.apache.maven.plugins</groupId>
224227
<artifactId>maven-surefire-report-plugin</artifactId>
225-
<version>2.20.1</version>
228+
<version>2.22.2</version>
226229
</plugin>
227230
</plugins>
228231
</reporting>

src/examples/java/UploadPhoto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private void setUserName() throws FlickrException {
124124
/**
125125
* Check local saved copy first ??. If Auth by username is available, then we will not need to make the API call.
126126
*
127-
* @throws FlickrException
127+
* @throws FlickrException if there was a problem connecting to Flickr
128128
*/
129129

130130
private void setNsid() throws FlickrException {

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void setScheme(String scheme) {
8989
* @param apiKey
9090
* @param sharedSecret
9191
* @return The Response
92-
* @throws FlickrException
92+
* @throws FlickrException if there was a problem connecting to Flickr
9393
*/
9494
public abstract Response get(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException;
9595

@@ -103,7 +103,7 @@ public void setScheme(String scheme) {
103103
* @param apiKey
104104
* @param sharedSecret
105105
* @return The Response object
106-
* @throws FlickrException
106+
* @throws FlickrException if there was a problem connecting to Flickr
107107
*/
108108
public abstract Response post(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException;
109109

@@ -118,7 +118,7 @@ public void setScheme(String scheme) {
118118
* @param apiKey
119119
* @param sharedSecret
120120
* @return The Response object
121-
* @throws FlickrException
121+
* @throws FlickrException if there was a problem connecting to Flickr
122122
*/
123123
public abstract Response postMultiPart(String path, UploadMetaData parameters, Payload payload, String apiKey, String sharedSecret) throws FlickrException;
124124

@@ -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/activity/ActivityInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ActivityInterface(String apiKey, String sharedSecret, Transport transport
4545
* @param perPage
4646
* @param page
4747
* @return ItemList
48-
* @throws FlickrException
48+
* @throws FlickrException if there was a problem connecting to Flickr
4949
*/
5050
public ItemList<Item> userComments(int perPage, int page) throws FlickrException {
5151
ItemList<Item> items = new ItemList<Item>();
@@ -88,7 +88,7 @@ public ItemList<Item> userComments(int perPage, int page) throws FlickrException
8888
* @param page
8989
* @param timeframe
9090
* @return ItemList
91-
* @throws FlickrException
91+
* @throws FlickrException if there was a problem connecting to Flickr
9292
*/
9393
public ItemList<Item> userPhotos(int perPage, int page, String timeframe) throws FlickrException {
9494
ItemList<Item> items = new ItemList<Item>();

src/main/java/com/flickr4java/flickr/auth/AuthInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public OAuth1Token getAccessToken(OAuth1RequestToken oAuthRequestToken, String v
159159
* @param accessToken
160160
* The authentication token
161161
* @return The Auth object
162-
* @throws FlickrException
162+
* @throws FlickrException if there was a problem connecting to Flickr
163163
*/
164164
public Auth checkToken(OAuth1Token accessToken) throws FlickrException {
165165
return checkToken(accessToken.getToken(), accessToken.getTokenSecret());
@@ -171,7 +171,7 @@ public Auth checkToken(OAuth1Token accessToken) throws FlickrException {
171171
* The authentication token
172172
* @param tokenSecret
173173
* @return The Auth object
174-
* @throws FlickrException
174+
* @throws FlickrException if there was a problem connecting to Flickr
175175
* @see "http://www.flickr.com/services/api/flickr.auth.oauth.checkToken.html"
176176
*/
177177
public Auth checkToken(String authToken, String tokenSecret) throws FlickrException {
@@ -199,7 +199,7 @@ public Auth checkToken(String authToken, String tokenSecret) throws FlickrExcept
199199
* Calling this method will delete the auth token used to make the request.
200200
*
201201
* @param authToken
202-
* @throws FlickrException
202+
* @throws FlickrException if there was a problem connecting to Flickr
203203
* @see "http://www.flickr.com/services/api/flickr.auth.oauth.getAccessToken.html"
204204
*/
205205
public OAuth1RequestToken exchangeAuthToken(String authToken) throws FlickrException {

src/main/java/com/flickr4java/flickr/blogs/BlogsInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public BlogsInterface(String apiKey, String sharedSecret, Transport transport) {
4848
* This method does not require authentication.
4949
*
5050
* @return List of Services
51-
* @throws FlickrException
51+
* @throws FlickrException if there was a problem connecting to Flickr
5252
*/
5353
public Collection<Service> getServices() throws FlickrException {
5454
List<Service> list = new ArrayList<Service>();
@@ -80,7 +80,7 @@ public Collection<Service> getServices() throws FlickrException {
8080
* The blog ID
8181
* @param blogPassword
8282
* The blog password
83-
* @throws FlickrException
83+
* @throws FlickrException if there was a problem connecting to Flickr
8484
*/
8585
public void postPhoto(Photo photo, String blogId, String blogPassword) throws FlickrException {
8686
Map<String, Object> parameters = new HashMap<String, Object>();
@@ -107,7 +107,7 @@ public void postPhoto(Photo photo, String blogId, String blogPassword) throws Fl
107107
* The photo metadata
108108
* @param blogId
109109
* The blog ID
110-
* @throws FlickrException
110+
* @throws FlickrException if there was a problem connecting to Flickr
111111
*/
112112
public void postPhoto(Photo photo, String blogId) throws FlickrException {
113113
postPhoto(photo, blogId, null);

0 commit comments

Comments
 (0)