camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/5] git commit: CAMEL-6729: camel-jt400 filter unsupported scheduled poll consumer options when creating a PollingConsumer as it does not support these options, due special in jt400 component.
Date Mon, 16 Sep 2013 10:42:41 GMT
Updated Branches:
  refs/heads/camel-2.11.x aebe52774 -> 0acff1b0a
  refs/heads/camel-2.12.x 4db3d9e12 -> a971b79da
  refs/heads/master 89c61cacc -> 302133ed3


CAMEL-6729: camel-jt400 filter unsupported scheduled poll consumer options when creating a
PollingConsumer as it does not support these options, due special in jt400 component.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0dbb9ea2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0dbb9ea2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0dbb9ea2

Branch: refs/heads/master
Commit: 0dbb9ea266f640c3859703f90fe5b5b98e27e579
Parents: 89c61ca
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 16 12:40:53 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 16 12:40:53 2013 +0200

----------------------------------------------------------------------
 .../camel/impl/ScheduledPollEndpoint.java       |  2 +-
 .../component/jt400/Jt400DataQueueEndpoint.java | 24 ++++++-
 .../jt400/Jt400CustomPollStrategyTest.java      | 71 ++++++++++++++++++++
 3 files changed, 95 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0dbb9ea2/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java b/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
index 9106ef3..cc63ddc 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
@@ -55,7 +55,7 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint {
         configureScheduledPollConsumerProperties(options, getConsumerProperties());
     }
 
-    private void configureScheduledPollConsumerProperties(Map<String, Object> options,
Map<String, Object> consumerProperties) {
+    protected void configureScheduledPollConsumerProperties(Map<String, Object> options,
Map<String, Object> consumerProperties) {
         // special for scheduled poll consumers as we want to allow end users to configure
its options
         // from the URI parameters without the consumer. prefix
         Map<String, Object> schedulerProperties = IntrospectionSupport.extractProperties(options,
"scheduler.");

http://git-wip-us.apache.org/repos/asf/camel/blob/0dbb9ea2/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
index 3692864..b9b5797 100644
--- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
+++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.jt400;
 
 import java.beans.PropertyVetoException;
 import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
 
 import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.AS400ConnectionPool;
@@ -27,7 +29,9 @@ import com.ibm.as400.access.KeyedDataQueue;
 import org.apache.camel.CamelException;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Producer;
+import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.impl.DefaultPollingEndpoint;
+import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
 
@@ -143,7 +147,25 @@ public class Jt400DataQueueEndpoint extends DefaultPollingEndpoint {
     @Override
     public PollingConsumer createPollingConsumer() throws Exception {
         Jt400DataQueueConsumer answer = new Jt400DataQueueConsumer(this);
-        configureConsumer(answer);
+
+        Map<String, Object> copy = new HashMap<String, Object>(getConsumerProperties());
+        Map<String, Object> throwaway = new HashMap<String, Object>();
+
+        // filter out unwanted options which is intended for the scheduled poll consumer
+        // as these options are not supported on Jt400DataQueueConsumer
+        configureScheduledPollConsumerProperties(copy, throwaway);
+
+        // set reference properties first as they use # syntax that fools the regular properties
setter
+        EndpointHelper.setReferenceProperties(getCamelContext(), this, copy);
+        EndpointHelper.setProperties(getCamelContext(), this, copy);
+
+        if (!isLenientProperties() && copy.size() > 0) {
+            throw new ResolveEndpointFailedException(this.getEndpointUri(), "There are "
+ copy.size()
+                    + " parameters that couldn't be set on the endpoint consumer."
+                    + " Check the uri if the parameters are spelt correctly and that they
are properties of the endpoint."
+                    + " Unknown consumer parameters=[" + copy + "]");
+        }
+
         return answer;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0dbb9ea2/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java
b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java
new file mode 100644
index 0000000..de1ff19
--- /dev/null
+++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.jt400;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.spi.PollingConsumerPollStrategy;
+import org.junit.Test;
+
+public class Jt400CustomPollStrategyTest extends Jt400TestSupport {
+
+    private static final String PASSWORD = "p4ssw0rd";
+    private PollingConsumerPollStrategy poll = new MyPollStrategy();
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("jt400PollStrategy", poll);
+        return jndi;
+    }
+
+    @Test
+    public void testCustomPollStrategy() throws Exception {
+        Jt400DataQueueEndpoint endpoint = resolveMandatoryEndpoint(
+                "jt400://user:" + PASSWORD + "@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool&pollStrategy=#jt400PollStrategy",
+                Jt400DataQueueEndpoint.class);
+        assertNotNull(endpoint);
+
+        PollingConsumer consumer = endpoint.createPollingConsumer();
+        assertNotNull(consumer);
+    }
+
+    private static final class MyPollStrategy implements PollingConsumerPollStrategy {
+
+        @Override
+        public boolean begin(Consumer consumer, Endpoint endpoint) {
+            return true;
+        }
+
+        @Override
+        public void commit(Consumer consumer, Endpoint endpoint, int i) {
+            // noop
+        }
+
+        @Override
+        public boolean rollback(Consumer consumer, Endpoint endpoint, int i, Exception e)
throws Exception {
+            return false;
+        }
+    }
+}


Mime
View raw message