001/* 002 * Copyright 2012-2016 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; 018 019import java.util.Map; 020 021import org.springframework.boot.autoconfigure.AutoConfigureAfter; 022import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 023import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 025import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 026import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; 027import org.springframework.boot.context.properties.EnableConfigurationProperties; 028import org.springframework.boot.web.servlet.ServletRegistrationBean; 029import org.springframework.context.ApplicationContext; 030import org.springframework.context.annotation.Bean; 031import org.springframework.context.annotation.Configuration; 032import org.springframework.ws.config.annotation.EnableWs; 033import org.springframework.ws.config.annotation.WsConfigurationSupport; 034import org.springframework.ws.transport.http.MessageDispatcherServlet; 035 036/** 037 * {@link EnableAutoConfiguration Auto-configuration} for Spring Web Services. 038 * 039 * @author Vedran Pavic 040 * @author Stephane Nicoll 041 * @since 1.4.0 042 */ 043@Configuration 044@ConditionalOnWebApplication 045@ConditionalOnClass(MessageDispatcherServlet.class) 046@ConditionalOnMissingBean(WsConfigurationSupport.class) 047@EnableConfigurationProperties(WebServicesProperties.class) 048@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class) 049public class WebServicesAutoConfiguration { 050 051 private final WebServicesProperties properties; 052 053 public WebServicesAutoConfiguration(WebServicesProperties properties) { 054 this.properties = properties; 055 } 056 057 @Bean 058 public ServletRegistrationBean messageDispatcherServlet( 059 ApplicationContext applicationContext) { 060 MessageDispatcherServlet servlet = new MessageDispatcherServlet(); 061 servlet.setApplicationContext(applicationContext); 062 String path = this.properties.getPath(); 063 String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*"); 064 ServletRegistrationBean registration = new ServletRegistrationBean(servlet, 065 urlMapping); 066 WebServicesProperties.Servlet servletProperties = this.properties.getServlet(); 067 registration.setLoadOnStartup(servletProperties.getLoadOnStartup()); 068 for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) { 069 registration.addInitParameter(entry.getKey(), entry.getValue()); 070 } 071 return registration; 072 } 073 074 @Configuration 075 @EnableWs 076 protected static class WsConfiguration { 077 078 } 079 080}