diff --git a/.gitignore b/.gitignore index eb5a316..252d3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target +.settings +.project +.classpath diff --git a/pom.xml b/pom.xml index 1c9b804..5bc11ea 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ oauth.signpost oauth-signpost pom - 1.2.1.1 + 1.2.1.2-SNAPSHOT oauth-signpost A simple, light-weight, and modular OAuth client library for the @@ -119,12 +119,6 @@ Signpost Snapshot Repository http://oss.sonatype.org/content/repositories/signpost-snapshots/ - diff --git a/signpost-commonshttp4/.classpath b/signpost-commonshttp4/.classpath index e27f6e5..a162450 100644 --- a/signpost-commonshttp4/.classpath +++ b/signpost-commonshttp4/.classpath @@ -2,7 +2,7 @@ - + diff --git a/signpost-commonshttp4/pom.xml b/signpost-commonshttp4/pom.xml index e593e20..2d5952f 100644 --- a/signpost-commonshttp4/pom.xml +++ b/signpost-commonshttp4/pom.xml @@ -2,7 +2,7 @@ oauth-signpost oauth.signpost - 1.2.1.1 + 1.2.1.2-SNAPSHOT 4.0.0 signpost-commonshttp4 @@ -12,7 +12,7 @@ oauth.signpost signpost-core - 1.2.1.1 + ${project.version} compile @@ -30,10 +30,9 @@ oauth.signpost signpost-core - 1.2.1.1 + ${project.version} test-jar test - \ No newline at end of file diff --git a/signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/CommonsHttpOAuthProvider.java b/signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/CommonsHttpOAuthProvider.java index ee42e87..35f1960 100644 --- a/signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/CommonsHttpOAuthProvider.java +++ b/signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/CommonsHttpOAuthProvider.java @@ -18,6 +18,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; @@ -43,19 +44,31 @@ public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTok this.httpClient = new DefaultHttpClient(); } + public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, + String authorizationWebsiteUrl, final String httpMethod) { + super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod); + this.httpClient = new DefaultHttpClient(); + } + public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, String authorizationWebsiteUrl, HttpClient httpClient) { super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl); this.httpClient = httpClient; } - + + public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, + String authorizationWebsiteUrl, HttpClient httpClient, String httpMethod) { + super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod); + this.httpClient = httpClient; + } + public void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } @Override protected HttpRequest createRequest(String endpointUrl) throws Exception { - HttpPost request = new HttpPost(endpointUrl); + HttpUriRequest request = this.method.equals(HTTP_POST) ? new HttpPost(endpointUrl) : new HttpGet(endpointUrl); return new HttpRequestAdapter(request); } diff --git a/signpost-core/.classpath b/signpost-core/.classpath index e27f6e5..a162450 100644 --- a/signpost-core/.classpath +++ b/signpost-core/.classpath @@ -2,7 +2,7 @@ - + diff --git a/signpost-core/pom.xml b/signpost-core/pom.xml index ff7c5fb..c7ef9e8 100644 --- a/signpost-core/pom.xml +++ b/signpost-core/pom.xml @@ -2,7 +2,7 @@ oauth-signpost oauth.signpost - 1.2.1.1 + 1.2.1.2-SNAPSHOT 4.0.0 signpost-core diff --git a/signpost-core/src/main/java/oauth/signpost/AbstractOAuthProvider.java b/signpost-core/src/main/java/oauth/signpost/AbstractOAuthProvider.java index eb72617..f0a7e29 100644 --- a/signpost-core/src/main/java/oauth/signpost/AbstractOAuthProvider.java +++ b/signpost-core/src/main/java/oauth/signpost/AbstractOAuthProvider.java @@ -31,7 +31,6 @@ * @author Matthias Kaeppler */ public abstract class AbstractOAuthProvider implements OAuthProvider { - private static final long serialVersionUID = 1L; private String requestTokenEndpointUrl; @@ -47,14 +46,25 @@ public abstract class AbstractOAuthProvider implements OAuthProvider { private boolean isOAuth10a; private transient OAuthProviderListener listener; - + + protected final String method; + public AbstractOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, - String authorizationWebsiteUrl) { + String authorizationWebsiteUrl, final String httpMethod) { this.requestTokenEndpointUrl = requestTokenEndpointUrl; this.accessTokenEndpointUrl = accessTokenEndpointUrl; this.authorizationWebsiteUrl = authorizationWebsiteUrl; this.responseParameters = new HttpParameters(); this.defaultHeaders = new HashMap(); + if (null == httpMethod || !(httpMethod.toUpperCase().equals("GET") || httpMethod.toUpperCase().equals("POST"))) { + throw new IllegalArgumentException("You must specify a valid httpMethod (GET or POST)"); + } + this.method = httpMethod; + } + + public AbstractOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, + String authorizationWebsiteUrl) { + this(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, OAuthProvider.HTTP_POST); } public String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl) diff --git a/signpost-core/src/main/java/oauth/signpost/OAuthProvider.java b/signpost-core/src/main/java/oauth/signpost/OAuthProvider.java index 9903ed0..ef1534c 100644 --- a/signpost-core/src/main/java/oauth/signpost/OAuthProvider.java +++ b/signpost-core/src/main/java/oauth/signpost/OAuthProvider.java @@ -83,6 +83,8 @@ * @see OAuthProviderListener */ public interface OAuthProvider extends Serializable { + public static final String HTTP_GET = "GET"; + public static final String HTTP_POST = "POST"; /** * Queries the service provider for a request token. diff --git a/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java b/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java index a065d15..09ffb78 100644 --- a/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java +++ b/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java @@ -33,11 +33,16 @@ public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEn String authorizationWebsiteUrl) { super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl); } + + public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, + String authorizationWebsiteUrl, final String httpMethod) { + super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod); + } protected HttpRequest createRequest(String endpointUrl) throws MalformedURLException, IOException { HttpURLConnection connection = (HttpURLConnection) new URL(endpointUrl).openConnection(); - connection.setRequestMethod("POST"); + connection.setRequestMethod(this.method); connection.setAllowUserInteraction(false); connection.setRequestProperty("Content-Length", "0"); return new HttpURLConnectionRequestAdapter(connection); diff --git a/signpost-jetty6/.classpath b/signpost-jetty6/.classpath index e27f6e5..a162450 100644 --- a/signpost-jetty6/.classpath +++ b/signpost-jetty6/.classpath @@ -2,7 +2,7 @@ - + diff --git a/signpost-jetty6/pom.xml b/signpost-jetty6/pom.xml index 139a4a2..d6d815f 100644 --- a/signpost-jetty6/pom.xml +++ b/signpost-jetty6/pom.xml @@ -2,7 +2,7 @@ oauth-signpost oauth.signpost - 1.2.1.1 + 1.2.1.2-SNAPSHOT 4.0.0 signpost-jetty6 @@ -12,7 +12,7 @@ oauth.signpost signpost-core - 1.2.1.1 + ${project.version} compile @@ -24,7 +24,7 @@ oauth.signpost signpost-core - 1.2.1.1 + ${project.version} test-jar test