You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2018/01/30 08:41:24 UTC

[camel] branch master updated (3c99cfd -> 8a735b1)

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

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


    from 3c99cfd  Camel-AWS - Improved test for all the component verifiers
     new 60b5861  CAMEL-12198: Make camel-pgevent work in modular class loading environments
     new 8a735b1  CAMEL-12198: Remove PGDataSource type check as some container implementations may wrap it using a different class

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/pgevent/PgEventEndpoint.java   | 30 ++++++++--------------
 .../karaf/features/src/main/resources/features.xml |  1 +
 .../{CamelCoreTest.java => CamelPgEventTest.java}  | 16 ++++++------
 .../org/apache/camel/itest/CamelPgEventTest.xml    | 25 ++++++++----------
 4 files changed, 29 insertions(+), 43 deletions(-)
 copy tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/{CamelCoreTest.java => CamelPgEventTest.java} (81%)
 copy components/camel-hystrix/src/test/resources/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.xml => tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelPgEventTest.xml (78%)

-- 
To stop receiving notification emails like this one, please contact
jamesnetherton@apache.org.

[camel] 01/02: CAMEL-12198: Make camel-pgevent work in modular class loading environments

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 60b58612c1763fdbb3877a4a5cb8d3dd0b7e7c42
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Jan 30 07:53:50 2018 +0000

    CAMEL-12198: Make camel-pgevent work in modular class loading environments
---
 .../camel/component/pgevent/PgEventEndpoint.java   | 10 ++--
 .../karaf/features/src/main/resources/features.xml |  1 +
 .../org/apache/camel/itest/CamelPgEventTest.java   | 58 ++++++++++++++++++++++
 .../org/apache/camel/itest/CamelPgEventTest.xml    | 42 ++++++++++++++++
 4 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
index c0dc3e2..0d304ef 100644
--- a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
+++ b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
@@ -18,20 +18,21 @@ package org.apache.camel.component.pgevent;
 
 import java.io.InvalidClassException;
 import java.sql.DriverManager;
-import java.util.Properties;
 import javax.sql.DataSource;
 
 import com.impossibl.postgres.api.jdbc.PGConnection;
 import com.impossibl.postgres.jdbc.PGDataSource;
