This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 557b5cec fix(settings): disable HTTP redirects in data source
connection tests (#1516)
557b5cec is described below
commit 557b5cec0a51537f9ca81d9ef2eade91220e14bd
Author: youngkermit8-coder <[email protected]>
AuthorDate: Tue Aug 11 20:40:48 2026 +0800
fix(settings): disable HTTP redirects in data source connection tests
(#1516)
Signed-off-by: youngkermit8-coder <[email protected]>
---
.../DataSourceClientHttpRequestFactory.java | 31 +++++++++++++
.../rocketmq/studio/settings/SettingsService.java | 2 +-
.../DataSourceClientHttpRequestFactoryTest.java | 51 ++++++++++++++++++++++
3 files changed, 83 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactory.java
b/server/src/main/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactory.java
new file mode 100644
index 00000000..157a3f36
--- /dev/null
+++
b/server/src/main/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactory.java
@@ -0,0 +1,31 @@
+/*
+ * 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.rocketmq.studio.settings;
+
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+class DataSourceClientHttpRequestFactory extends
SimpleClientHttpRequestFactory {
+
+ @Override
+ protected void prepareConnection(HttpURLConnection connection, String
httpMethod) throws IOException {
+ super.prepareConnection(connection, httpMethod);
+ connection.setInstanceFollowRedirects(false);
+ }
+}
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
b/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
index 432e3bee..6364e2a7 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
@@ -85,7 +85,7 @@ public class SettingsService {
}
private static RestClient buildDataSourceRestClient(RestClient.Builder
restClientBuilder) {
- SimpleClientHttpRequestFactory requestFactory = new
SimpleClientHttpRequestFactory();
+ SimpleClientHttpRequestFactory requestFactory = new
DataSourceClientHttpRequestFactory();
requestFactory.setConnectTimeout(DATA_SOURCE_TEST_CONNECT_TIMEOUT);
requestFactory.setReadTimeout(DATA_SOURCE_TEST_READ_TIMEOUT);
return restClientBuilder.requestFactory(requestFactory).build();
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactoryTest.java
b/server/src/test/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactoryTest.java
new file mode 100644
index 00000000..a81b5224
--- /dev/null
+++
b/server/src/test/java/org/apache/rocketmq/studio/settings/DataSourceClientHttpRequestFactoryTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.rocketmq.studio.settings;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpMethod;
+
+import java.net.HttpURLConnection;
+import java.net.URI;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DataSourceClientHttpRequestFactoryTest {
+
+ @Test
+ void prepareConnectionShouldDisableRedirectsTest() throws Exception {
+ HttpURLConnection connection = (HttpURLConnection)
URI.create("http://example.com")
+ .toURL().openConnection();
+ TestableDataSourceClientHttpRequestFactory requestFactory =
+ new TestableDataSourceClientHttpRequestFactory();
+
+ assertThat(connection.getInstanceFollowRedirects()).isTrue();
+
+ requestFactory.prepare(connection, HttpMethod.GET.name());
+
+ assertThat(connection.getInstanceFollowRedirects()).isFalse();
+ connection.disconnect();
+ }
+
+ private static class TestableDataSourceClientHttpRequestFactory
+ extends DataSourceClientHttpRequestFactory {
+
+ void prepare(HttpURLConnection connection, String httpMethod) throws
Exception {
+ prepareConnection(connection, httpMethod);
+ }
+ }
+}