CAMEL-9683: Started on camel-ribbon
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b478ba12 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b478ba12 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b478ba12 Branch: refs/heads/remoteServiceCall Commit: b478ba12d6b3be8de929d8cf5b69f53700d55eea Parents: 38b6c34 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon May 16 10:27:54 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon May 23 09:26:31 2016 +0200 ---------------------------------------------------------------------- .../support/ServiceCallExpressionSupport.java | 96 ++++++++++++++++++++ .../src/main/docs/kubernetes.adoc | 4 +- .../KubernetesServiceCallExpression.java | 40 ++++++++ .../KubernetesServiceCallProcessor.java | 6 +- ...KubernetesServiceCallServerListStrategy.java | 1 - .../processor/ServiceCallExpression.java | 92 ------------------- .../camel/component/ribbon/RibbonConstants.java | 6 +- .../ribbon/processor/RibbonLoadBalancer.java | 6 +- .../processor/RibbonProcessorFactory.java | 6 +- .../ribbon/processor/RibbonServer.java | 6 +- .../processor/RibbonServiceCallExpression.java | 40 ++++++++ .../processor/RibbonServiceCallProcessor.java | 4 +- ...bbonServiceCallStaticServerListStrategy.java | 6 +- .../ribbon/processor/ServiceCallExpression.java | 92 ------------------- 14 files changed, 198 insertions(+), 207 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/camel-core/src/main/java/org/apache/camel/support/ServiceCallExpressionSupport.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/support/ServiceCallExpressionSupport.java b/camel-core/src/main/java/org/apache/camel/support/ServiceCallExpressionSupport.java new file mode 100644 index 0000000..b08e074 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/support/ServiceCallExpressionSupport.java @@ -0,0 +1,96 @@ +/** + * 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.support; + +import org.apache.camel.Exchange; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Support class for custom implementations of {@link org.apache.camel.model.ServiceCallDefinition ServiceCall EIP} components. + */ +public abstract class ServiceCallExpressionSupport extends ExpressionAdapter { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceCallExpressionSupport.class); + + private final String name; + private final String scheme; + private final String contextPath; + private final String uri; + + public ServiceCallExpressionSupport(String name, String scheme, String contextPath, String uri) { + this.name = name; + this.scheme = scheme; + this.contextPath = contextPath; + this.uri = uri; + } + + public abstract String getIp(Exchange exchange) throws Exception; + + public abstract int getPort(Exchange exchange) throws Exception; + + @Override + public Object evaluate(Exchange exchange) { + try { + String ip = getIp(exchange); + int port = getPort(exchange); + return buildCamelEndpointUri(ip, port, name, uri, contextPath, scheme); + } catch (Exception e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } + } + + protected static String buildCamelEndpointUri(String ip, int port, String name, String uri, String contextPath, String scheme) { + // serviceCall("myService") (will use http by default) + // serviceCall("myService/foo") (will use http by default) + // serviceCall("http:myService/foo") + // serviceCall("myService", "http:myService.host:myService.port/foo") + // serviceCall("myService", "netty4:tcp:myService?connectTimeout=1000") + + // build basic uri if none provided + String answer = uri; + if (answer == null) { + if (scheme == null) { + if (port == 443) { + scheme = "https"; + } else { + scheme = "http"; + } + } + answer = scheme + "://" + ip + ":" + port; + if (contextPath != null) { + answer += "" + contextPath; + } + } else { + // we have existing uri, then replace the serviceName with ip:port + if (answer.contains(name + ".host")) { + answer = answer.replaceFirst(name + "\\.host", ip); + } + if (answer.contains(name + ".port")) { + answer = answer.replaceFirst(name + "\\.port", "" + port); + } + if (answer.contains(name)) { + answer = answer.replaceFirst(name, ip + ":" + port); + } + } + + LOG.debug("Camel endpoint uri: {} for calling service: {} + on server {}:{}", answer, name, ip, port); + return answer; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-kubernetes/src/main/docs/kubernetes.adoc ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/docs/kubernetes.adoc b/components/camel-kubernetes/src/main/docs/kubernetes.adoc index 93ed8f8..3507e04 100644 --- a/components/camel-kubernetes/src/main/docs/kubernetes.adoc +++ b/components/camel-kubernetes/src/main/docs/kubernetes.adoc @@ -44,6 +44,7 @@ The Kubernetes component has no options. + // endpoint options: START The Kubernetes component supports 23 endpoint options which are listed below: @@ -56,7 +57,7 @@ The Kubernetes component supports 23 endpoint options which are listed below: | category | common | | String | *Required* Kubernetes Producer and Consumer category | kubernetesClient | common | | DefaultKubernetesClient | Default KubernetesClient to use if provided | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. -| namespaceName | consumer | | String | The namespace name +| namespace | consumer | | String | The namespace | poolSize | consumer | 1 | int | The Consumer pool size | exceptionHandler | consumer (advanced) | | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored. | operation | producer | | String | Producer operation to do on Kubernetes @@ -80,6 +81,7 @@ The Kubernetes component supports 23 endpoint options which are listed below: + [[Kubernetes-Headers]] Headers ^^^^^^^ http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallExpression.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallExpression.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallExpression.java new file mode 100644 index 0000000..dcb770f --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallExpression.java @@ -0,0 +1,40 @@ +/** + * 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.kubernetes.processor; + +import org.apache.camel.Exchange; +import org.apache.camel.component.kubernetes.KubernetesConstants; +import org.apache.camel.support.ServiceCallExpressionSupport; +import org.apache.camel.util.ExchangeHelper; + +public class KubernetesServiceCallExpression extends ServiceCallExpressionSupport { + + public KubernetesServiceCallExpression(String name, String scheme, String contextPath, String uri) { + super(name, scheme, contextPath, uri); + } + + @Override + public String getIp(Exchange exchange) throws Exception { + return ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_IP, String.class); + } + + @Override + public int getPort(Exchange exchange) throws Exception { + return ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_PORT, int.class); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java index 0cd0d74..976cf63 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java @@ -59,13 +59,11 @@ public class KubernetesServiceCallProcessor extends ServiceSupport implements As private final String uri; private final ExchangePattern exchangePattern; private final KubernetesConfiguration configuration; + private final KubernetesServiceCallExpression serviceCallExpression; private ServiceCallServerListStrategy<KubernetesServer> serverListStrategy; private ServiceCallLoadBalancer<KubernetesServer> loadBalancer; - private final ServiceCallExpression serviceCallExpression; private SendDynamicProcessor processor; - // TODO: allow to plugin custom load balancer like ribbon - public KubernetesServiceCallProcessor(String name, String namespace, String uri, ExchangePattern exchangePattern, KubernetesConfiguration configuration) { // setup from the provided name which can contain scheme and context-path information as well String serviceName; @@ -91,7 +89,7 @@ public class KubernetesServiceCallProcessor extends ServiceSupport implements As this.uri = uri; this.exchangePattern = exchangePattern; this.configuration = configuration; - this.serviceCallExpression = new ServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri); + this.serviceCallExpression = new KubernetesServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallServerListStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallServerListStrategy.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallServerListStrategy.java index 7742c90..94fdc43 100644 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallServerListStrategy.java +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallServerListStrategy.java @@ -1,4 +1,3 @@ - /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java deleted file mode 100644 index 1c2a43a..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * 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.kubernetes.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.support.ExpressionAdapter; -import org.apache.camel.util.ExchangeHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ServiceCallExpression extends ExpressionAdapter { - - private static final Logger LOG = LoggerFactory.getLogger(ServiceCallExpression.class); - - private final String name; - private final String scheme; - private final String contextPath; - private final String uri; - - public ServiceCallExpression(String name, String scheme, String contextPath, String uri) { - this.name = name; - this.scheme = scheme; - this.contextPath = contextPath; - this.uri = uri; - } - - @Override - public Object evaluate(Exchange exchange) { - try { - String ip = ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_IP, String.class); - int port = ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_PORT, int.class); - return buildCamelEndpointUri(ip, port, name, uri, contextPath, scheme); - } catch (Exception e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - } - - protected static String buildCamelEndpointUri(String ip, int port, String name, String uri, String contextPath, String scheme) { - // serviceCall("myService") (will use http by default) - // serviceCall("myService/foo") (will use http by default) - // serviceCall("http:myService/foo") - // serviceCall("myService", "http:myService.host:myService.port/foo") - // serviceCall("myService", "netty4:tcp:myService?connectTimeout=1000") - - // build basic uri if none provided - String answer = uri; - if (answer == null) { - if (scheme == null) { - if (port == 443) { - scheme = "https"; - } else { - scheme = "http"; - } - } - answer = scheme + "://" + ip + ":" + port; - if (contextPath != null) { - answer += "" + contextPath; - } - } else { - // we have existing uri, then replace the serviceName with ip:port - if (answer.contains(name + ".host")) { - answer = answer.replaceFirst(name + "\\.host", ip); - } - if (answer.contains(name + ".port")) { - answer = answer.replaceFirst(name + "\\.port", "" + port); - } - if (answer.contains(name)) { - answer = answer.replaceFirst(name, ip + ":" + port); - } - } - - LOG.debug("Camel endpoint uri: {} for calling service: {} + on server {}:{}", answer, name, ip, port); - return answer; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConstants.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConstants.java index 0a860cd..705d69f 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConstants.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/RibbonConstants.java @@ -5,9 +5,9 @@ * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> + * + * 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. http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonLoadBalancer.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonLoadBalancer.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonLoadBalancer.java index 80ab086..54da6b4 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonLoadBalancer.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonLoadBalancer.java @@ -5,9 +5,9 @@ * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> + * + * 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. http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonProcessorFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonProcessorFactory.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonProcessorFactory.java index efeb2e8..2779734 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonProcessorFactory.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonProcessorFactory.java @@ -5,9 +5,9 @@ * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> + * + * 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. http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServer.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServer.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServer.java index 83233a2..8a545a8 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServer.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServer.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallExpression.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallExpression.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallExpression.java new file mode 100644 index 0000000..b04330a --- /dev/null +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallExpression.java @@ -0,0 +1,40 @@ +/** + * 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.ribbon.processor; + +import org.apache.camel.Exchange; +import org.apache.camel.component.ribbon.RibbonConstants; +import org.apache.camel.support.ServiceCallExpressionSupport; +import org.apache.camel.util.ExchangeHelper; + +public class RibbonServiceCallExpression extends ServiceCallExpressionSupport { + + public RibbonServiceCallExpression(String name, String scheme, String contextPath, String uri) { + super(name, scheme, contextPath, uri); + } + + @Override + public String getIp(Exchange exchange) throws Exception { + return ExchangeHelper.getMandatoryHeader(exchange, RibbonConstants.RIBBON_SERVER_IP, String.class); + } + + @Override + public int getPort(Exchange exchange) throws Exception { + return ExchangeHelper.getMandatoryHeader(exchange, RibbonConstants.RIBBON_SERVER_PORT, int.class); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java index ad74c1d..1dbeaed 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallProcessor.java @@ -64,7 +64,7 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP private ServiceCallLoadBalancer<RibbonServer> loadBalancer; private ZoneAwareLoadBalancer<RibbonServer> ribbonLoadBalancer; private IRule rule; - private final ServiceCallExpression serviceCallExpression; + private final RibbonServiceCallExpression serviceCallExpression; private SendDynamicProcessor processor; // TODO: allow to plugin custom load balancer like ribbon @@ -94,7 +94,7 @@ public class RibbonServiceCallProcessor extends ServiceSupport implements AsyncP this.uri = uri; this.exchangePattern = exchangePattern; this.configuration = configuration; - this.serviceCallExpression = new ServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri); + this.serviceCallExpression = new RibbonServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java index 3b090fe..e315fe9 100644 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java +++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/RibbonServiceCallStaticServerListStrategy.java @@ -5,9 +5,9 @@ * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> + * + * 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. http://git-wip-us.apache.org/repos/asf/camel/blob/b478ba12/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/ServiceCallExpression.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/ServiceCallExpression.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/ServiceCallExpression.java deleted file mode 100644 index 12dbdf4..0000000 --- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/processor/ServiceCallExpression.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.ribbon.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.component.ribbon.RibbonConstants; -import org.apache.camel.support.ExpressionAdapter; -import org.apache.camel.util.ExchangeHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ServiceCallExpression extends ExpressionAdapter { - - private static final Logger LOG = LoggerFactory.getLogger(ServiceCallExpression.class); - - private final String name; - private final String scheme; - private final String contextPath; - private final String uri; - - public ServiceCallExpression(String name, String scheme, String contextPath, String uri) { - this.name = name; - this.scheme = scheme; - this.contextPath = contextPath; - this.uri = uri; - } - - @Override - public Object evaluate(Exchange exchange) { - try { - String ip = ExchangeHelper.getMandatoryHeader(exchange, RibbonConstants.RIBBON_SERVER_IP, String.class); - int port = ExchangeHelper.getMandatoryHeader(exchange, RibbonConstants.RIBBON_SERVER_PORT, int.class); - return buildCamelEndpointUri(ip, port, name, uri, contextPath, scheme); - } catch (Exception e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - } - - protected static String buildCamelEndpointUri(String ip, int port, String name, String uri, String contextPath, String scheme) { - // serviceCall("myService") (will use http by default) - // serviceCall("myService/foo") (will use http by default) - // serviceCall("http:myService/foo") - // serviceCall("myService", "http:myService.host:myService.port/foo") - // serviceCall("myService", "netty4:tcp:myService?connectTimeout=1000") - - // build basic uri if none provided - String answer = uri; - if (answer == null) { - if (scheme == null) { - if (port == 443) { - scheme = "https"; - } else { - scheme = "http"; - } - } - answer = scheme + "://" + ip + ":" + port; - if (contextPath != null) { - answer += "" + contextPath; - } - } else { - // we have existing uri, then replace the serviceName with ip:port - if (answer.contains(name + ".host")) { - answer = answer.replaceFirst(name + "\\.host", ip); - } - if (answer.contains(name + ".port")) { - answer = answer.replaceFirst(name + "\\.port", "" + port); - } - if (answer.contains(name)) { - answer = answer.replaceFirst(name, ip + ":" + port); - } - } - - LOG.debug("Camel endpoint uri: {} for calling service: {} + on server {}:{}", answer, name, ip, port); - return answer; - } - -}