This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c68dafe075e3 CAMEL-24768: camel-huaweicloud-dms/-iam - fix ineffective
int-option guards and a fragile property cast (#26503)
c68dafe075e3 is described below
commit c68dafe075e32562eb24c5408cb71bbb7eaa5c7b
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Sep 16 12:20:18 2026 +0200
CAMEL-24768: camel-huaweicloud-dms/-iam - fix ineffective int-option guards
and a fragile property cast (#26503)
Fixes ineffective int-option guards (mandatory-field and proxy-port
validation that never triggered) and a
fragile exchange-property cast in camel-huaweicloud-dms and
camel-huaweicloud-iam.
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
.../component/huaweicloud/dms/DMSEndpoint.java | 2 +-
.../component/huaweicloud/dms/DMSProducer.java | 8 +-
.../dms/CreateInstanceMissingStorageSpaceTest.java | 100 +++++++++++++++++++++
.../component/huaweicloud/iam/IAMEndpoint.java | 2 +-
4 files changed, 106 insertions(+), 6 deletions(-)
diff --git
a/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSEndpoint.java
b/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSEndpoint.java
index dd80cd65ccc5..58a60ccfc76d 100644
---
a/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSEndpoint.java
+++
b/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSEndpoint.java
@@ -469,7 +469,7 @@ public class DMSEndpoint extends DefaultEndpoint {
HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig();
httpConfig.withIgnoreSSLVerification(isIgnoreSslVerification());
if (ObjectHelper.isNotEmpty(getProxyHost())
- && ObjectHelper.isNotEmpty(getProxyPort())) {
+ && getProxyPort() > 0) {
httpConfig.withProxyHost(getProxyHost())
.withProxyPort(getProxyPort());
diff --git
a/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSProducer.java
b/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSProducer.java
index 507d39d24d9d..048940fd5540 100644
---
a/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSProducer.java
+++
b/components/camel-huawei/camel-huaweicloud-dms/src/main/java/org/apache/camel/component/huaweicloud/dms/DMSProducer.java
@@ -132,7 +132,7 @@ public class DMSProducer extends DefaultProducer {
if
(ObjectHelper.isEmpty(clientConfigurations.getSpecification())) {
throw new IllegalArgumentException("Specification is
mandatory to create a Kafka instance");
}
- if
(ObjectHelper.isEmpty(clientConfigurations.getPartitionNum())) {
+ if (clientConfigurations.getPartitionNum() == null ||
clientConfigurations.getPartitionNum() <= 0) {
throw new IllegalArgumentException("Partition number is
mandatory to create a Kafka instance");
}
if
(ObjectHelper.isEmpty(clientConfigurations.getKafkaManagerUser())) {
@@ -153,7 +153,7 @@ public class DMSProducer extends DefaultProducer {
throw new IllegalArgumentException("Engine must be 'kafka' or
'rabbitmq'");
}
- if (ObjectHelper.isEmpty(clientConfigurations.getStorageSpace())) {
+ if (clientConfigurations.getStorageSpace() == null ||
clientConfigurations.getStorageSpace() <= 0) {
throw new IllegalArgumentException("Storage space is mandatory
to create an instance");
}
if (ObjectHelper.isEmpty(clientConfigurations.getVpcId())) {
@@ -344,13 +344,13 @@ public class DMSProducer extends DefaultProducer {
// checking for storage space
clientConfigurations.setStorageSpace(
ObjectHelper.isNotEmpty(exchange.getProperty(DMSProperties.STORAGE_SPACE))
- ? (Integer)
exchange.getProperty(DMSProperties.STORAGE_SPACE)
+ ? exchange.getProperty(DMSProperties.STORAGE_SPACE,
Integer.class)
: endpoint.getStorageSpace());
// checking for partition number
clientConfigurations.setPartitionNum(
ObjectHelper.isNotEmpty(exchange.getProperty(DMSProperties.PARTITION_NUM))
- ? (Integer)
exchange.getProperty(DMSProperties.PARTITION_NUM)
+ ? exchange.getProperty(DMSProperties.PARTITION_NUM,
Integer.class)
: endpoint.getPartitionNum());
// checking for access user
diff --git
a/components/camel-huawei/camel-huaweicloud-dms/src/test/java/org/apache/camel/component/huaweicloud/dms/CreateInstanceMissingStorageSpaceTest.java
b/components/camel-huawei/camel-huaweicloud-dms/src/test/java/org/apache/camel/component/huaweicloud/dms/CreateInstanceMissingStorageSpaceTest.java
new file mode 100644
index 000000000000..1c5fc4c39da1
--- /dev/null
+++
b/components/camel-huawei/camel-huaweicloud-dms/src/test/java/org/apache/camel/component/huaweicloud/dms/CreateInstanceMissingStorageSpaceTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.camel.component.huaweicloud.dms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.common.models.ServiceKeys;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The "Storage space is mandatory" guard must fire when storageSpace is left
at its endpoint default. It comes from a
+ * primitive int option, so the previous {@code ObjectHelper.isEmpty(Integer)}
check was always false and the guard
+ * never triggered (storage_space:0 was sent instead).
+ */
+public class CreateInstanceMissingStorageSpaceTest extends CamelTestSupport {
+ TestConfiguration testConfiguration = new TestConfiguration();
+
+ @BindToRegistry("dmsClient")
+ DmsClient mockClient = Mockito.mock(DmsClient.class);
+
+ @BindToRegistry("serviceKeys")
+ ServiceKeys serviceKeys = new ServiceKeys(
+ testConfiguration.getProperty("accessKey"),
+ testConfiguration.getProperty("secretKey"));
+
+ @BindToRegistry("availableZones")
+ List<String> availableZones = new ArrayList<>();
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:operation")
+ .to("hwcloud-dms:createInstance?" +
+ "serviceKeys=#serviceKeys" +
+ "&projectId=" +
testConfiguration.getProperty("projectId") +
+ "®ion=" +
testConfiguration.getProperty("region") +
+ "&instanceId=" +
testConfiguration.getProperty("instanceId") +
+ "&ignoreSslVerification=true" +
+ "&dmsClient=#dmsClient" +
+ "&name=" + testConfiguration.getProperty("name") +
+ "&engine=rabbitmq" +
+ "&engineVersion=" +
testConfiguration.getProperty("engineVersion") +
+ // storageSpace intentionally omitted -> endpoint default 0
+ "&accessUser=" +
testConfiguration.getProperty("accessUser") +
+ "&password=" +
testConfiguration.getProperty("password") +
+ "&vpcId=" + testConfiguration.getProperty("vpcId")
+
+ "&securityGroupId=" +
testConfiguration.getProperty("securityGroupId") +
+ "&subnetId=" +
testConfiguration.getProperty("subnetId") +
+ "&availableZones=#availableZones" +
+ "&productId=" +
testConfiguration.getProperty("productId") +
+ "&storageSpecCode=" +
testConfiguration.getProperty("storageSpecCode"))
+ .to("mock:operation_result");
+ }
+ };
+ }
+
+ @Test
+ public void missingStorageSpaceIsRejected() {
+ availableZones.add(testConfiguration.getProperty("availableZone"));
+
+ Exchange result = template.request("direct:operation", e ->
e.getIn().setBody("sample_body"));
+
+ Throwable cause = result.getException();
+ assertNotNull(cause, "a create with no storageSpace was expected to
fail");
+ boolean mandatory = false;
+ while (cause != null) {
+ if (cause instanceof IllegalArgumentException &&
cause.getMessage() != null
+ && cause.getMessage().contains("Storage space is
mandatory")) {
+ mandatory = true;
+ break;
+ }
+ cause = cause.getCause();
+ }
+ assertTrue(mandatory, "expected 'Storage space is mandatory', got: " +
result.getException());
+ }
+}
diff --git
a/components/camel-huawei/camel-huaweicloud-iam/src/main/java/org/apache/camel/component/huaweicloud/iam/IAMEndpoint.java
b/components/camel-huawei/camel-huaweicloud-iam/src/main/java/org/apache/camel/component/huaweicloud/iam/IAMEndpoint.java
index 127f133ce623..2c1256e52515 100644
---
a/components/camel-huawei/camel-huaweicloud-iam/src/main/java/org/apache/camel/component/huaweicloud/iam/IAMEndpoint.java
+++
b/components/camel-huawei/camel-huaweicloud-iam/src/main/java/org/apache/camel/component/huaweicloud/iam/IAMEndpoint.java
@@ -245,7 +245,7 @@ public class IAMEndpoint extends DefaultEndpoint {
HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig();
httpConfig.withIgnoreSSLVerification(isIgnoreSslVerification());
if (ObjectHelper.isNotEmpty(getProxyHost())
- && ObjectHelper.isNotEmpty(getProxyPort())) {
+ && getProxyPort() > 0) {
httpConfig.withProxyHost(getProxyHost())
.withProxyPort(getProxyPort());