CAMEL-10470: camel-mail - Should allow to configure SimpleSearchTerm as plain POJO
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/24176c52 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/24176c52 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/24176c52 Branch: refs/heads/camel-2.17.x Commit: 24176c52d59a08ad14990a4b16646bbbd8da60bc Parents: 20775ec Author: Claus Ibsen <[email protected]> Authored: Fri Nov 11 10:01:46 2016 +0100 Committer: Claus Ibsen <[email protected]> Committed: Fri Nov 11 10:02:30 2016 +0100 ---------------------------------------------------------------------- .../camel/component/mail/MailComponent.java | 16 +++++++- .../mail/MailSearchTermUriConfigBeanTest.java | 42 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/24176c52/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java index 081d364..0cd8ff9 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java @@ -20,7 +20,6 @@ import java.net.URI; import java.util.HashSet; import java.util.Map; import java.util.Set; - import javax.mail.search.SearchTerm; import org.apache.camel.CamelContext; @@ -63,10 +62,25 @@ public class MailComponent extends UriEndpointComponent { configureAdditionalJavaMailProperties(config, parameters); MailEndpoint endpoint = new MailEndpoint(uri, this, config); + + // special for search term bean reference + Object searchTerm = getAndRemoveOrResolveReferenceParameter(parameters, "searchTerm", Object.class); + if (searchTerm != null) { + SearchTerm st; + if (searchTerm instanceof SimpleSearchTerm) { + // okay its a SimpleSearchTerm then lets convert that to SearchTerm + st = MailConverters.toSearchTerm((SimpleSearchTerm) searchTerm, getCamelContext().getTypeConverter()); + } else { + st = getCamelContext().getTypeConverter().mandatoryConvertTo(SearchTerm.class, searchTerm); + } + endpoint.setSearchTerm(st); + } + endpoint.setContentTypeResolver(contentTypeResolver); setProperties(endpoint.getConfiguration(), parameters); setProperties(endpoint, parameters); + // special for searchTerm.xxx options Map<String, Object> sstParams = IntrospectionSupport.extractProperties(parameters, "searchTerm."); if (!sstParams.isEmpty()) { // use SimpleSearchTerm as POJO to store the configuration and then convert that to the actual SearchTerm http://git-wip-us.apache.org/repos/asf/camel/blob/24176c52/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java new file mode 100644 index 0000000..f0d8f12 --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java @@ -0,0 +1,42 @@ +/** + * 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.mail; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; + +public class MailSearchTermUriConfigBeanTest extends MailSearchTermUriConfigTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + SimpleSearchTerm mySearchTerm = new SimpleSearchTerm(); + mySearchTerm.setSubjectOrBody("Camel"); + + JndiRegistry jndi = super.createRegistry(); + jndi.bind("mySearchTerm", mySearchTerm); + return jndi; + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("pop3://bill@localhost?password=secret&searchTerm=#mySearchTerm").to("mock:result"); + } + }; + } + +}
