11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2323import org .apache .catalina .connector .Connector ;
2424import org .apache .catalina .startup .Tomcat ;
2525import org .apache .coyote .http11 .Http11NioProtocol ;
26- import org .apache .tomcat .util .descriptor .web .ApplicationListener ;
2726import org .apache .tomcat .websocket .server .WsContextListener ;
27+
2828import org .springframework .util .SocketUtils ;
2929import org .springframework .web .context .WebApplicationContext ;
3030import org .springframework .web .servlet .DispatcherServlet ;
3636 */
3737public class TomcatWebSocketTestServer implements WebSocketTestServer {
3838
39- private static final ApplicationListener WS_APPLICATION_LISTENER =
40- new ApplicationListener (WsContextListener .class .getName (), false );
41-
4239 private final Tomcat tomcatServer ;
4340
4441 private final int port ;
@@ -47,20 +44,19 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer {
4744
4845
4946 public TomcatWebSocketTestServer () {
50-
5147 this .port = SocketUtils .findAvailableTcpPort ();
5248
5349 Connector connector = new Connector (Http11NioProtocol .class .getName ());
54- connector .setPort (this .port );
50+ connector .setPort (this .port );
5551
56- File baseDir = createTempDir ("tomcat" );
57- String baseDirPath = baseDir .getAbsolutePath ();
52+ File baseDir = createTempDir ("tomcat" );
53+ String baseDirPath = baseDir .getAbsolutePath ();
5854
5955 this .tomcatServer = new Tomcat ();
6056 this .tomcatServer .setBaseDir (baseDirPath );
6157 this .tomcatServer .setPort (this .port );
62- this .tomcatServer .getService ().addConnector (connector );
63- this .tomcatServer .setConnector (connector );
58+ this .tomcatServer .getService ().addConnector (connector );
59+ this .tomcatServer .setConnector (connector );
6460 }
6561
6662 private File createTempDir (String prefix ) {
@@ -83,9 +79,9 @@ public int getPort() {
8379
8480 @ Override
8581 public void deployConfig (WebApplicationContext wac ) {
86- this .context = this .tomcatServer .addContext ("" , System .getProperty ("java.io.tmpdir" ));
87- this .context .addApplicationListener (WS_APPLICATION_LISTENER );
88- Tomcat .addServlet (context , "dispatcherServlet" , new DispatcherServlet (wac ));
82+ this .context = this .tomcatServer .addContext ("" , System .getProperty ("java.io.tmpdir" ));
83+ this .context .addApplicationListener (WsContextListener . class . getName () );
84+ Tomcat .addServlet (this . context , "dispatcherServlet" , new DispatcherServlet (wac ));
8985 this .context .addServletMapping ("/" , "dispatcherServlet" );
9086 }
9187
0 commit comments