Repository: camel Updated Branches: refs/heads/master 45225d226 -> cc4e7785f
Fix for CAMEL-7499, Expose the component options for Camel Mail Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cc4e7785 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cc4e7785 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cc4e7785 Branch: refs/heads/master Commit: cc4e7785f82e2e9cd524c2b155a56f6722bee2d0 Parents: 45225d2 Author: Kevin Earls <ke...@kevinearls.com> Authored: Wed Jun 11 17:07:21 2014 +0200 Committer: Kevin Earls <ke...@kevinearls.com> Committed: Wed Jun 11 17:07:21 2014 +0200 ---------------------------------------------------------------------- .../camel/component/mail/MailComponent.java | 8 ++- .../camel/component/mail/MailConfiguration.java | 28 ++++++++++ .../camel/component/mail/MailEndpoint.java | 5 ++ ...ponentConfigurationAndDocumentationTest.java | 58 ++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/cc4e7785/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 7236760..ace627e 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 @@ -25,7 +25,7 @@ import javax.mail.search.SearchTerm; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.util.IntrospectionSupport; import org.apache.camel.util.ObjectHelper; @@ -34,20 +34,22 @@ import org.apache.camel.util.ObjectHelper; * * @version */ -public class MailComponent extends DefaultComponent { +public class MailComponent extends UriEndpointComponent { private MailConfiguration configuration; private ContentTypeResolver contentTypeResolver; public MailComponent() { + super(MailEndpoint.class); this.configuration = new MailConfiguration(); } public MailComponent(MailConfiguration configuration) { + super(MailEndpoint.class); this.configuration = configuration; } public MailComponent(CamelContext context) { - super(context); + super(context, MailEndpoint.class); this.configuration = new MailConfiguration(); } http://git-wip-us.apache.org/repos/asf/camel/blob/cc4e7785/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java index 29c5cca..084a153 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java @@ -25,6 +25,8 @@ import javax.mail.Session; import javax.net.ssl.SSLContext; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; import org.apache.camel.util.jsse.SSLContextParameters; /** @@ -32,37 +34,63 @@ import org.apache.camel.util.jsse.SSLContextParameters; * * @version */ +@UriParams public class MailConfiguration implements Cloneable { private JavaMailSender javaMailSender; private Properties javaMailProperties; private Properties additionalJavaMailProperties; + @UriParam private String protocol; + @UriParam private String host; + @UriParam private int port = -1; + @UriParam private String username; + @UriParam private String password; + @UriParam private String subject; private Session session; + @UriParam private boolean mapMailMessage = true; + @UriParam private String from = MailConstants.MAIL_DEFAULT_FROM; + @UriParam private String folderName = MailConstants.MAIL_DEFAULT_FOLDER; + @UriParam private boolean delete; + @UriParam private String copyTo; + @UriParam private boolean unseen = true; + @UriParam private boolean ignoreUriScheme; private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType, String>(); + @UriParam private String replyTo; + @UriParam private int fetchSize = -1; + @UriParam private boolean debugMode; + @UriParam private int connectionTimeout = MailConstants.MAIL_DEFAULT_CONNECTION_TIMEOUT; + @UriParam private boolean dummyTrustManager; + @UriParam private String contentType = "text/plain"; + @UriParam private String alternativeBodyHeader = MailConstants.MAIL_ALTERNATIVE_BODY; + @UriParam private boolean useInlineAttachments; + @UriParam private boolean ignoreUnsupportedCharset; + @UriParam private boolean disconnect; + @UriParam private boolean closeFolder = true; + @UriParam private boolean peek = true; private SSLContextParameters sslContextParameters; http://git-wip-us.apache.org/repos/asf/camel/blob/cc4e7785/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java index b4bd387..e1345ac 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java @@ -28,17 +28,22 @@ import org.apache.camel.impl.DefaultExchange; import org.apache.camel.impl.DefaultHeaderFilterStrategy; import org.apache.camel.impl.ScheduledPollEndpoint; import org.apache.camel.spi.HeaderFilterStrategy; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; /** * Endpoint for Camel Mail. * * @version */ +@UriEndpoint(scheme = "mail", consumerClass = MailConsumer.class) public class MailEndpoint extends ScheduledPollEndpoint { private MailBinding binding; + @UriParam private MailConfiguration configuration; private HeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy(); private ContentTypeResolver contentTypeResolver; + @UriParam private int maxMessagesPerPoll; private SearchTerm searchTerm; http://git-wip-us.apache.org/repos/asf/camel/blob/cc4e7785/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentConfigurationAndDocumentationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentConfigurationAndDocumentationTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentConfigurationAndDocumentationTest.java new file mode 100644 index 0000000..827dece --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentConfigurationAndDocumentationTest.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.component.mail; + +import org.apache.camel.CamelContext; +import org.apache.camel.ComponentConfiguration; +import org.apache.camel.EndpointConfiguration; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +import java.util.List; + +public class MailComponentConfigurationAndDocumentationTest extends CamelTestSupport { + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testComponentConfiguration() throws Exception { + MailComponent comp = context.getComponent("smtp", MailComponent.class); + EndpointConfiguration conf = comp.createConfiguration("smtp://james@myhost?password=secret&connectionTimeout=2500"); + + assertEquals("secret", conf.getParameter("password")); + assertEquals("2500", conf.getParameter("connectionTimeout")); + + ComponentConfiguration compConf = comp.createComponentConfiguration(); + String json = compConf.createParameterJsonSchema(); + assertNotNull(json); + + assertTrue(json.contains("\"contentType\": { \"type\": \"java.lang.String\" }")); + assertTrue(json.contains("\"debugMode\": { \"type\": \"boolean\" }")); + } + + @Test + public void testComponentDocumentation() throws Exception { + CamelContext context = new DefaultCamelContext(); + String html = context.getComponentDocumentation("mail"); + assertNotNull("Should have found some auto-generated HTML if on Java 7", html); + } + +}