Skip to content

Commit

Permalink
Merge branch 'don-vip-update_deps'
Browse files Browse the repository at this point in the history
  • Loading branch information
boncey committed May 2, 2020
2 parents f573cb9 + aef7cf5 commit d55d1fa
Show file tree
Hide file tree
Showing 54 changed files with 434 additions and 334 deletions.
23 changes: 13 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

<properties>
<javaVersion>1.8</javaVersion>
<junitVersion>4.11</junitVersion>
<slf4j.version>1.7.25</slf4j.version>
<scribe.version>6.2.0</scribe.version>
<junitVersion>4.13</junitVersion>
<slf4j.version>1.7.30</slf4j.version>
<scribe.version>6.9.0</scribe.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -71,7 +71,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<version>2.5.3</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
Expand All @@ -85,7 +85,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.8.1</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
Expand All @@ -94,7 +94,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>2.22.2</version>
<configuration>
<environmentVariables>
<SETUP_PROPERTIES_PATH>${setupPropertiesPath}</SETUP_PROPERTIES_PATH>
Expand All @@ -104,7 +104,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -118,7 +118,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.2.0</version>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -202,7 +205,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -222,7 +225,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20.1</version>
<version>2.22.2</version>
</plugin>
</plugins>
</reporting>
Expand Down
2 changes: 1 addition & 1 deletion src/examples/java/UploadPhoto.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void setUserName() throws FlickrException {
/**
* Check local saved copy first ??. If Auth by username is available, then we will not need to make the API call.
*
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/

private void setNsid() throws FlickrException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/flickr4java/flickr/Flickr.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* <p>
*
* 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
* applications</a> (You -> Your account -> Extending Flickr -> Account Links -> edit).
* applications</a> (You / Your account / Extending Flickr / Account Links / edit).
*
* @author Anthony Eden
* @version $Id: Flickr.java,v 1.45 2009/06/23 21:51:25 x-mago Exp $
Expand Down
99 changes: 14 additions & 85 deletions src/main/java/com/flickr4java/flickr/REST.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import com.flickr4java.flickr.uploader.UploadMetaData;
import com.flickr4java.flickr.util.DebugInputStream;
import com.flickr4java.flickr.util.IOUtilities;
import com.flickr4java.flickr.util.OAuthUtilities;
import com.flickr4java.flickr.util.UrlUtilities;
import com.github.scribejava.apis.FlickrApi;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig;
import com.github.scribejava.core.model.OAuth1AccessToken;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Verb;
Expand All @@ -31,7 +29,6 @@
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

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

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

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

OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));

buildNormalPostRequest(parameters, request);
OAuthRequest request = OAuthUtilities.buildNormalPostRequest(parameters, buildUrl(path));

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

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

OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));
Map<String, String> uploadParameters = new HashMap<>(metaData.getUploadParameters());

buildMultipartRequest(uploadParameters, request);
OAuthRequest request = OAuthUtilities.buildMultipartRequest(uploadParameters, buildUrl(path));

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

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

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

try {
return handleResponse(request, service);
} catch (IllegalAccessException | InterruptedException | ExecutionException | InstantiationException | IOException | SAXException | ParserConfigurationException e) {
} catch (ReflectiveOperationException | InterruptedException | ExecutionException | IOException | SAXException | ParserConfigurationException e) {
throw new FlickrRuntimeException(e);
}
}

private OAuth10aService createAndSignRequest(String apiKey, String sharedSecret, OAuthRequest request) {
RequestContext requestContext = RequestContext.getRequestContext();
Auth auth = requestContext.getAuth();
OAuth10aService service = createOAuthService(apiKey, sharedSecret);
if (auth != null) {
OAuth1AccessToken requestToken = new OAuth1AccessToken(auth.getToken(), auth.getTokenSecret());
service.signRequest(requestToken, request);
}

if (proxyAuth) {
request.addHeader("Proxy-Authorization", "Basic " + getProxyCredentials());
}

if (Flickr.debugRequest) {
logger.debug("POST: " + request.getCompleteUrl());
}

return service;
OAuth10aService service = OAuthUtilities.createOAuthService(apiKey, sharedSecret, connectTimeoutMs, readTimeoutMs);
OAuthUtilities.signRequest(service, request, proxyAuth ? getProxyCredentials() : null);
return service;
}

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

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

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

DocumentBuilder builder = getDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(strXml)));
f4jResponse = (Response) responseClass.newInstance();
Response f4jResponse = (Response) responseClass.getConstructor().newInstance();
f4jResponse.parse(document);

return f4jResponse;
Expand Down Expand Up @@ -314,55 +292,6 @@ public Response getNonOAuth(String path, Map<String, String> parameters) {
}
}

/**
* @param sharedSecret
* @return
*/
private OAuth10aService createOAuthService(String apiKey, String sharedSecret) {
JDKHttpClientConfig config = JDKHttpClientConfig.defaultConfig();
if (connectTimeoutMs != null) {
config.setConnectTimeout(connectTimeoutMs);
}
if (readTimeoutMs != null) {
config.setReadTimeout(readTimeoutMs);
}
ServiceBuilder serviceBuilder = new ServiceBuilder(apiKey).apiKey(apiKey).apiSecret(sharedSecret).httpClientConfig(config);

if (Flickr.debugRequest) {
serviceBuilder = serviceBuilder.debug();
}

return serviceBuilder.build(FlickrApi.instance());
}

/**
* @param parameters
* @param request
*/
private void buildNormalPostRequest(Map<String, Object> parameters, OAuthRequest request) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
request.addBodyParameter(entry.getKey(), String.valueOf(entry.getValue()));
}
}