+import com.impossibl.postgres.jdbc.PGDriver;
+
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
-import org.apache.camel.util.URISupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -84,13 +85,12 @@ public class PgEventEndpoint extends DefaultEndpoint {
 
     public final PGConnection initJdbc() throws Exception {
         PGConnection conn;
-        Properties props = new Properties();
-        props.putAll(URISupport.parseQuery(uri));
         if (this.getDatasource() != null) {
             conn = (PGConnection) this.getDatasource().getConnection();
         } else {
             // ensure we can load the class
-            getCamelContext().getClassResolver().resolveMandatoryClass("com.impossibl.postgres.jdbc.PGDriver");
+            ClassResolver classResolver = getCamelContext().getClassResolver();
+            classResolver.resolveMandatoryClass(PGDriver.class.getName(), PgEventComponent.class.getClassLoader());
             conn = (PGConnection) DriverManager.getConnection("jdbc:pgsql://" + this.getHost() + ":" + this.getPort() + "/" + this.getDatabase(), this.getUser(), this.getPass());
         }
         return conn;
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 1a901fa..839e91b 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1723,6 +1723,7 @@
     <details>installing camel-pgevent may output an error in the log but it is installed correctly</details>
     <feature version='${project.version}'>camel-core</feature>
     <feature>transaction</feature>
+    <feature>jdbc</feature>
     <bundle dependency='true'>mvn:com.impossibl.pgjdbc-ng/pgjdbc-ng/${pgjdbc-ng-driver-version}</bundle>
     <bundle dependency='true'>mvn:io.netty/netty-common/${netty-version}</bundle>
     <bundle dependency='true'>mvn:io.netty/netty-transport/${netty-version}</bundle>
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelPgEventTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelPgEventTest.java
new file mode 100644
index 0000000..ad2674a
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelPgEventTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.itest;
+
+import java.net.URL;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.karaf.AbstractFeatureTest;
+import org.apache.camel.test.karaf.CamelKarafTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+@Ignore("Needs a running PostgreSQL instance")
+public class CamelPgEventTest extends AbstractFeatureTest {
+
+    @Test
+    public void testCamelPgEvent() throws Exception {
+        // install the camel blueprint xml file we use in this test
+        URL url = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelPgEventTest.xml", CamelPgEventTest.class.getClassLoader());
+        installBlueprintAsBundle("CamelPgEventTest", url, true);
+        installCamelFeature("camel-pgevent");
+
+        // lookup Camel from OSGi
+        CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
+
+        // test camel
+        MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
+        mock.expectedBodiesReceived("Hello World");
+
+        mock.assertIsSatisfied(5000);
+    }
+
+    @Configuration
+    public Option[] configure() {
+        return CamelKarafTestSupport.configure("camel-test-karaf");
+    }
+}
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelPgEventTest.xml b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelPgEventTest.xml
new file mode 100644
index 0000000..6f61acdd
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelPgEventTest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint">
+
+    <route>
+      <from uri="timer://test?repeatCount=1&amp;period=1"/>
+      <setBody>
+        <constant>Hello World</constant>
+      </setBody>
+      <to uri="pgevent://localhost:5432/postgres/testchannel?user=postgres&amp;pass=mysecretpassword"/>
+    </route>
+
+    <route>
+      <from uri="pgevent://localhost:5432/postgres/testchannel?user=postgres&amp;pass=mysecretpassword"/>
+      <to uri="mock:result"/>
+    </route>
+
+  </camelContext>
+
+</blueprint>

-- 
To stop receiving notification emails like this one, please contact
jamesnetherton@apache.org.

[camel] 02/02: CAMEL-12198: Remove PGDataSource type check as some container implementations may wrap it using a different class

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8a735b1616c90bee761fdda78dc2c4858d5e568f
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Jan 30 08:38:55 2018 +0000

    CAMEL-12198: Remove PGDataSource type check as some container implementations may wrap it using a different class
---
 .../camel/component/pgevent/PgEventEndpoint.java     | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
index 0d304ef..18c28a2 100644
--- a/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
+++ b/components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventEndpoint.java
@@ -16,12 +16,10 @@
  */
 package org.apache.camel.component.pgevent;
 
-import java.io.InvalidClassException;
 import java.sql.DriverManager;
 import javax.sql.DataSource;
 
 import com.impossibl.postgres.api.jdbc.PGConnection;
-import com.impossibl.postgres.jdbc.PGDataSource;
 import com.impossibl.postgres.jdbc.PGDriver;
 
 import org.apache.camel.Consumer;
@@ -140,22 +138,14 @@ public class PgEventEndpoint extends DefaultEndpoint {
         return new PgEventProducer(this);
     }
 
-    private void validateInputs() throws InvalidClassException, IllegalArgumentException {
+    private void validateInputs() throws IllegalArgumentException {
         if (getChannel() == null || getChannel().length() == 0) {
             throw new IllegalArgumentException("A required parameter was not set when creating this Endpoint (channel)");
         }
-        if (datasource != null) {
-            LOG.debug("******Datasource detected*****");
-            if (!PGDataSource.class.isInstance(datasource)) {
-                throw new InvalidClassException("The datasource passed to the "
-                        + "pgevent component is NOT a PGDataSource class from the"
-                        + "pgjdbc-ng library. See: https://github.com/impossibl/pgjdbc-ng");
-            }
-        } else {
-            if (user == null) {
-                throw new IllegalArgumentException("A required parameter was "
-                        + "not set when creating this Endpoint (pgUser or pgDataSource)");
-            }
+
+        if (datasource == null && user == null) {
+            throw new IllegalArgumentException("A required parameter was "
+                    + "not set when creating this Endpoint (pgUser or pgDataSource)");
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
jamesnetherton@apache.org.