001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.remote; 018 019import java.util.ArrayList; 020import java.util.List; 021import java.util.Map; 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlAnyAttribute; 025import javax.xml.bind.annotation.XmlAttribute; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlRootElement; 028import javax.xml.bind.annotation.XmlTransient; 029import javax.xml.namespace.QName; 030 031import org.apache.camel.model.IdentifiedType; 032import org.apache.camel.model.OtherAttributesAware; 033import org.apache.camel.model.ProcessorDefinition; 034import org.apache.camel.model.PropertyDefinition; 035import org.apache.camel.spi.Metadata; 036import org.apache.camel.spi.ServiceCallLoadBalancer; 037import org.apache.camel.spi.ServiceCallServerListStrategy; 038 039/** 040 * Remote service call configuration 041 */ 042@Metadata(label = "eip,routing,remote") 043@XmlRootElement(name = "serviceCallConfiguration") 044@XmlAccessorType(XmlAccessType.FIELD) 045public abstract class ServiceCallConfigurationDefinition extends IdentifiedType implements OtherAttributesAware { 046 047 @XmlTransient 048 private ServiceCallDefinition parent; 049 @XmlAttribute @Metadata(defaultValue = "http") 050 private String component; 051 @XmlAttribute 052 private String loadBalancerRef; 053 @XmlTransient 054 private ServiceCallLoadBalancer loadBalancer; 055 @XmlAttribute 056 private String serverListStrategyRef; 057 @XmlTransient 058 private ServiceCallServerListStrategy serverListStrategy; 059 @XmlElement(name = "clientProperty") @Metadata(label = "advanced") 060 private List<PropertyDefinition> properties; 061 // use xs:any to support optional property placeholders 062 @XmlAnyAttribute 063 private Map<QName, Object> otherAttributes; 064 065 public ServiceCallConfigurationDefinition() { 066 } 067 068 public ServiceCallConfigurationDefinition(ServiceCallDefinition parent) { 069 this.parent = parent; 070 } 071 072 // Getter/Setter 073 // ------------------------------------------------------------------------- 074 075 076 public String getComponent() { 077 return component; 078 } 079 080 public void setComponent(String component) { 081 this.component = component; 082 } 083 084 public String getLoadBalancerRef() { 085 return loadBalancerRef; 086 } 087 088 /** 089 * Sets a reference to a custom {@link org.apache.camel.spi.ServiceCallLoadBalancer} to use. 090 */ 091 public void setLoadBalancerRef(String loadBalancerRef) { 092 this.loadBalancerRef = loadBalancerRef; 093 } 094 095 public ServiceCallLoadBalancer getLoadBalancer() { 096 return loadBalancer; 097 } 098 099 public void setLoadBalancer(ServiceCallLoadBalancer loadBalancer) { 100 this.loadBalancer = loadBalancer; 101 } 102 103 public String getServerListStrategyRef() { 104 return serverListStrategyRef; 105 } 106 107 /** 108 * Sets a reference to a custom {@link org.apache.camel.spi.ServiceCallServerListStrategy} to use. 109 */ 110 public void setServerListStrategyRef(String serverListStrategyRef) { 111 this.serverListStrategyRef = serverListStrategyRef; 112 } 113 114 public ServiceCallServerListStrategy getServerListStrategy() { 115 return serverListStrategy; 116 } 117 118 public void setServerListStrategy(ServiceCallServerListStrategy serverListStrategy) { 119 this.serverListStrategy = serverListStrategy; 120 } 121 122 public List<PropertyDefinition> getProperties() { 123 return properties; 124 } 125 126 /** 127 * Set client properties to use. 128 * <p/> 129 * These properties are specific to what service call implementation are in 130 * use. For example if using ribbon, then the client properties are define 131 * in com.netflix.client.config.CommonClientConfigKey. 132 */ 133 public void setProperties(List<PropertyDefinition> properties) { 134 this.properties = properties; 135 } 136 137 @Override 138 public Map<QName, Object> getOtherAttributes() { 139 return otherAttributes; 140 } 141 142 @Override 143 public void setOtherAttributes(Map<QName, Object> otherAttributes) { 144 this.otherAttributes = otherAttributes; 145 } 146 147 // Fluent API 148 // ------------------------------------------------------------------------- 149 150 /** 151 * Sets the default Camel component to use for calling the remote service. 152 * <p/> 153 * By default the http component is used. You can configure this to use <tt>netty4-http</tt>, <tt>jetty</tt>, 154 * <tt>restlet</tt> or some other components of choice. If the service is not HTTP protocol you can use other 155 * components such as <tt>mqtt</tt>, <tt>jms</tt>, <tt>amqp</tt> etc. 156 * <p/> 157 * If the service call has been configured using an uri, then the component from the uri is used instead 158 * of this default component. 159 */ 160 public ServiceCallConfigurationDefinition component(String component) { 161 setComponent(component); 162 return this; 163 } 164 165 /** 166 * Sets a reference to a custom {@link org.apache.camel.spi.ServiceCallLoadBalancer} to use. 167 */ 168 public ServiceCallConfigurationDefinition loadBalancer(String loadBalancerRef) { 169 setLoadBalancerRef(loadBalancerRef); 170 return this; 171 } 172 173 /** 174 * Sets a custom {@link org.apache.camel.spi.ServiceCallLoadBalancer} to use. 175 */ 176 public ServiceCallConfigurationDefinition loadBalancer(ServiceCallLoadBalancer loadBalancer) { 177 setLoadBalancer(loadBalancer); 178 return this; 179 } 180 181 /** 182 * Sets a reference to a custom {@link org.apache.camel.spi.ServiceCallServerListStrategy} to use. 183 */ 184 public ServiceCallConfigurationDefinition serverListStrategy(String serverListStrategyRef) { 185 setServerListStrategyRef(serverListStrategyRef); 186 return this; 187 } 188 189 /** 190 * Sets a custom {@link org.apache.camel.spi.ServiceCallServerListStrategy} to use. 191 */ 192 public ServiceCallConfigurationDefinition serverListStrategy(ServiceCallServerListStrategy serverListStrategy) { 193 setServerListStrategy(serverListStrategy); 194 return this; 195 } 196 197 /** 198 * Adds a custom client property to use. 199 * <p/> 200 * These properties are specific to what service call implementation are in use. For example if using ribbon, then 201 * the client properties are define in com.netflix.client.config.CommonClientConfigKey. 202 */ 203 public ServiceCallConfigurationDefinition clientProperty(String key, String value) { 204 if (properties == null) { 205 properties = new ArrayList<>(); 206 } 207 PropertyDefinition prop = new PropertyDefinition(); 208 prop.setKey(key); 209 prop.setValue(value); 210 properties.add(prop); 211 return this; 212 } 213 214 /** 215 * End of configuration 216 */ 217 public ProcessorDefinition end() { 218 // end parent as well so we do not have to use 2x end 219 return parent.end(); 220 } 221 222}