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.cloud; 018 019import java.util.ArrayList; 020import java.util.Collections; 021import java.util.HashMap; 022import java.util.List; 023import java.util.Map; 024 025import javax.xml.bind.annotation.XmlAccessType; 026import javax.xml.bind.annotation.XmlAccessorType; 027import javax.xml.bind.annotation.XmlElement; 028import javax.xml.bind.annotation.XmlType; 029 030import org.apache.camel.CamelContext; 031import org.apache.camel.model.IdentifiedType; 032import org.apache.camel.model.PropertyDefinition; 033import org.apache.camel.spi.Metadata; 034import org.apache.camel.support.CamelContextHelper; 035 036@XmlType(name = "serviceCallConfiguration") 037@XmlAccessorType(XmlAccessType.FIELD) 038public abstract class ServiceCallConfiguration extends IdentifiedType { 039 @XmlElement(name = "properties") 040 @Metadata(label = "advanced") 041 protected List<PropertyDefinition> properties; 042 043 // ************************************************************************* 044 // 045 // ************************************************************************* 046 047 public List<PropertyDefinition> getProperties() { 048 return properties; 049 } 050 051 /** 052 * Set client properties to use. 053 * <p/> 054 * These properties are specific to what service call implementation are in 055 * use. For example if using ribbon, then the client properties are define 056 * in com.netflix.client.config.CommonClientConfigKey. 057 */ 058 public void setProperties(List<PropertyDefinition> properties) { 059 this.properties = properties; 060 } 061 062 /** 063 * Adds a custom property to use. 064 * <p/> 065 * These properties are specific to what service call implementation are in 066 * use. For example if using ribbon, then the client properties are define 067 * in com.netflix.client.config.CommonClientConfigKey. 068 */ 069 public ServiceCallConfiguration property(String key, String value) { 070 if (properties == null) { 071 properties = new ArrayList<>(); 072 } 073 PropertyDefinition prop = new PropertyDefinition(); 074 prop.setKey(key); 075 prop.setValue(value); 076 properties.add(prop); 077 return this; 078 } 079 080 protected Map<String, String> getPropertiesAsMap(CamelContext camelContext) throws Exception { 081 Map<String, String> answer; 082 083 if (properties == null || properties.isEmpty()) { 084 answer = Collections.emptyMap(); 085 } else { 086 answer = new HashMap<>(); 087 for (PropertyDefinition prop : properties) { 088 // support property placeholders 089 String key = CamelContextHelper.parseText(camelContext, prop.getKey()); 090 String value = CamelContextHelper.parseText(camelContext, prop.getValue()); 091 answer.put(key, value); 092 } 093 } 094 095 return answer; 096 } 097 098 // ************************************************************************* 099 // Utilities 100 // ************************************************************************* 101 102 protected void postProcessFactoryParameters(CamelContext camelContext, Map<String, Object> parameters) throws Exception { 103 } 104}