|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -23,8 +23,8 @@ import org.apache.catalina.Context; |
|
|
|
import org.apache.catalina.connector.Connector; |
|
|
|
import org.apache.catalina.connector.Connector; |
|
|
|
import org.apache.catalina.startup.Tomcat; |
|
|
|
import org.apache.catalina.startup.Tomcat; |
|
|
|
import org.apache.coyote.http11.Http11NioProtocol; |
|
|
|
import org.apache.coyote.http11.Http11NioProtocol; |
|
|
|
import org.apache.tomcat.util.descriptor.web.ApplicationListener; |
|
|
|
|
|
|
|
import org.apache.tomcat.websocket.server.WsContextListener; |
|
|
|
import org.apache.tomcat.websocket.server.WsContextListener; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.SocketUtils; |
|
|
|
import org.springframework.util.SocketUtils; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
import org.springframework.web.servlet.DispatcherServlet; |
|
|
|
import org.springframework.web.servlet.DispatcherServlet; |
|
|
|
@ -36,9 +36,6 @@ import org.springframework.web.servlet.DispatcherServlet; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class TomcatWebSocketTestServer implements WebSocketTestServer { |
|
|
|
public class TomcatWebSocketTestServer implements WebSocketTestServer { |
|
|
|
|
|
|
|
|
|
|
|
private static final ApplicationListener WS_APPLICATION_LISTENER = |
|
|
|
|
|
|
|
new ApplicationListener(WsContextListener.class.getName(), false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Tomcat tomcatServer; |
|
|
|
private final Tomcat tomcatServer; |
|
|
|
|
|
|
|
|
|
|
|
private final int port; |
|
|
|
private final int port; |
|
|
|
@ -47,20 +44,19 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TomcatWebSocketTestServer() { |
|
|
|
public TomcatWebSocketTestServer() { |
|
|
|
|
|
|
|
|
|
|
|
this.port = SocketUtils.findAvailableTcpPort(); |
|
|
|
this.port = SocketUtils.findAvailableTcpPort(); |
|
|
|
|
|
|
|
|
|
|
|
Connector connector = new Connector(Http11NioProtocol.class.getName()); |
|
|
|
Connector connector = new Connector(Http11NioProtocol.class.getName()); |
|
|
|
connector.setPort(this.port); |
|
|
|
connector.setPort(this.port); |
|
|
|
|
|
|
|
|
|
|
|
File baseDir = createTempDir("tomcat"); |
|
|
|
File baseDir = createTempDir("tomcat"); |
|
|
|
String baseDirPath = baseDir.getAbsolutePath(); |
|
|
|
String baseDirPath = baseDir.getAbsolutePath(); |
|
|
|
|
|
|
|
|
|
|
|
this.tomcatServer = new Tomcat(); |
|
|
|
this.tomcatServer = new Tomcat(); |
|
|
|
this.tomcatServer.setBaseDir(baseDirPath); |
|
|
|
this.tomcatServer.setBaseDir(baseDirPath); |
|
|
|
this.tomcatServer.setPort(this.port); |
|
|
|
this.tomcatServer.setPort(this.port); |
|
|
|
this.tomcatServer.getService().addConnector(connector); |
|
|
|
this.tomcatServer.getService().addConnector(connector); |
|
|
|
this.tomcatServer.setConnector(connector); |
|
|
|
this.tomcatServer.setConnector(connector); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private File createTempDir(String prefix) { |
|
|
|
private File createTempDir(String prefix) { |
|
|
|
@ -83,9 +79,9 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void deployConfig(WebApplicationContext wac) { |
|
|
|
public void deployConfig(WebApplicationContext wac) { |
|
|
|
this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir")); |
|
|
|
this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir")); |
|
|
|
this.context.addApplicationListener(WS_APPLICATION_LISTENER); |
|
|
|
this.context.addApplicationListener(WsContextListener.class.getName()); |
|
|
|
Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(wac)); |
|
|
|
Tomcat.addServlet(this.context, "dispatcherServlet", new DispatcherServlet(wac)); |
|
|
|
this.context.addServletMapping("/", "dispatcherServlet"); |
|
|
|
this.context.addServletMapping("/", "dispatcherServlet"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|