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.actuate.web.mappings.servlet; 018 019import java.util.Collections; 020import java.util.List; 021import java.util.stream.Collectors; 022 023import javax.servlet.Servlet; 024import javax.servlet.ServletContext; 025 026import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; 027import org.springframework.context.ApplicationContext; 028import org.springframework.web.context.WebApplicationContext; 029 030/** 031 * A {@link MappingDescriptionProvider} that describes that mappings of any {@link Servlet 032 * Servlets} registered with a {@link ServletContext}. 033 * 034 * @author Andy Wilkinson 035 * @since 2.0 036 */ 037public class ServletsMappingDescriptionProvider implements MappingDescriptionProvider { 038 039 @Override 040 public List<ServletRegistrationMappingDescription> describeMappings( 041 ApplicationContext context) { 042 if (!(context instanceof WebApplicationContext)) { 043 return Collections.emptyList(); 044 } 045 return ((WebApplicationContext) context).getServletContext() 046 .getServletRegistrations().values().stream() 047 .map(ServletRegistrationMappingDescription::new) 048 .collect(Collectors.toList()); 049 } 050 051 @Override 052 public String getMappingName() { 053 return "servlets"; 054 } 055 056}