You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/07 20:54:20 UTC

[camel] 04/08: CAMEL-14263: camel-nagios should use source code generated configurer to avoid reflection configuration.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b86fd0dfdae5857a5920e66724f2f70e47c4d650
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 7 21:20:45 2019 +0100

    CAMEL-14263: camel-nagios should use source code generated configurer to avoid reflection configuration.
---
 .../src/main/docs/nagios-component.adoc            |  3 +-
 .../camel/component/nagios/NagiosComponent.java    |  1 -
 .../component/nagios/NagiosConfiguration.java      | 22 ----------
 .../component/nagios/NagiosEncryptionMethod.java   | 28 ------------
 .../camel/component/nagios/NagiosEndpoint.java     | 18 +++++---
 .../component/nagios/NagiosAsyncSendTest.java      | 51 ----------------------
 .../apache/camel/component/nagios/NagiosTest.java  | 14 ++----
 .../component/nagios/NagiosXorEncryptionTest.java  | 13 ++----
 .../endpoint/dsl/NagiosEndpointBuilderFactory.java | 40 -----------------
 .../springboot/NagiosComponentConfiguration.java   | 18 --------
 10 files changed, 19 insertions(+), 189 deletions(-)

diff --git a/components/camel-nagios/src/main/docs/nagios-component.adoc b/components/camel-nagios/src/main/docs/nagios-component.adoc
index 3b4d84f..89bc709 100644
--- a/components/camel-nagios/src/main/docs/nagios-component.adoc
+++ b/components/camel-nagios/src/main/docs/nagios-component.adoc
@@ -83,7 +83,7 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (9 parameters):
+=== Query Parameters (8 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -96,7 +96,6 @@ with the following path and query parameters:
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 | *encryption* (security) | To specify an encryption method. |  | Encryption
-| *encryptionMethod* (security) | *Deprecated* To specify an encryption method. |  | NagiosEncryptionMethod
 | *password* (security) | Password to be authenticated when sending checks to Nagios. |  | String
 |===
 // endpoint options: END
diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosComponent.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosComponent.java
index ea31810..925e736 100644
--- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosComponent.java
+++ b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosComponent.java
@@ -43,7 +43,6 @@ public class NagiosComponent extends DefaultComponent {
         ObjectHelper.notNull(configuration, "configuration");
         NagiosConfiguration config = configuration.copy();
         config.configure(url);
-        setProperties(config, parameters);
 
         NagiosEndpoint endpoint = new NagiosEndpoint(uri, this);
         endpoint.setConfiguration(config);
diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
index 0379619..5277eb1 100644
--- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
+++ b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
@@ -42,9 +42,6 @@ public class NagiosConfiguration implements Cloneable {
     private int timeout = 5000;
     @UriParam(label = "security", secret = true)
     private String password;
-    @Deprecated
-    @UriParam(label = "security")
-    private NagiosEncryptionMethod encryptionMethod;
     @UriParam(label = "security")
     private Encryption encryption = Encryption.NONE;
 
@@ -152,19 +149,6 @@ public class NagiosConfiguration implements Cloneable {
         this.password = password;
     }
 
-    public NagiosEncryptionMethod getEncryptionMethod() {
-        return encryptionMethod;
-    }
-
-    /**
-     * To specify an encryption method.
-     * @deprecated use the {@link #encryption} query parameter instead.
-     */
-    @Deprecated
-    public void setEncryptionMethod(NagiosEncryptionMethod encryptionMethod) {
-        this.encryptionMethod = encryptionMethod;
-    }
-
     public Encryption getEncryption() {
         return encryption;
     }
@@ -176,10 +160,4 @@ public class NagiosConfiguration implements Cloneable {
         this.encryption = encryption;
     }
 
-    @Override
-    public String toString() {
-        return "NagiosConfiguration[host=" + host + ":" + port + ", connectionTimeout=" + connectionTimeout
-                + ", timeout=" + timeout + ", encryptionMethod=" + encryptionMethod + ", encryption=" + encryption + "]";
-    }
-
 }
diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEncryptionMethod.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEncryptionMethod.java
deleted file mode 100644
index 3cebeb2..0000000
--- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEncryptionMethod.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.nagios;
-
-/**
- * Encryption methods supported by nagios.
- * @deprecated use {@link com.googlecode.jsendnsca.encryption.Encryption} instead.
- */
-@Deprecated
-public enum NagiosEncryptionMethod {
-
-    No, Xor, TripleDes
-
-}
diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java
index 3988a74..62e4fd2 100644
--- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java
+++ b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java
@@ -78,7 +78,18 @@ public class NagiosEndpoint extends DefaultEndpoint {
         this.sendSync = sendSync;
     }
 
-    public synchronized PassiveCheckSender getSender() {
+    public PassiveCheckSender getSender() {
+        return sender;
+    }
+
+    public void setSender(PassiveCheckSender sender) {
+        this.sender = sender;
+    }
+
+    @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+
         if (sender == null) {
             if (isSendSync()) {
                 sender = new NagiosPassiveCheckSender(getConfiguration().getNagiosSettings());
@@ -87,10 +98,5 @@ public class NagiosEndpoint extends DefaultEndpoint {
                 sender = new NonBlockingNagiosPassiveCheckSender(getConfiguration().getNagiosSettings());
             }
         }
-        return sender;
-    }
-
-    public void setSender(PassiveCheckSender sender) {
-        this.sender = sender;
     }
 }
diff --git a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosAsyncSendTest.java b/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosAsyncSendTest.java
deleted file mode 100644
index 94cc948..0000000
--- a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosAsyncSendTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.nagios;
-
-import com.googlecode.jsendnsca.NonBlockingNagiosPassiveCheckSender;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.BeforeClass;
-import org.mockito.Mockito;
-
-public class NagiosAsyncSendTest extends NagiosTest {
-
-    @BeforeClass
-    public static void setSender() {
-        nagiosPassiveCheckSender =  Mockito.mock(NonBlockingNagiosPassiveCheckSender.class);
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                String uri = "nagios:127.0.0.1:25664?password=secret&sendSync=false";
-
-                NagiosComponent nagiosComponent = new NagiosComponent();
-                nagiosComponent.setCamelContext(context);
-                NagiosEndpoint nagiosEndpoint = (NagiosEndpoint) nagiosComponent.createEndpoint(uri);
-                nagiosEndpoint.setSender(nagiosPassiveCheckSender);
-                nagiosEndpoint.createProducer();
-
-                from("direct:start")
-                        .to(nagiosEndpoint)
-                        .to("mock:result");
-            }
-        };
-    }
-
-}
diff --git a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosTest.java b/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosTest.java
index 749b486..c7302bd 100644
--- a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosTest.java
+++ b/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosTest.java
@@ -23,6 +23,7 @@ import com.googlecode.jsendnsca.Level;
 import com.googlecode.jsendnsca.MessagePayload;
 import com.googlecode.jsendnsca.NagiosPassiveCheckSender;
 import com.googlecode.jsendnsca.PassiveCheckSender;
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 public class NagiosTest extends CamelTestSupport {
-    @Mock
+    @Mock @BindToRegistry("mySender")
     protected static PassiveCheckSender nagiosPassiveCheckSender;
 
     protected boolean canRun;
@@ -53,7 +54,6 @@ public class NagiosTest extends CamelTestSupport {
         super.setUp();
     }
 
-
     @Test
     public void testSendToNagios() throws Exception {
         if (!canRun) {
@@ -159,16 +159,8 @@ public class NagiosTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                String uri = "nagios:127.0.0.1:25664?password=secret";
-
-                NagiosComponent nagiosComponent = new NagiosComponent();
-                nagiosComponent.setCamelContext(context);
-                NagiosEndpoint nagiosEndpoint = (NagiosEndpoint) nagiosComponent.createEndpoint(uri);
-                nagiosEndpoint.setSender(nagiosPassiveCheckSender);
-                nagiosEndpoint.createProducer();
-
                 from("direct:start")
-                        .to(nagiosEndpoint)
+                        .to("nagios:127.0.0.1:25664?password=secret&sender=#mySender")
                         .to("mock:result");
             }
         };
diff --git a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosXorEncryptionTest.java b/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosXorEncryptionTest.java
index eb354d3..114549d 100644
--- a/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosXorEncryptionTest.java
+++ b/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosXorEncryptionTest.java
@@ -20,6 +20,7 @@ import com.googlecode.jsendnsca.Level;
 import com.googlecode.jsendnsca.MessagePayload;
 import com.googlecode.jsendnsca.NagiosPassiveCheckSender;
 import com.googlecode.jsendnsca.PassiveCheckSender;
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -34,7 +35,7 @@ import static org.mockito.Mockito.verify;
 public class NagiosXorEncryptionTest extends CamelTestSupport {
     protected boolean canRun;
 
-    @Mock
+    @Mock @BindToRegistry("mySender")
     private PassiveCheckSender nagiosPassiveCheckSender = Mockito.mock(NagiosPassiveCheckSender.class);
 
     @Before
@@ -67,16 +68,8 @@ public class NagiosXorEncryptionTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                String uri = "nagios:127.0.0.1:25664?password=secret&encryption=Xor";
-
-                NagiosComponent nagiosComponent = new NagiosComponent();
-                nagiosComponent.setCamelContext(context);
-                NagiosEndpoint nagiosEndpoint = (NagiosEndpoint) nagiosComponent.createEndpoint(uri);
-                nagiosEndpoint.setSender(nagiosPassiveCheckSender);
-                nagiosEndpoint.createProducer();
-
                 from("direct:start")
-                        .to(nagiosEndpoint)
+                        .to("nagios:127.0.0.1:25664?password=secret&encryption=Xor&sender=#mySender")
                         .to("mock:result");
             }
         };
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/NagiosEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/NagiosEndpointBuilderFactory.java
index 3ff61d4..3122591 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/NagiosEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/NagiosEndpointBuilderFactory.java
@@ -171,35 +171,6 @@ public interface NagiosEndpointBuilderFactory {
             return this;
         }
         /**
-         * To specify an encryption method.
-         * 
-         * The option is a:
-         * <code>org.apache.camel.component.nagios.NagiosEncryptionMethod</code>
-         * type.
-         * 
-         * Group: security
-         */
-        @Deprecated
-        default NagiosEndpointBuilder encryptionMethod(
-                NagiosEncryptionMethod encryptionMethod) {
-            doSetProperty("encryptionMethod", encryptionMethod);
-            return this;
-        }
-        /**
-         * To specify an encryption method.
-         * 
-         * The option will be converted to a
-         * <code>org.apache.camel.component.nagios.NagiosEncryptionMethod</code>
-         * type.
-         * 
-         * Group: security
-         */
-        @Deprecated
-        default NagiosEndpointBuilder encryptionMethod(String encryptionMethod) {
-            doSetProperty("encryptionMethod", encryptionMethod);
-            return this;
-        }
-        /**
          * Password to be authenticated when sending checks to Nagios.
          * 
          * The option is a: <code>java.lang.String</code> type.
@@ -286,17 +257,6 @@ public interface NagiosEndpointBuilderFactory {
         RIJNDAEL256,
         BLOWFISH;
     }
-
-    /**
-     * Proxy enum for
-     * <code>org.apache.camel.component.nagios.NagiosEncryptionMethod</code>
-     * enum.
-     */
-    enum NagiosEncryptionMethod {
-        No,
-        Xor,
-        TripleDes;
-    }
     /**
      * Nagios (camel-nagios)
      * To send passive checks to Nagios using JSendNSCA.
diff --git a/platforms/spring-boot/components-starter/camel-nagios-starter/src/main/java/org/apache/camel/component/nagios/springboot/NagiosComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-nagios-starter/src/main/java/org/apache/camel/component/nagios/springboot/NagiosComponentConfiguration.java
index 23489a6..333ec7a 100644
--- a/platforms/spring-boot/components-starter/camel-nagios-starter/src/main/java/org/apache/camel/component/nagios/springboot/NagiosComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-nagios-starter/src/main/java/org/apache/camel/component/nagios/springboot/NagiosComponentConfiguration.java
@@ -19,10 +19,8 @@ package org.apache.camel.component.nagios.springboot;
 import javax.annotation.Generated;
 import com.googlecode.jsendnsca.NagiosSettings;
 import com.googlecode.jsendnsca.encryption.Encryption;
-import org.apache.camel.component.nagios.NagiosEncryptionMethod;
 import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
 import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
 
 /**
  * To send passive checks to Nagios using JSendNSCA.
@@ -132,11 +130,6 @@ public class NagiosComponentConfiguration
         /**
          * To specify an encryption method.
          */
-        @Deprecated
-        private NagiosEncryptionMethod encryptionMethod;
-        /**
-         * To specify an encryption method.
-         */
         private Encryption encryption;
 
         public NagiosSettings getNagiosSettings() {
@@ -187,17 +180,6 @@ public class NagiosComponentConfiguration
             this.password = password;
         }
 
-        @Deprecated
-        @DeprecatedConfigurationProperty
-        public NagiosEncryptionMethod getEncryptionMethod() {
-            return encryptionMethod;
-        }
-
-        @Deprecated
-        public void setEncryptionMethod(NagiosEncryptionMethod encryptionMethod) {
-            this.encryptionMethod = encryptionMethod;
-        }
-
         public Encryption getEncryption() {
             return encryption;
         }