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.Arrays; 021import java.util.List; 022import java.util.ListIterator; 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.XmlRootElement; 029 030import org.apache.camel.CamelContext; 031import org.apache.camel.spi.Metadata; 032import org.apache.camel.util.ObjectHelper; 033 034@Metadata(label = "routing,cloud,service-filter") 035@XmlRootElement(name = "blacklistServiceFilter") 036@XmlAccessorType(XmlAccessType.FIELD) 037public class BlacklistServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration { 038 @XmlElement 039 private List<String> servers; 040 041 public BlacklistServiceCallServiceFilterConfiguration() { 042 this(null); 043 } 044 045 public BlacklistServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) { 046 super(parent, "blacklist-service-filter"); 047 } 048 049 // ************************************************************************* 050 // Properties 051 // ************************************************************************* 052 053 public List<String> getServers() { 054 return servers; 055 } 056 057 /** 058 * Sets the server blacklist. Each entry can be a list of servers separated 059 * by comma in the format: 060 * [service@]host:port,[service@]host2:port,[service@]host3:port 061 * 062 * @param servers a list of servers. 063 * @return this instance 064 */ 065 public void setServers(List<String> servers) { 066 this.servers = servers; 067 } 068 069 // ************************************************************************* 070 // Fluent API 071 // ************************************************************************* 072 073 /** 074 * Sets the server blacklist. Each entry can be a list of servers separated 075 * by comma in the format: 076 * [service@]host:port,[service@]host2:port,[service@]host3:port 077 * 078 * @param servers a list of servers. 079 * @return this instance 080 */ 081 public BlacklistServiceCallServiceFilterConfiguration servers(List<String> servers) { 082 setServers(servers); 083 return this; 084 } 085 086 /** 087 * Sets the server blacklist. 088 * 089 * @param servers a list of servers separated by comma in the format: 090 * [service@]host:port,[service@]host2:port,[service@]host3:port 091 * @return this instance 092 */ 093 public BlacklistServiceCallServiceFilterConfiguration servers(String servers) { 094 if (ObjectHelper.isNotEmpty(servers)) { 095 String[] parts = servers.split(","); 096 097 if (this.servers == null) { 098 this.servers = new ArrayList<>(); 099 } 100 101 this.servers.addAll(Arrays.asList(parts)); 102 } 103 104 return this; 105 } 106 107 // ************************************************************************* 108 // Utilities 109 // ************************************************************************* 110 111 @Override 112 protected void postProcessFactoryParameters(CamelContext camelContext, Map<String, Object> parameters) throws Exception { 113 List<String> servers = List.class.cast(parameters.get("servers")); 114 115 if (ObjectHelper.isNotEmpty(servers)) { 116 final ListIterator<String> it = servers.listIterator(); 117 while (it.hasNext()) { 118 it.set(camelContext.resolvePropertyPlaceholders(it.next())); 119 } 120 121 parameters.put("servers", servers); 122 } 123 } 124}