/**
* @param parameters
* @param request
*/
private void buildMultipartRequest(Map<String, String> parameters, OAuthRequest request) {
String multipartBoundary = getMultipartBoundary();
request.initMultipartBoundary(multipartBoundary);

request.addHeader("Content-Type", "multipart/form-data; boundary=" + multipartBoundary);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
}

private String getMultipartBoundary() {
return "---------------------------" + UUID.randomUUID();
}

public boolean isProxyAuth() {
return proxyAuth;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/flickr4java/flickr/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void setScheme(String scheme) {
* @param apiKey
* @param sharedSecret
* @return The Response
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public abstract Response get(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException;

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

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

Expand All @@ -132,7 +132,7 @@ public void setScheme(String scheme) {
* @param parameters
* The parameters
* @return The Response
* @throws FlickrException
* @throws FlickrRuntimeException
*/
public abstract Response getNonOAuth(String path, Map<String, String> parameters) throws FlickrRuntimeException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ActivityInterface(String apiKey, String sharedSecret, Transport transport
* @param perPage
* @param page
* @return ItemList
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public ItemList<Item> userComments(int perPage, int page) throws FlickrException {
ItemList<Item> items = new ItemList<Item>();
Expand Down Expand Up @@ -88,7 +88,7 @@ public ItemList<Item> userComments(int perPage, int page) throws FlickrException
* @param page
* @param timeframe
* @return ItemList
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public ItemList<Item> userPhotos(int perPage, int page, String timeframe) throws FlickrException {
ItemList<Item> items = new ItemList<Item>();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/flickr4java/flickr/auth/AuthInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public OAuth1Token getAccessToken(OAuth1RequestToken oAuthRequestToken, String v
* @param accessToken
* The authentication token
* @return The Auth object
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public Auth checkToken(OAuth1Token accessToken) throws FlickrException {
return checkToken(accessToken.getToken(), accessToken.getTokenSecret());
Expand All @@ -171,7 +171,7 @@ public Auth checkToken(OAuth1Token accessToken) throws FlickrException {
* The authentication token
* @param tokenSecret
* @return The Auth object
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
* @see "http://www.flickr.com/services/api/flickr.auth.oauth.checkToken.html"
*/
public Auth checkToken(String authToken, String tokenSecret) throws FlickrException {
Expand Down Expand Up @@ -199,7 +199,7 @@ public Auth checkToken(String authToken, String tokenSecret) throws FlickrExcept
* Calling this method will delete the auth token used to make the request.
*
* @param authToken
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
* @see "http://www.flickr.com/services/api/flickr.auth.oauth.getAccessToken.html"
*/
public OAuth1RequestToken exchangeAuthToken(String authToken) throws FlickrException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public BlogsInterface(String apiKey, String sharedSecret, Transport transport) {
* This method does not require authentication.
*
* @return List of Services
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public Collection<Service> getServices() throws FlickrException {
List<Service> list = new ArrayList<Service>();
Expand Down Expand Up @@ -80,7 +80,7 @@ public Collection<Service> getServices() throws FlickrException {
* The blog ID
* @param blogPassword
* The blog password
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public void postPhoto(Photo photo, String blogId, String blogPassword) throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
Expand All @@ -107,7 +107,7 @@ public void postPhoto(Photo photo, String blogId, String blogPassword) throws Fl
* The photo metadata
* @param blogId
* The blog ID
* @throws FlickrException
* @throws FlickrException if there was a problem connecting to Flickr
*/
public void postPhoto(Photo photo, String blogId) throws FlickrException {
postPhoto(photo, blogId, null);
Expand Down
Loading

0 comments on commit d55d1fa

Please sign in to comment.