001/* 002 * Copyright 2012-2017 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.websocket.servlet; 018 019import org.eclipse.jetty.util.thread.ShutdownThread; 020import org.eclipse.jetty.webapp.AbstractConfiguration; 021import org.eclipse.jetty.webapp.WebAppContext; 022import org.eclipse.jetty.websocket.jsr356.server.ServerContainer; 023import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; 024 025import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; 026import org.springframework.boot.web.server.WebServerFactoryCustomizer; 027import org.springframework.core.Ordered; 028 029/** 030 * WebSocket customizer for {@link JettyServletWebServerFactory}. 031 * 032 * @author Dave Syer 033 * @author Phillip Webb 034 * @author Andy Wilkinson 035 * @since 2.0.0 036 */ 037public class JettyWebSocketServletWebServerCustomizer 038 implements WebServerFactoryCustomizer<JettyServletWebServerFactory>, Ordered { 039 040 @Override 041 public void customize(JettyServletWebServerFactory factory) { 042 factory.addConfigurations(new AbstractConfiguration() { 043 044 @Override 045 public void configure(WebAppContext context) throws Exception { 046 ServerContainer serverContainer = WebSocketServerContainerInitializer 047 .configureContext(context); 048 ShutdownThread.deregister(serverContainer); 049 } 050 051 }); 052 } 053 054 @Override 055 public int getOrder() { 056 return 0; 057 } 058 059}