001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.autoconfigure.webservices.client; 018 019import java.util.List; 020import java.util.stream.Collectors; 021 022import org.springframework.beans.factory.ObjectProvider; 023import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 025import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 026import org.springframework.boot.webservices.client.WebServiceTemplateBuilder; 027import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer; 028import org.springframework.context.annotation.Bean; 029import org.springframework.context.annotation.Configuration; 030import org.springframework.oxm.Marshaller; 031import org.springframework.oxm.Unmarshaller; 032import org.springframework.util.CollectionUtils; 033import org.springframework.ws.client.core.WebServiceTemplate; 034 035/** 036 * {@link EnableAutoConfiguration Auto-configuration} for {@link WebServiceTemplate}. 037 * 038 * @author Dmytro Nosan 039 * @since 2.1.0 040 */ 041@Configuration 042@ConditionalOnClass({ WebServiceTemplate.class, Unmarshaller.class, Marshaller.class }) 043public class WebServiceTemplateAutoConfiguration { 044 045 private final ObjectProvider<WebServiceTemplateCustomizer> webServiceTemplateCustomizers; 046 047 public WebServiceTemplateAutoConfiguration( 048 ObjectProvider<WebServiceTemplateCustomizer> webServiceTemplateCustomizers) { 049 this.webServiceTemplateCustomizers = webServiceTemplateCustomizers; 050 } 051 052 @Bean 053 @ConditionalOnMissingBean 054 public WebServiceTemplateBuilder webServiceTemplateBuilder() { 055 WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder(); 056 List<WebServiceTemplateCustomizer> customizers = this.webServiceTemplateCustomizers 057 .orderedStream().collect(Collectors.toList()); 058 if (!CollectionUtils.isEmpty(customizers)) { 059 builder = builder.customizers(customizers); 060 } 061 return builder; 062 } 063 064}