Skip to content

Commit

Permalink
JCLOUDS-1641: Use POST instead of PATCH for GCS
Browse files Browse the repository at this point in the history
Modern Java versions do not allow the reflection workaround previously
used.
  • Loading branch information
gaul committed Nov 27, 2024
1 parent 44ec4b8 commit 66b44f8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ private void setRequestMethodBypassingJREMethodLimitation(final HttpURLConnectio
try {
// SSL connections may have the HttpURLConnection wrapped inside
delegateField = connectionClass.getDeclaredField("delegate");
// TODO: Fails on modern Java versions:
// Unable to make field private final sun.net.www.protocol.https.DelegateHttpsURLConnection sun.net.www.protocol.https.HttpsURLConnectionImpl.delegate accessible: module java.base does not "opens sun.net.www.protocol.https" to unnamed module @1ed4004b connecting to PATCH
delegateField.setAccessible(true);
HttpURLConnection delegateConnection = (HttpURLConnection) delegateField.get(httpURLConnection);
setRequestMethodBypassingJREMethodLimitation(delegateConnection, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static GoogleCloudStorageOAuthScopes create() {
return fullControlScopes();
} else if (input.getMethod().equalsIgnoreCase("PUT") || input.getMethod().equalsIgnoreCase("PATCH")) {
return fullControlScopes();
} else if ("PATCH".equalsIgnoreCase(input.getFirstHeaderOrNull("X-HTTP-Method-Override"))) {
return fullControlScopes();
}
return readOrWriteScopes().forRequest(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
Expand Down Expand Up @@ -162,7 +162,8 @@ BucketAccessControls updateBucketAccessControls(@PathParam("bucket") String buck
* @return If successful, this method returns a BucketAccessControls resource in the response body
*/
@Named("BucketAccessControls:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}/acl/{entity}")
@Fallback(NullOnNotFoundOr404.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindToJsonPayload;
Expand Down Expand Up @@ -250,7 +250,8 @@ Bucket updateBucket(@PathParam("bucket") String bucketName,
* @return If successful, this method returns the updated {@link Bucket} resource.
*/
@Named("Bucket:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}")
@Fallback(NullOnNotFoundOr404.class)
Expand All @@ -272,7 +273,8 @@ Bucket patchBucket(@PathParam("bucket") String bucketName,
* @return If successful, this method returns the updated {@link Bucket} resource.
*/
@Named("Bucket:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}")
@Fallback(NullOnNotFoundOr404.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
Expand Down Expand Up @@ -170,7 +170,8 @@ ObjectAccessControls updateDefaultObjectAccessControls(@PathParam("bucket") Stri
* Name of the bucket which contains the object
*/
@Named("DefaultObjectAccessControls:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}/defaultObjectAcl/{entity}")
@Fallback(NullOnNotFoundOr404.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
Expand Down Expand Up @@ -282,7 +282,8 @@ ObjectAccessControls updateObjectAccessControls(@PathParam("bucket") String buck
* @return an {@link ObjectAccessControls }
*/
@Named("ObjectAccessControls:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}/o/{object}/acl/{entity}")
ObjectAccessControls patchObjectAccessControls(@PathParam("bucket") String bucketName,
Expand All @@ -307,7 +308,8 @@ ObjectAccessControls patchObjectAccessControls(@PathParam("bucket") String bucke
* @return {@link ObjectAccessControls }
*/
@Named("ObjectAccessControls:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Produces(APPLICATION_JSON)
@Path("/b/{bucket}/o/{object}/acl/{entity}")
ObjectAccessControls patchObjectAccessControls(@PathParam("bucket") String bucketName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
Expand Down Expand Up @@ -310,7 +310,8 @@ GoogleCloudStorageObject updateObject(@PathParam("bucket") String bucketName,
* @return a {@link GoogleCloudStorageObject}
*/
@Named("Object:patch")
@PATCH
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("storage/v1/b/{bucket}/o/{object}")
Expand All @@ -334,7 +335,8 @@ GoogleCloudStorageObject patchObject(@PathParam("bucket") String bucketName,
* @return a {@link GoogleCloudStorageObject}
*/
@Named("Object:patch")
@PUT
@POST
@Headers(keys = "X-HTTP-Method-Override", values = "PATCH")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("storage/v1/b/{bucket}/o/{object}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void patch() throws Exception {

assertEquals(objectApi().patchObject("test", "file_name", template),
new ParseGoogleCloudStorageObject().expected());
assertSent(server, "PATCH", "/storage/v1/b/test/o/file_name", APPLICATION_JSON,
assertSent(server, "POST", "/storage/v1/b/test/o/file_name", APPLICATION_JSON,
"{" +
" \"name\": \"file_name\"," +
" \"size\": 1000," +
Expand Down

0 comments on commit 66b44f8

Please sign in to comment.