You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/01/18 18:02:36 UTC

[GitHub] [camel] mathewsreji opened a new pull request #4900: Camel component for HuaweiCloud Simple Notification Services (SMN) se…

mathewsreji opened a new pull request #4900:
URL: https://github.com/apache/camel/pull/4900


   …rvices
   
   SMN is one among the Cloud product offering within HuaweiCloud ecosystem which enables cloud application users to broadcast/send out notifications to subscribers. It provides a single unified endpoint aka. topic for the application to push data.
   
   Multiple subscribers can be associated with a given topic. Simple Message Notification (SMN) enables you to broadcast messages to subscribers who can chose to receive the notifications via an email addresses, phone numbers, serverless functions and HTTP/HTTPS servers and connect cloud services through notifications, reducing system complexity and developmental efforts to the publishing app.
   
   - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
   - [ ] Each commit in the pull request should have a meaningful subject line and body.
   - [ ] If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Run `mvn clean install -Psourcecheck` in your module with source check enabled to make sure basic checks pass and there are no checkstyle violations. A more thorough check will be performed on your pull request automatically.
   Below are the contribution guidelines:
   https://github.com/apache/camel/blob/master/CONTRIBUTING.md


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024294



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {

Review comment:
       Removed wiremocks (as it can potentially cause port conflicts in worst case). Referred testing strategy of aws-s3 camel component by mocking SmnClient 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565025533



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {

Review comment:
       lazy initialization has been removed. instead moved the routine call inside constructor




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565388052



##########
File path: components/camel-huaweicloud-smn/src/test/resources/log4j2.properties
##########
@@ -0,0 +1,7 @@
+

Review comment:
       We need to add the Apache License Header here.

##########
File path: components/camel-huaweicloud-smn/src/test/resources/testconfiguration.properties
##########
@@ -0,0 +1,6 @@
+## Test configurations

Review comment:
       We need to add the Apache License Header here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565393111



##########
File path: components/camel-huaweicloud-smn/src/test/resources/testconfiguration.properties
##########
@@ -0,0 +1,6 @@
+## Test configurations

Review comment:
       License header added




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565359436



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnProperties;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        validateAndInitializeSmnClient((SimpleNotificationEndpoint) super.getEndpoint());

Review comment:
       Looks like SmnClient class from SDK library doesn't have a close method. So skipping doStop adjustments. I will drop a recommendation to the sdk team to have this in future releases. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565053683



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       @mathewsreji  you are still use getField() method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang merged pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang merged pull request #4900:
URL: https://github.com/apache/camel/pull/4900


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024384



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;

Review comment:
       Redundancy removed from the code




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r559850830



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;

Review comment:
       Please add the License header on all the test java files.

##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;

Review comment:
       It may cause some trouble in CI if the test port is used.
   There is a port lookup util method in Camel that you can take a look.

##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;
+
+    TestConfiguration testConfiguration = new TestConfiguration();
+
+    WireMockServer wireMockServer;
+
+    @BindToRegistry("serviceKeys")
+    ServiceKeys serviceKeys
+            = new ServiceKeys(testConfiguration.getProperty("authKey"), testConfiguration.getProperty("secretKey"));
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        // populating tag values. user has to adjust the map entries according to the structure of their respective templates
+        Map<String, String> tags = new HashMap<>();
+        tags.put("name", "reji");
+        tags.put("phone", "1234567890");
+
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:publish_templated_message")
+                        .setProperty("CamelHwCloudSmnSubject", constant("This is my subjectline"))
+                        .setProperty("CamelHwCloudSmnTopic", constant(testConfiguration.getProperty("topic")))
+                        .setProperty("CamelHwCloudSmnMessageTtl", constant(60))
+                        .setProperty("CamelHwCloudSmnTemplateTags", constant(tags))
+                        .setProperty("CamelHwCloudSmnTemplateName", constant("hello-template"))
+                        //.to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"+"&projectId="+testConfiguration.getProperty("projectId")+"&region="+testConfiguration.getProperty("region")+"&proxyHost=localhost&proxyPort=3128&ignoreSslVerification=true")
+                        .to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"
+                            + "&projectId=" + testConfiguration.getProperty("projectId") + "&region="
+                            + testConfiguration.getProperty("region") + "&ignoreSslVerification=true")
+                        .log("templated notification sent")
+                        .to("mock:publish_templated_message_result");
+            }
+        };
+    }
+
+    private void setupSimpleNotificationsUtilsMock() {
+        try {
+            Mockito.mockStatic(SimpleNotificationUtils.class);
+            Mockito.when(SimpleNotificationUtils.resolveSmnServiceEndpoint("unit-test"))
+                    .thenReturn("http://localhost:" + wiremockServerPort);
+        } catch (MockitoException e) {
+            LOGGER.info("Mock already registered. Using existing registration");
+        }
+    }
+
+    @Test
+    public void testTemplatedNotificationSend() throws Exception {
+        boolean isMockedServerTest = testConfiguration.getProperty("region").equals("unit-test");
+        if (isMockedServerTest) {
+            LOGGER.info("region is unit-test. Starting up wiremock stubs");
+            initWireMock();
+            setupSimpleNotificationsUtilsMock();
+        }
+
+        MockEndpoint mock = getMockEndpoint("mock:publish_templated_message_result");
+        mock.expectedMinimumMessageCount(1);
+        template.sendBody("direct:publish_templated_message", null);
+        Exchange responseExchange = mock.getExchanges().get(0);
+
+        mock.assertIsSatisfied();
+
+        Assert.assertNotNull(responseExchange.getProperty("CamelSmnMesssageId"));
+        Assert.assertNotNull(responseExchange.getProperty("CamelSmnRequestId"));
+        Assert.assertTrue(responseExchange.getProperty("CamelSmnMesssageId").toString().length() > 0);
+        Assert.assertTrue(responseExchange.getProperty("CamelSmnRequestId").toString().length() > 0);
+
+        if (isMockedServerTest) {
+            Assert.assertEquals("bf94b63a5dfb475994d3ac34664e24f2", responseExchange.getProperty("CamelSmnMesssageId"));
+            Assert.assertEquals("6a63a18b8bab40ffb71ebd9cb80d0085", responseExchange.getProperty("CamelSmnRequestId"));
+
+            LoggedRequest loggedRequest = TestUtils.retrieveTemplatedNotificationRequest(getAllServeEvents());
+            LOGGER.info("Verifying wiremock request");
+            Assert.assertEquals(
+                    "http://localhost:8080/v2/9071a38e7f6a4ba7b7bcbeb7d4ea6efc/notifications/topics/urn:smn:unit-test:9071a38e7f6a4ba7b7bcbeb7d4ea6efc:reji-test/publish",
+                    loggedRequest.getAbsoluteUrl());
+            Assert.assertEquals(
+                    "eyJzdWJqZWN0IjoiVGhpcyBpcyBteSBzdWJqZWN0bGluZSIsIm1lc3NhZ2VfdGVtcGxhdGVfbmFtZSI6ImhlbGxvLXRlbXBsYXRlIiwidGFncyI6eyJwaG9uZSI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoicmVqaSJ9LCJ0aW1lX3RvX2xpdmUiOiI2MCJ9",
+                    loggedRequest.getBodyAsBase64());
+            Assert.assertEquals(
+                    "{\"subject\":\"This is my subjectline\",\"message_template_name\":\"hello-template\",\"tags\":{\"phone\":\"1234567890\",\"name\":\"reji\"},\"time_to_live\":\"60\"}",
+                    loggedRequest.getBodyAsString());
+        }
+    }
+
+    private void initWireMock() throws Exception {
+        try {
+            wireMockServer = new WireMockServer(wiremockServerPort);
+            wireMockServer.start();
+        } catch (Exception e) {
+            LOGGER.info("wiremock server already registered in test context. using the same");

Review comment:
       We should throw the exception beside printing a log.

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       I'm not sure if we can still use reflection in Camel 3.0 to support camel-quarkus.
   Please double check it with the community.

##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;
+
+    TestConfiguration testConfiguration = new TestConfiguration();
+
+    WireMockServer wireMockServer;
+
+    @BindToRegistry("serviceKeys")
+    ServiceKeys serviceKeys
+            = new ServiceKeys(testConfiguration.getProperty("authKey"), testConfiguration.getProperty("secretKey"));
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        // populating tag values. user has to adjust the map entries according to the structure of their respective templates
+        Map<String, String> tags = new HashMap<>();
+        tags.put("name", "reji");
+        tags.put("phone", "1234567890");
+
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:publish_templated_message")
+                        .setProperty("CamelHwCloudSmnSubject", constant("This is my subjectline"))
+                        .setProperty("CamelHwCloudSmnTopic", constant(testConfiguration.getProperty("topic")))
+                        .setProperty("CamelHwCloudSmnMessageTtl", constant(60))
+                        .setProperty("CamelHwCloudSmnTemplateTags", constant(tags))
+                        .setProperty("CamelHwCloudSmnTemplateName", constant("hello-template"))
+                        //.to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"+"&projectId="+testConfiguration.getProperty("projectId")+"&region="+testConfiguration.getProperty("region")+"&proxyHost=localhost&proxyPort=3128&ignoreSslVerification=true")
+                        .to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"
+                            + "&projectId=" + testConfiguration.getProperty("projectId") + "&region="
+                            + testConfiguration.getProperty("region") + "&ignoreSslVerification=true")
+                        .log("templated notification sent")
+                        .to("mock:publish_templated_message_result");
+            }
+        };
+    }
+
+    private void setupSimpleNotificationsUtilsMock() {
+        try {
+            Mockito.mockStatic(SimpleNotificationUtils.class);

Review comment:
       It's not a good practice to mock the static utils method.
   As we cannot verify the code of mocked static method in the unit test.

##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {

Review comment:
       we can consider to reuse the WireMock setup code across PublishTemplatedMessageTest and PublishTextMessageTest.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
oscerd commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r559928628



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       No, we should avoid it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r564774880



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;

Review comment:
       Sounds like a better idea. I will get the wiremock removed and instead have a mocked client. Thanks




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565370884



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       @WillemJiang - I have removed reflections completely from component code. I see it used inside the unit test  for models. I guess will just remove the testing classes ClientConfigurations and ServiceKeys. It's an overkill I guess. Removing it and checking in the code. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565051872



##########
File path: components/camel-huaweicloud-smn/pom.xml
##########
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Review comment:
       Please add ASF license header here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
omarsmak commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r560055021



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;

Review comment:
       this is redundant, since the super class's constructor takes the endpoint. Hence, you can add a method `getEndpoint` that casts your endpoint implementation, e.g: `(SimpleNotificationEndpoint) super.getEndpoint()`

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");

Review comment:
       out of curiosity, do you think it just makes sense to have a default service instead of throwing an error? especially that there is currently one service implemented 

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(
+                        String.format("operation %s not supported in publishMessage service",
+                                clientConfigurations.getOperation()));
+        }
+        setResponseParameters(exchange, response);
+    }
+
+    /**
+     * maps api response parameters as exchange property
+     * 
+     * @param exchange
+     * @param response
+     */
+    private void setResponseParameters(Exchange exchange, PublishMessageResponse response) {
+        if (response == null) {
+            return; // mapping is not required if response object is null
+        }
+        if (!ObjectHelper.isEmpty(response.getMessageId())) {
+            exchange.setProperty("CamelSmnMesssageId", response.getMessageId());
+        }
+        if (!ObjectHelper.isEmpty(response.getRequestId())) {
+            exchange.setProperty("CamelSmnRequestId", response.getRequestId());
+        }
+    }
+
+    /**
+     * validation and initialization of SmnClient object
+     *
+     * @param simpleNotificationEndpoint
+     */
+    private void validateAndInitializeSmnClient(SimpleNotificationEndpoint simpleNotificationEndpoint) {
+        this.clientConfigurations = new ClientConfigurations();
+
+        //checking for cloud SK (secret key)
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getSecretKey()) &&
+                ObjectHelper.isEmpty(simpleNotificationEndpoint.getServiceKeys())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("secret key (SK) not found");
+            }
+            throw new IllegalArgumentException("authentication parameter 'secret key (SK)' not found");
+        } else {
+            clientConfigurations.setSecretKey(simpleNotificationEndpoint.getSecretKey() != null
+                    ? simpleNotificationEndpoint.getSecretKey() : simpleNotificationEndpoint.getServiceKeys().getSecretKey());
+        }
+
+        //checking for cloud AK (auth key)
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getAuthKey()) &&
+                ObjectHelper.isEmpty(simpleNotificationEndpoint.getServiceKeys())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("authentication key (AK) not found");
+            }
+            throw new IllegalArgumentException("authentication parameter 'authentication key (AK)' not found");
+        } else {
+            clientConfigurations.setAuthenticationkey(simpleNotificationEndpoint.getAuthKey() != null
+                    ? simpleNotificationEndpoint.getAuthKey()
+                    : simpleNotificationEndpoint.getServiceKeys().getAuthenticationKey());
+        }
+
+        //checking for project ID
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getProjectId())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Project ID not found");
+            }
+            throw new IllegalArgumentException("project ID not found");
+        } else {
+            clientConfigurations.setProjectId(simpleNotificationEndpoint.getProjectId());
+        }
+
+        //checking for region
+        String endpointUrl = SimpleNotificationUtils.resolveSmnServiceEndpoint(simpleNotificationEndpoint.getRegion());
+        if (endpointUrl == null) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Valid region not found");
+            }
+            throw new IllegalArgumentException("enter a valid region");
+        } else {
+            clientConfigurations.setServiceEndpoint(endpointUrl);
+        }
+
+        //checking for ignore ssl verification
+        boolean ignoreSslVerification = simpleNotificationEndpoint.isIgnoreSslVerification();
+        if (ignoreSslVerification) {
+            if (LOG.isWarnEnabled()) {
+                LOG.error("SSL verification is ignored. This is unsafe in production environment");
+            }
+            clientConfigurations.setIgnoreSslVerification(ignoreSslVerification);
+        }
+
+        //checking if http proxy authentication is used
+        if (simpleNotificationEndpoint.getProxyHost() != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Reading http proxy configurations");
+            }
+            clientConfigurations.setProxyHost(simpleNotificationEndpoint.getProxyHost());
+            clientConfigurations.setProxyPort(simpleNotificationEndpoint.getProxyPort());
+            clientConfigurations.setProxyUser(simpleNotificationEndpoint.getProxyUser());
+            clientConfigurations.setProxyPassword(simpleNotificationEndpoint.getProxyPassword());
+        }
+
+        this.smnClient = initializeClient(clientConfigurations);
+    }
+
+    /**
+     * initialization of smn client. this is lazily initialized on the first message
+     * 
+     * @param  clientConfigurations
+     * @return
+     */
+    private SmnClient initializeClient(ClientConfigurations clientConfigurations) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Initializing Smn client");
+        }
+        HttpConfig httpConfig = null;
+
+        if (clientConfigurations.getProxyHost() != null) {
+            httpConfig = HttpConfig.getDefaultHttpConfig();
+            httpConfig.withProxyHost(clientConfigurations.getProxyHost())
+                    .withProxyPort(clientConfigurations.getProxyPort())
+                    .setIgnoreSSLVerification(clientConfigurations.isIgnoreSslVerification());
+
+            if (clientConfigurations.getProxyUser() != null) {
+                httpConfig.withProxyUsername(clientConfigurations.getProxyUser());
+                httpConfig.withProxyPassword(clientConfigurations.getProxyPassword());
+            }
+        }
+
+        BasicCredentials credentials = new BasicCredentials()
+                .withAk(clientConfigurations.getAuthenticationkey())
+                .withSk(clientConfigurations.getSecretKey())
+                .withProjectId(clientConfigurations.getProjectId());
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Building Smn client");
+        }
+
+        // building smn client object
+        SmnClient smnClient = SmnClient.newBuilder()
+                .withCredential(credentials)
+                .withHttpConfig(httpConfig)
+                .withEndpoint(clientConfigurations.getServiceEndpoint())
+                .build();
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Successfully initialized Smn client");
+        }
+        return smnClient;
+    }
+
+    /**
+     * validation of all user inputs before attempting to invoke a service operation
+     *
+     * @param  simpleNotificationEndpoint
+     * @param  exchange
+     * @return
+     */
+    private ClientConfigurations validateServiceConfigurations(
+            SimpleNotificationEndpoint simpleNotificationEndpoint, Exchange exchange) {
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Inspecting exchange body");
+        }
+        // verifying if exchange has valid body content. this is mandatory for 'publish as text' operation
+        if (ObjectHelper.isEmpty(exchange.getMessage().getBody())) {
+            if (simpleNotificationEndpoint.getOperation().equals("publishAsTextMessage")) {
+                if (LOG.isErrorEnabled()) {
+                    LOG.error("Found null/empty body. Cannot perform publish as text operation");
+                }
+                throw new IllegalArgumentException("exchange body cannot be null / empty");
+            }
+        }
+
+        // checking for mandatory field 'operation name'
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Inspecting operation name");
+        }
+        if (ObjectHelper.isEmpty(exchange.getProperty("CamelHwCloudOperation"))
+                && ObjectHelper.isEmpty(simpleNotificationEndpoint.getOperation())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Found null/empty operation name. Cannot proceed with Smn operations");
+            }
+            throw new IllegalArgumentException("operation name not found");
+        } else {
+            clientConfigurations.setOperation(exchange.getProperty("CamelHwCloudOperation") != null

Review comment:
       same here for the exchange properties constants 

##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;

Review comment:
       In general, I would like us to avoid the external mocking as much as possible. Did you consider to mock `SmnClient` instead? Meaning that, create a test SmnClient client that overrides the functionality of  `SmnClient` with your mocked functionality instead. And then add the ability in the endpoint to set the client explicitly. With that you won't need wiremock, your service is mocked by yourself, e.g: https://github.com/apache/camel/blob/master/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java and then you can see that in the other tests, the mocked client was supplied

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/constants/SmnConstants.java
##########
@@ -0,0 +1,22 @@
+/*
+ * 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.smn.constants;
+
+public class SmnConstants {

Review comment:
       constant class means private constructor 

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {

Review comment:
       any reason why the `smsClient` has to be lazily initialized and not on the `start` method?

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(
+                        String.format("operation %s not supported in publishMessage service",
+                                clientConfigurations.getOperation()));
+        }
+        setResponseParameters(exchange, response);
+    }
+
+    /**
+     * maps api response parameters as exchange property
+     * 
+     * @param exchange
+     * @param response
+     */
+    private void setResponseParameters(Exchange exchange, PublishMessageResponse response) {
+        if (response == null) {
+            return; // mapping is not required if response object is null
+        }
+        if (!ObjectHelper.isEmpty(response.getMessageId())) {
+            exchange.setProperty("CamelSmnMesssageId", response.getMessageId());

Review comment:
       I would prefer to separate the headers properties and exchange properties into a separate constant class, e.g: `SimpleNotificationConstants`. You can take a look at other components for reference

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(

Review comment:
       also here a default operation instead of throwing an error

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {

Review comment:
       private constructor here is missing for the utility class




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024654



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(
+                        String.format("operation %s not supported in publishMessage service",
+                                clientConfigurations.getOperation()));
+        }
+        setResponseParameters(exchange, response);
+    }
+
+    /**
+     * maps api response parameters as exchange property
+     * 
+     * @param exchange
+     * @param response
+     */
+    private void setResponseParameters(Exchange exchange, PublishMessageResponse response) {
+        if (response == null) {
+            return; // mapping is not required if response object is null
+        }
+        if (!ObjectHelper.isEmpty(response.getMessageId())) {
+            exchange.setProperty("CamelSmnMesssageId", response.getMessageId());
+        }
+        if (!ObjectHelper.isEmpty(response.getRequestId())) {
+            exchange.setProperty("CamelSmnRequestId", response.getRequestId());
+        }
+    }
+
+    /**
+     * validation and initialization of SmnClient object
+     *
+     * @param simpleNotificationEndpoint
+     */
+    private void validateAndInitializeSmnClient(SimpleNotificationEndpoint simpleNotificationEndpoint) {
+        this.clientConfigurations = new ClientConfigurations();
+
+        //checking for cloud SK (secret key)
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getSecretKey()) &&
+                ObjectHelper.isEmpty(simpleNotificationEndpoint.getServiceKeys())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("secret key (SK) not found");
+            }
+            throw new IllegalArgumentException("authentication parameter 'secret key (SK)' not found");
+        } else {
+            clientConfigurations.setSecretKey(simpleNotificationEndpoint.getSecretKey() != null
+                    ? simpleNotificationEndpoint.getSecretKey() : simpleNotificationEndpoint.getServiceKeys().getSecretKey());
+        }
+
+        //checking for cloud AK (auth key)
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getAuthKey()) &&
+                ObjectHelper.isEmpty(simpleNotificationEndpoint.getServiceKeys())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("authentication key (AK) not found");
+            }
+            throw new IllegalArgumentException("authentication parameter 'authentication key (AK)' not found");
+        } else {
+            clientConfigurations.setAuthenticationkey(simpleNotificationEndpoint.getAuthKey() != null
+                    ? simpleNotificationEndpoint.getAuthKey()
+                    : simpleNotificationEndpoint.getServiceKeys().getAuthenticationKey());
+        }
+
+        //checking for project ID
+        if (ObjectHelper.isEmpty(simpleNotificationEndpoint.getProjectId())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Project ID not found");
+            }
+            throw new IllegalArgumentException("project ID not found");
+        } else {
+            clientConfigurations.setProjectId(simpleNotificationEndpoint.getProjectId());
+        }
+
+        //checking for region
+        String endpointUrl = SimpleNotificationUtils.resolveSmnServiceEndpoint(simpleNotificationEndpoint.getRegion());
+        if (endpointUrl == null) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Valid region not found");
+            }
+            throw new IllegalArgumentException("enter a valid region");
+        } else {
+            clientConfigurations.setServiceEndpoint(endpointUrl);
+        }
+
+        //checking for ignore ssl verification
+        boolean ignoreSslVerification = simpleNotificationEndpoint.isIgnoreSslVerification();
+        if (ignoreSslVerification) {
+            if (LOG.isWarnEnabled()) {
+                LOG.error("SSL verification is ignored. This is unsafe in production environment");
+            }
+            clientConfigurations.setIgnoreSslVerification(ignoreSslVerification);
+        }
+
+        //checking if http proxy authentication is used
+        if (simpleNotificationEndpoint.getProxyHost() != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Reading http proxy configurations");
+            }
+            clientConfigurations.setProxyHost(simpleNotificationEndpoint.getProxyHost());
+            clientConfigurations.setProxyPort(simpleNotificationEndpoint.getProxyPort());
+            clientConfigurations.setProxyUser(simpleNotificationEndpoint.getProxyUser());
+            clientConfigurations.setProxyPassword(simpleNotificationEndpoint.getProxyPassword());
+        }
+
+        this.smnClient = initializeClient(clientConfigurations);
+    }
+
+    /**
+     * initialization of smn client. this is lazily initialized on the first message
+     * 
+     * @param  clientConfigurations
+     * @return
+     */
+    private SmnClient initializeClient(ClientConfigurations clientConfigurations) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Initializing Smn client");
+        }
+        HttpConfig httpConfig = null;
+
+        if (clientConfigurations.getProxyHost() != null) {
+            httpConfig = HttpConfig.getDefaultHttpConfig();
+            httpConfig.withProxyHost(clientConfigurations.getProxyHost())
+                    .withProxyPort(clientConfigurations.getProxyPort())
+                    .setIgnoreSSLVerification(clientConfigurations.isIgnoreSslVerification());
+
+            if (clientConfigurations.getProxyUser() != null) {
+                httpConfig.withProxyUsername(clientConfigurations.getProxyUser());
+                httpConfig.withProxyPassword(clientConfigurations.getProxyPassword());
+            }
+        }
+
+        BasicCredentials credentials = new BasicCredentials()
+                .withAk(clientConfigurations.getAuthenticationkey())
+                .withSk(clientConfigurations.getSecretKey())
+                .withProjectId(clientConfigurations.getProjectId());
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Building Smn client");
+        }
+
+        // building smn client object
+        SmnClient smnClient = SmnClient.newBuilder()
+                .withCredential(credentials)
+                .withHttpConfig(httpConfig)
+                .withEndpoint(clientConfigurations.getServiceEndpoint())
+                .build();
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Successfully initialized Smn client");
+        }
+        return smnClient;
+    }
+
+    /**
+     * validation of all user inputs before attempting to invoke a service operation
+     *
+     * @param  simpleNotificationEndpoint
+     * @param  exchange
+     * @return
+     */
+    private ClientConfigurations validateServiceConfigurations(
+            SimpleNotificationEndpoint simpleNotificationEndpoint, Exchange exchange) {
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Inspecting exchange body");
+        }
+        // verifying if exchange has valid body content. this is mandatory for 'publish as text' operation
+        if (ObjectHelper.isEmpty(exchange.getMessage().getBody())) {
+            if (simpleNotificationEndpoint.getOperation().equals("publishAsTextMessage")) {
+                if (LOG.isErrorEnabled()) {
+                    LOG.error("Found null/empty body. Cannot perform publish as text operation");
+                }
+                throw new IllegalArgumentException("exchange body cannot be null / empty");
+            }
+        }
+
+        // checking for mandatory field 'operation name'
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Inspecting operation name");
+        }
+        if (ObjectHelper.isEmpty(exchange.getProperty("CamelHwCloudOperation"))
+                && ObjectHelper.isEmpty(simpleNotificationEndpoint.getOperation())) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Found null/empty operation name. Cannot proceed with Smn operations");
+            }
+            throw new IllegalArgumentException("operation name not found");
+        } else {
+            clientConfigurations.setOperation(exchange.getProperty("CamelHwCloudOperation") != null

Review comment:
       Moved to SmnProperties class




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565029333



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(

Review comment:
       > also here a default operation instead of throwing an error
   
   @omarsmak 
   After analysis, I suggest it would be nice to keep it concrete with mandatory/right operation name because input for each operations are slightly different. if  user misses out on correct inputs/properties, then API might error out. Sdk team will be expanding support for more services and operations. so once we have a bigger list, we could analyze on a good candidate to become a default service/operation




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r560303397



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(

Review comment:
       I think defaulting to publishAsTextMessage is good idea. i'll check it out  




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565356560



##########
File path: components/camel-huaweicloud-smn/pom.xml
##########
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Review comment:
       License header has been added and checked in now. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on pull request #4900:
URL: https://github.com/apache/camel/pull/4900#issuecomment-762951341


   @WillemJiang @oscerd - thanks for the review comments. I will resolve each of them shortly.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on pull request #4900:
URL: https://github.com/apache/camel/pull/4900#issuecomment-762436885


   JIRA logged at https://issues.apache.org/jira/browse/CAMEL-16001


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565358080



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnProperties;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        validateAndInitializeSmnClient((SimpleNotificationEndpoint) super.getEndpoint());

Review comment:
       @omarsmak Thats a great way. I just overrid the doStart() method of parent DefaultProducer. Code checked in . thanks




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024581



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");
+        }
+    }
+
+    /**
+     * Publish message service operations
+     *
+     * @param endpoint
+     * @param exchange
+     */
+    private void performPublishMessageServiceOperations(SimpleNotificationEndpoint endpoint, Exchange exchange) {
+        PublishMessageResponse response;
+
+        PublishMessageRequestBody apiBody;
+        this.clientConfigurations = validateServiceConfigurations(endpoint, exchange);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Checking operation name");
+        }
+        switch (clientConfigurations.getOperation()) {
+
+            case SmnOperations.PUBLISH_AS_TEXT_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as text message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            case SmnOperations.PUBLISH_AS_TEMPLATED_MESSAGE:
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Publishing as templated message");
+                }
+                apiBody = new PublishMessageRequestBody()
+                        .withMessage(exchange.getMessage().getBody(String.class))
+                        .withSubject(clientConfigurations.getSubject())
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()))
+                        .withMessageTemplateName((String) exchange.getProperty("CamelHwCloudSmnTemplateName"))
+                        .withTags((HashMap<String, String>) exchange.getProperty("CamelHwCloudSmnTemplateTags"))
+                        .withTimeToLive(String.valueOf(clientConfigurations.getMessageTtl()));
+
+                response = smnClient.publishMessage(new PublishMessageRequest()
+                        .withBody(apiBody)
+                        .withTopicUrn(clientConfigurations.getTopicUrn()));
+                break;
+
+            default:
+                throw new UnsupportedOperationException(
+                        String.format("operation %s not supported in publishMessage service",
+                                clientConfigurations.getOperation()));
+        }
+        setResponseParameters(exchange, response);
+    }
+
+    /**
+     * maps api response parameters as exchange property
+     * 
+     * @param exchange
+     * @param response
+     */
+    private void setResponseParameters(Exchange exchange, PublishMessageResponse response) {
+        if (response == null) {
+            return; // mapping is not required if response object is null
+        }
+        if (!ObjectHelper.isEmpty(response.getMessageId())) {
+            exchange.setProperty("CamelSmnMesssageId", response.getMessageId());

Review comment:
       Done. Moved all constants to SmnProperties class




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565370884



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       I have removed reflections completely from component code. I see it used inside the unit test  for models. I guess will just remove the testing classes ClientConfigurations and ServiceKeys. It's an overkill I guess. Removing it and checking in the code. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024025



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;
+
+    TestConfiguration testConfiguration = new TestConfiguration();
+
+    WireMockServer wireMockServer;
+
+    @BindToRegistry("serviceKeys")
+    ServiceKeys serviceKeys
+            = new ServiceKeys(testConfiguration.getProperty("authKey"), testConfiguration.getProperty("secretKey"));
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        // populating tag values. user has to adjust the map entries according to the structure of their respective templates
+        Map<String, String> tags = new HashMap<>();
+        tags.put("name", "reji");
+        tags.put("phone", "1234567890");
+
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:publish_templated_message")
+                        .setProperty("CamelHwCloudSmnSubject", constant("This is my subjectline"))
+                        .setProperty("CamelHwCloudSmnTopic", constant(testConfiguration.getProperty("topic")))
+                        .setProperty("CamelHwCloudSmnMessageTtl", constant(60))
+                        .setProperty("CamelHwCloudSmnTemplateTags", constant(tags))
+                        .setProperty("CamelHwCloudSmnTemplateName", constant("hello-template"))
+                        //.to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"+"&projectId="+testConfiguration.getProperty("projectId")+"&region="+testConfiguration.getProperty("region")+"&proxyHost=localhost&proxyPort=3128&ignoreSslVerification=true")
+                        .to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"
+                            + "&projectId=" + testConfiguration.getProperty("projectId") + "&region="
+                            + testConfiguration.getProperty("region") + "&ignoreSslVerification=true")
+                        .log("templated notification sent")
+                        .to("mock:publish_templated_message_result");
+            }
+        };
+    }
+
+    private void setupSimpleNotificationsUtilsMock() {
+        try {
+            Mockito.mockStatic(SimpleNotificationUtils.class);

Review comment:
       This is completely removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
omarsmak commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565184340



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnProperties;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        validateAndInitializeSmnClient((SimpleNotificationEndpoint) super.getEndpoint());

Review comment:
       I would move the client initialization into either one of following overriden methods:
   
   - `doInit()` : In case your client is static, meaning that it does not create any threads upon initialization, aka lazy initialization. [Example](https://github.com/apache/camel/blob/master/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java#L152)
   - `doStart()`: In case your client will create for example thread pool upon initialization, this better to be placed here. [Example](https://github.com/apache/camel/blob/master/components/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsConsumer.java#L43)
   
   Also if the `SmnClient` is closable, please make sure to close in `doStop()`

##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/constants/SmnProperties.java
##########
@@ -0,0 +1,19 @@
+package org.apache.camel.component.huaweicloud.smn.constants;
+
+public class SmnProperties {
+
+    public SmnProperties() {
+    }
+
+    // request properties
+    public static String TEMPLATE_NAME = "CamelHwCloudSmnTemplateName";

Review comment:
       immutable `final` is missing from the constants




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565025146



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;

Review comment:
       Suggestion has been incorporated into the code. Main codebase has been re-visited to  make it  more testable with above suggestion




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] WillemJiang commented on pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
WillemJiang commented on pull request #4900:
URL: https://github.com/apache/camel/pull/4900#issuecomment-768380422


   @oscerd  Could you check the lasted code?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565025677



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationUtils.class.getName());
+
+    /**
+     * resolves endpoint url for the given region
+     * 
+     * @param  region
+     * @return
+     */
+    public static String resolveSmnServiceEndpoint(String region) {
+        if (region == null) {
+            return null;
+        }
+
+        String result = null;
+
+        try {
+            String formattedEndpointKey = formatEndpointKey(region);

Review comment:
       Usage of reflection has been removed completely




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565025341



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationProducer.java
##########
@@ -0,0 +1,366 @@
+/*
+ * 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.smn;
+
+import java.util.HashMap;
+
+import com.huaweicloud.sdk.core.auth.BasicCredentials;
+import com.huaweicloud.sdk.core.http.HttpConfig;
+import com.huaweicloud.sdk.smn.v2.SmnClient;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequest;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageRequestBody;
+import com.huaweicloud.sdk.smn.v2.model.PublishMessageResponse;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnConstants;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnOperations;
+import org.apache.camel.component.huaweicloud.smn.constants.SmnServices;
+import org.apache.camel.component.huaweicloud.smn.models.ClientConfigurations;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleNotificationProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleNotificationProducer.class);
+    private SimpleNotificationEndpoint simpleNotificationEndpoint;
+    private SmnClient smnClient;
+    private ClientConfigurations clientConfigurations;
+
+    public SimpleNotificationProducer(SimpleNotificationEndpoint endpoint) {
+        super(endpoint);
+        this.simpleNotificationEndpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        /**
+         * the produce method is invoked when a message arrives at producer endpoint (lazy init of SmnClient on first
+         * message)
+         */
+        if (this.smnClient == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Initializing the SmnClient");
+            }
+            validateAndInitializeSmnClient(simpleNotificationEndpoint);
+        }
+
+        String service = simpleNotificationEndpoint.getSmnService();
+
+        if (!ObjectHelper.isEmpty(service)) {
+            switch (service) {
+                case SmnServices.PUBLISH_MESSAGE:
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Using message publishing service");
+                    }
+                    performPublishMessageServiceOperations(simpleNotificationEndpoint, exchange);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Completed publishing message");
+                    }
+                    break;
+                default:
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Unsupported service name {}", service);
+                    }
+                    throw new UnsupportedOperationException(String.format("service %s is not a supported service", service));
+            }
+        } else {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Service name is null/empty");
+            }
+            throw new IllegalStateException("service name cannot be null/empty");

Review comment:
       It was just a personal choice. I have removed the lazy initialization to class init time 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565392653



##########
File path: components/camel-huaweicloud-smn/src/test/resources/log4j2.properties
##########
@@ -0,0 +1,7 @@
+

Review comment:
       Thanks for pointing. License headers added. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565023971



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;

Review comment:
       as suggested by @omarsmak , have removed external mocks and instead mocked the SmnClient class and stubbed the operation method




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024902



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/SimpleNotificationUtils.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.smn;
+
+import com.huaweicloud.sdk.core.region.Region;
+import com.huaweicloud.sdk.smn.v2.region.SmnRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * utility functions for the component
+ */
+public class SimpleNotificationUtils {

Review comment:
       Added private constructor




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565025883



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.smn.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+
+public class PublishTemplatedMessageTest extends CamelTestSupport {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PublishTemplatedMessageTest.class.getName());
+    private static int wiremockServerPort = 8080;
+
+    TestConfiguration testConfiguration = new TestConfiguration();
+
+    WireMockServer wireMockServer;
+
+    @BindToRegistry("serviceKeys")
+    ServiceKeys serviceKeys
+            = new ServiceKeys(testConfiguration.getProperty("authKey"), testConfiguration.getProperty("secretKey"));
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        // populating tag values. user has to adjust the map entries according to the structure of their respective templates
+        Map<String, String> tags = new HashMap<>();
+        tags.put("name", "reji");
+        tags.put("phone", "1234567890");
+
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:publish_templated_message")
+                        .setProperty("CamelHwCloudSmnSubject", constant("This is my subjectline"))
+                        .setProperty("CamelHwCloudSmnTopic", constant(testConfiguration.getProperty("topic")))
+                        .setProperty("CamelHwCloudSmnMessageTtl", constant(60))
+                        .setProperty("CamelHwCloudSmnTemplateTags", constant(tags))
+                        .setProperty("CamelHwCloudSmnTemplateName", constant("hello-template"))
+                        //.to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"+"&projectId="+testConfiguration.getProperty("projectId")+"&region="+testConfiguration.getProperty("region")+"&proxyHost=localhost&proxyPort=3128&ignoreSslVerification=true")
+                        .to("hwcloud-smn:publishMessageService?serviceKeys=#serviceKeys&operation=publishAsTemplatedMessage"
+                            + "&projectId=" + testConfiguration.getProperty("projectId") + "&region="
+                            + testConfiguration.getProperty("region") + "&ignoreSslVerification=true")
+                        .log("templated notification sent")
+                        .to("mock:publish_templated_message_result");
+            }
+        };
+    }
+
+    private void setupSimpleNotificationsUtilsMock() {
+        try {
+            Mockito.mockStatic(SimpleNotificationUtils.class);
+            Mockito.when(SimpleNotificationUtils.resolveSmnServiceEndpoint("unit-test"))
+                    .thenReturn("http://localhost:" + wiremockServerPort);
+        } catch (MockitoException e) {
+            LOGGER.info("Mock already registered. Using existing registration");
+        }
+    }
+
+    @Test
+    public void testTemplatedNotificationSend() throws Exception {
+        boolean isMockedServerTest = testConfiguration.getProperty("region").equals("unit-test");
+        if (isMockedServerTest) {
+            LOGGER.info("region is unit-test. Starting up wiremock stubs");
+            initWireMock();
+            setupSimpleNotificationsUtilsMock();
+        }
+
+        MockEndpoint mock = getMockEndpoint("mock:publish_templated_message_result");
+        mock.expectedMinimumMessageCount(1);
+        template.sendBody("direct:publish_templated_message", null);
+        Exchange responseExchange = mock.getExchanges().get(0);
+
+        mock.assertIsSatisfied();
+
+        Assert.assertNotNull(responseExchange.getProperty("CamelSmnMesssageId"));
+        Assert.assertNotNull(responseExchange.getProperty("CamelSmnRequestId"));
+        Assert.assertTrue(responseExchange.getProperty("CamelSmnMesssageId").toString().length() > 0);
+        Assert.assertTrue(responseExchange.getProperty("CamelSmnRequestId").toString().length() > 0);
+
+        if (isMockedServerTest) {
+            Assert.assertEquals("bf94b63a5dfb475994d3ac34664e24f2", responseExchange.getProperty("CamelSmnMesssageId"));
+            Assert.assertEquals("6a63a18b8bab40ffb71ebd9cb80d0085", responseExchange.getProperty("CamelSmnRequestId"));
+
+            LoggedRequest loggedRequest = TestUtils.retrieveTemplatedNotificationRequest(getAllServeEvents());
+            LOGGER.info("Verifying wiremock request");
+            Assert.assertEquals(
+                    "http://localhost:8080/v2/9071a38e7f6a4ba7b7bcbeb7d4ea6efc/notifications/topics/urn:smn:unit-test:9071a38e7f6a4ba7b7bcbeb7d4ea6efc:reji-test/publish",
+                    loggedRequest.getAbsoluteUrl());
+            Assert.assertEquals(
+                    "eyJzdWJqZWN0IjoiVGhpcyBpcyBteSBzdWJqZWN0bGluZSIsIm1lc3NhZ2VfdGVtcGxhdGVfbmFtZSI6ImhlbGxvLXRlbXBsYXRlIiwidGFncyI6eyJwaG9uZSI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoicmVqaSJ9LCJ0aW1lX3RvX2xpdmUiOiI2MCJ9",
+                    loggedRequest.getBodyAsBase64());
+            Assert.assertEquals(
+                    "{\"subject\":\"This is my subjectline\",\"message_template_name\":\"hello-template\",\"tags\":{\"phone\":\"1234567890\",\"name\":\"reji\"},\"time_to_live\":\"60\"}",
+                    loggedRequest.getBodyAsString());
+        }
+    }
+
+    private void initWireMock() throws Exception {
+        try {
+            wireMockServer = new WireMockServer(wiremockServerPort);
+            wireMockServer.start();
+        } catch (Exception e) {
+            LOGGER.info("wiremock server already registered in test context. using the same");

Review comment:
       removed usage of wiremock totally. instead using mock for SmnClient 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565023737



##########
File path: components/camel-huaweicloud-smn/src/test/java/org/apache/camel/component/huaweicloud/smn/PublishTemplatedMessageTest.java
##########
@@ -0,0 +1,129 @@
+package org.apache.camel.component.huaweicloud.smn;

Review comment:
       License header added on all test files




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565356201



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/constants/SmnProperties.java
##########
@@ -0,0 +1,19 @@
+package org.apache.camel.component.huaweicloud.smn.constants;
+
+public class SmnProperties {
+
+    public SmnProperties() {
+    }
+
+    // request properties
+    public static String TEMPLATE_NAME = "CamelHwCloudSmnTemplateName";

Review comment:
       good catch :) just checked in the fix. thanks 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4900:
URL: https://github.com/apache/camel/pull/4900#issuecomment-768391696


   LGTM, I think we should merge.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] mathewsreji commented on a change in pull request #4900: [CAMEL-16001] Camel component for HuaweiCloud Simple Notification Services (SMN) se…

Posted by GitBox <gi...@apache.org>.
mathewsreji commented on a change in pull request #4900:
URL: https://github.com/apache/camel/pull/4900#discussion_r565024787



##########
File path: components/camel-huaweicloud-smn/src/main/java/org/apache/camel/component/huaweicloud/smn/constants/SmnConstants.java
##########
@@ -0,0 +1,22 @@
+/*
+ * 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.smn.constants;
+
+public class SmnConstants {

Review comment:
       Added private constructor




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org