This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new af41e3766c Allow PATCH method when using rest connection, fixes #7558
(#7562)
af41e3766c is described below
commit af41e3766c26c625e367038de97a37631f573bb8
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Fri Jul 17 19:06:31 2026 +0200
Allow PATCH method when using rest connection, fixes #7558 (#7562)
---
.../apache/hop/metadata/rest/RestConnection.java | 2 +
.../hop/metadata/rest/RestConnectionPatchTest.java | 85 ++++++++++++++++++++++
2 files changed, 87 insertions(+)
diff --git
a/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
index f79abe626e..4674dc5a5d 100644
---
a/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
+++
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
@@ -51,6 +51,7 @@ import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.HopMetadataPropertyType;
import org.apache.hop.metadata.api.IHopMetadata;
import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
@Getter
@@ -192,6 +193,7 @@ public class RestConnection extends HopMetadataBase
implements IHopMetadata {
public Invocation.Builder getInvocationBuilder(String url, String proxyHost,
Integer proxyPort)
throws HopException {
builder = ClientBuilder.newBuilder();
+ builder.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
setProxyHost(proxyHost, proxyPort);
// Configure SSL if needed (client cert, trust store, or ignore SSL)
diff --git
a/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestConnectionPatchTest.java
b/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestConnectionPatchTest.java
new file mode 100644
index 0000000000..03bbf50c45
--- /dev/null
+++
b/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestConnectionPatchTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.metadata.rest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.sun.net.httpserver.HttpServer;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import org.apache.hop.core.variables.Variables;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Regression test for issue #7558: a PATCH request issued through a REST
connection must actually
+ * reach the server. The invocation builder produced by {@link RestConnection}
uses Jersey's default
+ * (JDK {@code HttpURLConnection}) connector, which rejects PATCH unless {@link
+ * org.glassfish.jersey.client.HttpUrlConnectorProvider#SET_METHOD_WORKAROUND}
is enabled. Before
+ * the fix the PATCH failed with a {@code ProcessingException} even though the
URL was assembled
+ * correctly.
+ */
+class RestConnectionPatchTest {
+
+ private HttpServer server;
+ private String url;
+
+ @BeforeEach
+ void startServer() throws Exception {
+ server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);
+ // Echo the HTTP method back so the test can prove PATCH actually reached
the server.
+ server.createContext(
+ "/objects",
+ exchange -> {
+ byte[] body = ("method=" +
exchange.getRequestMethod()).getBytes(StandardCharsets.UTF_8);
+ exchange.sendResponseHeaders(200, body.length);
+ try (OutputStream os = exchange.getResponseBody()) {
+ os.write(body);
+ }
+ });
+ server.start();
+ url = "http://localhost:" + server.getAddress().getPort() + "/objects";
+ }
+
+ @AfterEach
+ void stopServer() {
+ if (server != null) {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void patchThroughConnectionReachesServer() throws Exception {
+ RestConnection connection = new RestConnection(new Variables());
+
+ Invocation.Builder invocationBuilder =
connection.getInvocationBuilder(url);
+ try (Response response =
+ invocationBuilder.method(
+ "PATCH", Entity.entity("{\"name\":\"updated\"}",
MediaType.APPLICATION_JSON_TYPE))) {
+
+ assertEquals(200, response.getStatus());
+ assertEquals("method=PATCH", response.readEntity(String.class));
+ }
+ }
+}