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..cbdc206 100644 --- a/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java +++ b/signpost-core/src/main/java/oauth/signpost/basic/DefaultOAuthProvider.java @@ -27,33 +27,36 @@ */ public class DefaultOAuthProvider extends AbstractOAuthProvider { - private static final long serialVersionUID = 1L; - - public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, - String authorizationWebsiteUrl) { - super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl); - } - - protected HttpRequest createRequest(String endpointUrl) throws MalformedURLException, - IOException { - HttpURLConnection connection = (HttpURLConnection) new URL(endpointUrl).openConnection(); - connection.setRequestMethod("POST"); - connection.setAllowUserInteraction(false); - connection.setRequestProperty("Content-Length", "0"); - return new HttpURLConnectionRequestAdapter(connection); - } - - protected HttpResponse sendRequest(HttpRequest request) throws IOException { - HttpURLConnection connection = (HttpURLConnection) request.unwrap(); - connection.connect(); - return new HttpURLConnectionResponseAdapter(connection); - } - - @Override - protected void closeConnection(HttpRequest request, HttpResponse response) { - HttpURLConnection connection = (HttpURLConnection) request.unwrap(); - if (connection != null) { - connection.disconnect(); - } - } + private static final long serialVersionUID = 1L; + + public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl, String authorizationWebsiteUrl) { + super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl); + } + + protected HttpRequest createRequest(String endpointUrl) throws MalformedURLException, IOException { + HttpURLConnection connection = (HttpURLConnection) new URL(endpointUrl).openConnection(); + connection.setRequestMethod("POST"); + connection.setAllowUserInteraction(false); + connection.setRequestProperty("Content-Length", "0"); + connection.setDoOutput(true); + return new HttpURLConnectionRequestAdapter(connection); + } + + protected HttpResponse sendRequest(HttpRequest request) throws IOException { + HttpURLConnection connection = (HttpURLConnection) request.unwrap(); + String requestMethod = connection.getRequestMethod(); + if ("POST".equalsIgnoreCase(requestMethod) || "PUT".equalsIgnoreCase(requestMethod)) { + connection.getOutputStream(); + } + connection.connect(); + return new HttpURLConnectionResponseAdapter(connection); + } + + @Override + protected void closeConnection(HttpRequest request, HttpResponse response) { + HttpURLConnection connection = (HttpURLConnection) request.unwrap(); + if (connection != null) { + connection.disconnect(); + } + } }