CAMEL-8038: Component endpoint options should provide @UriPath. Also components extending others should be separate classes as minimum
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c77199a5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c77199a5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c77199a5 Branch: refs/heads/master Commit: c77199a5b11235b6cd1a74226f5a0078743e249b Parents: b3f210f Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Nov 12 11:32:53 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Nov 12 12:07:26 2014 +0100 ---------------------------------------------------------------------- .../org/apache/camel/util/JsonSchemaHelper.java | 4 ++ .../atmosphere/websocket/WebsocketEndpoint.java | 24 ++++----- .../src/test/resources/log4j.properties | 2 +- .../camel/component/http/HttpComponent.java | 11 ++-- .../camel/component/http/HttpEndpoint.java | 16 ++++-- .../camel/component/http/HttpsComponent.java | 39 ++++++++++++++ .../camel/component/http/HttpsEndpoint.java | 57 ++++++++++++++++++++ .../services/org/apache/camel/component/https | 2 +- .../component/servlet/ServletEndpoint.java | 3 ++ .../tools/apt/EndpointAnnotationProcessor.java | 5 +- .../camel/tools/apt/JsonSchemaHelper.java | 4 ++ 11 files changed, 141 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java index e580ec7..76f27be 100644 --- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java @@ -16,6 +16,8 @@ */ package org.apache.camel.util; +import java.net.URI; +import java.net.URL; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -44,6 +46,8 @@ public final class JsonSchemaHelper { return "enum"; } else if (type.isArray()) { return "array"; + } if (type.isAssignableFrom(URI.class) || type.isAssignableFrom(URL.class)) { + return "sting"; } String primitive = getPrimitiveType(type); http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java index 5183019..7d16e31 100644 --- a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java +++ b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java @@ -26,6 +26,7 @@ import org.apache.camel.component.http.HttpClientConfigurer; import org.apache.camel.component.servlet.ServletEndpoint; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.httpclient.params.HttpClientParams; @@ -34,10 +35,13 @@ import org.apache.commons.httpclient.params.HttpClientParams; */ @UriEndpoint(scheme = "atmosphere-websocket", consumerClass = WebsocketConsumer.class) public class WebsocketEndpoint extends ServletEndpoint { + + @UriPath + private String servicePath; private WebSocketStore store; - @UriParam + @UriParam(defaultValue = "false") private boolean sendToAll; - @UriParam + @UriParam(defaultValue = "false") private boolean useStreaming; public WebsocketEndpoint(String endPointURI, WebsocketComponent component, URI httpUri, HttpClientParams params, HttpConnectionManager httpConnectionManager, @@ -47,35 +51,26 @@ public class WebsocketEndpoint extends ServletEndpoint { //TODO find a better way of assigning the store int idx = endPointURI.indexOf('?'); String name = idx > -1 ? endPointURI.substring(0, idx) : endPointURI; - this.store = component.getWebSocketStore(name); + + this.servicePath = name; + this.store = component.getWebSocketStore(servicePath); } - - /* (non-Javadoc) - * @see org.apache.camel.Endpoint#createProducer() - */ @Override public Producer createProducer() throws Exception { return new WebsocketProducer(this); } - /* (non-Javadoc) - * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor) - */ @Override public Consumer createConsumer(Processor processor) throws Exception { return new WebsocketConsumer(this, processor); } - /* (non-Javadoc) - * @see org.apache.camel.IsSingleton#isSingleton() - */ @Override public boolean isSingleton() { return true; } - /** * @return the sendToAll */ @@ -104,7 +99,6 @@ public class WebsocketEndpoint extends ServletEndpoint { this.useStreaming = useStreaming; } - WebSocketStore getWebSocketStore() { return store; } http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-atmosphere-websocket/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-atmosphere-websocket/src/test/resources/log4j.properties b/components/camel-atmosphere-websocket/src/test/resources/log4j.properties index 0c38599..bb1dc33 100644 --- a/components/camel-atmosphere-websocket/src/test/resources/log4j.properties +++ b/components/camel-atmosphere-websocket/src/test/resources/log4j.properties @@ -36,4 +36,4 @@ log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m% log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n -log4j.appender.file.file=target/camel-websocket2-test.log +log4j.appender.file.file=target/camel-atmosphere-websocket-test.log http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java index 717c505..9256c9b 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java @@ -17,6 +17,7 @@ package org.apache.camel.component.http; import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -37,8 +38,7 @@ import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; /** - * Defines the <a href="http://camel.apache.org/http.html">HTTP - * Component</a> + * The <a href="http://camel.apache.org/http.html">HTTP Component</a> * * @version */ @@ -248,7 +248,7 @@ public class HttpComponent extends HeaderFilterStrategyComponent { URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), httpClientParameters); // create the endpoint and connectionManagerParams already be set - HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer); + HttpEndpoint endpoint = createHttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer); if (headerFilterStrategy != null) { endpoint.setHeaderFilterStrategy(headerFilterStrategy); @@ -305,6 +305,11 @@ public class HttpComponent extends HeaderFilterStrategyComponent { endpoint.setHttpUri(httpUri); return endpoint; } + + protected HttpEndpoint createHttpEndpoint(String uri, HttpComponent component, HttpClientParams clientParams, + HttpConnectionManager connectionManager, HttpClientConfigurer configurer) throws URISyntaxException { + return new HttpEndpoint(uri, component, clientParams, connectionManager, configurer); + } @Override protected boolean useIntrospectionOnEndpoint() { http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java index 4fcef55..5971cbc 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java @@ -29,6 +29,7 @@ import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.HeaderFilterStrategyAware; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; import org.apache.camel.util.ObjectHelper; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnectionManager; @@ -49,18 +50,20 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy(); private HttpBinding binding; private HttpComponent component; + @UriPath private URI httpUri; private HttpClientParams clientParams; private HttpClientConfigurer httpClientConfigurer; private HttpConnectionManager httpConnectionManager; + @UriParam(defaultValue = "true") private boolean throwExceptionOnFailure = true; - @UriParam + @UriParam(defaultValue = "false") private boolean bridgeEndpoint; - @UriParam + @UriParam(defaultValue = "false") private boolean matchOnUriPrefix; - @UriParam + @UriParam(defaultValue = "true") private boolean chunked = true; - @UriParam + @UriParam(defaultValue = "false") private boolean disableStreamCache; @UriParam private String proxyHost; @@ -70,7 +73,7 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter private String authMethodPriority; @UriParam private boolean transferException; - @UriParam + @UriParam(defaultValue = "false") private boolean traceEnabled; @UriParam private String httpMethodRestrict; @@ -249,6 +252,9 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter return httpUri; } + /** + * The url of the HTTP endpoint to call. + */ public void setHttpUri(URI httpUri) { this.httpUri = httpUri; } http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsComponent.java new file mode 100644 index 0000000..3e83e52 --- /dev/null +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsComponent.java @@ -0,0 +1,39 @@ +/** + * 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.http; + +import java.net.URISyntaxException; + +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.params.HttpClientParams; + +/** + * The <a href="http://camel.apache.org/http.html">HTTPS Component</a> + */ +public class HttpsComponent extends HttpComponent { + + public HttpsComponent() { + super(HttpsEndpoint.class); + } + + @Override + protected HttpEndpoint createHttpEndpoint(String uri, HttpComponent component, HttpClientParams clientParams, + HttpConnectionManager connectionManager, HttpClientConfigurer configurer) throws URISyntaxException { + return new HttpsEndpoint(uri, component, clientParams, connectionManager, configurer); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsEndpoint.java new file mode 100644 index 0000000..2ebb3a5 --- /dev/null +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpsEndpoint.java @@ -0,0 +1,57 @@ +/** + * 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.http; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.camel.spi.UriEndpoint; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.params.HttpClientParams; + +@UriEndpoint(scheme = "https", consumerClass = HttpConsumer.class) +public class HttpsEndpoint extends HttpEndpoint { + + public HttpsEndpoint() { + } + + public HttpsEndpoint(String endPointURI, HttpComponent component, URI httpURI) throws URISyntaxException { + super(endPointURI, component, httpURI); + } + + public HttpsEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpConnectionManager httpConnectionManager) throws URISyntaxException { + super(endPointURI, component, httpURI, httpConnectionManager); + } + + public HttpsEndpoint(String uri, HttpComponent component, HttpClientParams clientParams, + HttpConnectionManager connectionManager, HttpClientConfigurer configurer) throws URISyntaxException { + super(uri, component, clientParams, connectionManager, configurer); + } + + public HttpsEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams, + HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException { + super(endPointURI, component, httpURI, clientParams, httpConnectionManager, clientConfigurer); + } + + /** + * The url of the HTTPS endpoint to call. + */ + @Override + public void setHttpUri(URI httpUri) { + super.setHttpUri(httpUri); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https b/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https index 4efb7cf..af1bb0c 100644 --- a/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https +++ b/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https @@ -15,4 +15,4 @@ # limitations under the License. # -class=org.apache.camel.component.http.HttpComponent +class=org.apache.camel.component.http.HttpsComponent http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java index 84af20d..abb50e2 100644 --- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java +++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java @@ -43,6 +43,9 @@ public class ServletEndpoint extends HttpEndpoint { super(endPointURI, component, httpUri, params, httpConnectionManager, clientConfigurer); } + /** + * Name of the servlet to use + */ public void setServletName(String name) { servletName = name; } http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java ---------------------------------------------------------------------- diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java index 908905d..b14722c 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java @@ -203,7 +203,10 @@ public class EndpointAnnotationProcessor extends AbstractProcessor { buffer.append(","); } buffer.append("\n "); - buffer.append(JsonSchemaHelper.toJson(entry.getName(), entry.getType(), entry.getDefaultValue(), entry.getDocumentationWithNotes(), entry.isEnumType(), entry.getEnums())); + // as its json we need to sanitize the docs + String doc = entry.getDocumentationWithNotes(); + doc = sanitizeDescription(doc, false); + buffer.append(JsonSchemaHelper.toJson(entry.getName(), entry.getType(), entry.getDefaultValue(), doc, entry.isEnumType(), entry.getEnums())); } buffer.append("\n }"); http://git-wip-us.apache.org/repos/asf/camel/blob/c77199a5/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java index ad1ca8f..108c58a 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java @@ -16,6 +16,8 @@ */ package org.apache.camel.tools.apt; +import java.net.URI; +import java.net.URL; import java.util.Set; /** @@ -77,6 +79,8 @@ final class JsonSchemaHelper { public static String getType(String type, boolean enumType) { if (enumType) { return "enum"; + } if (type.equals(URI.class.getName()) || type.equals(URL.class.getName())) { + return "sting"; } String primitive = getPrimitiveType(type);