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/8ad3d365 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8ad3d365 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8ad3d365 Branch: refs/heads/camel-2.12.x Commit: 8ad3d365652597deefd50cf7e5862de40aa0ecbc Parents: 4db3d9e Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Sep 16 12:40:53 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Sep 16 12:42:00 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/8ad3d365/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/8ad3d365/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/8ad3d365/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; + } + } +}