Merged branch 'issue-1124-9.2.x' into 'jetty-9.2.x'.
This commit is contained in:
commit
c0b94a9d41
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.websocket.server;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
|
||||||
|
public class InfoContextAttributeListener implements WebSocketCreator, ServletContextListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) sce.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||||
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
|
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
|
||||||
|
{
|
||||||
|
return new InfoSocket();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.websocket.server;
|
||||||
|
|
||||||
|
import javax.servlet.ServletConfig;
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
|
||||||
|
public class InfoServlet extends HttpServlet implements WebSocketCreator
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
|
||||||
|
{
|
||||||
|
return new InfoSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(ServletConfig config) throws ServletException
|
||||||
|
{
|
||||||
|
ServletContext context = config.getServletContext();
|
||||||
|
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(NativeWebSocketConfiguration.class.getName());
|
||||||
|
configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
|
||||||
|
configuration.addMapping(new ServletPathSpec("/info/*"), this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -210,7 +210,7 @@ public class WebSocketUpgradeFilterTest
|
||||||
WSServer server = new WSServer(testDir, "/");
|
WSServer server = new WSServer(testDir, "/");
|
||||||
|
|
||||||
server.copyClass(InfoSocket.class);
|
server.copyClass(InfoSocket.class);
|
||||||
server.copyClass(InfoContextListener.class);
|
server.copyClass(InfoContextAttributeListener.class);
|
||||||
server.copyWebInf("wsuf-config-via-listener.xml");
|
server.copyWebInf("wsuf-config-via-listener.xml");
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
|
@ -220,6 +220,29 @@ public class WebSocketUpgradeFilterTest
|
||||||
return server.getServer();
|
return server.getServer();
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
// WSUF from web.xml, SCI active, apply app-ws configuration via Servlet.init
|
||||||
|
|
||||||
|
cases.add(new Object[]{"wsuf/WebAppContext/web.xml/Servlet.init", new ServerProvider()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Server newServer() throws Exception
|
||||||
|
{
|
||||||
|
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml");
|
||||||
|
|
||||||
|
WSServer server = new WSServer(testDir, "/");
|
||||||
|
|
||||||
|
server.copyClass(InfoSocket.class);
|
||||||
|
server.copyClass(InfoServlet.class);
|
||||||
|
server.copyWebInf("wsuf-config-via-servlet-init.xml");
|
||||||
|
server.start();
|
||||||
|
|
||||||
|
WebAppContext webapp = server.createWebAppContext();
|
||||||
|
server.deployWebapp(webapp);
|
||||||
|
|
||||||
|
return server.getServer();
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
|
||||||
return cases;
|
return cases;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
version="3.1">
|
version="3.1">
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.eclipse.jetty.websocket.server.InfoContextListener</listener-class>
|
<listener-class>org.eclipse.jetty.websocket.server.InfoContextAttributeListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app
|
||||||
|
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
|
version="3.1">
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>info-servlet</servlet-name>
|
||||||
|
<servlet-class>org.eclipse.jetty.websocket.server.InfoServlet</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<filter-name>wsuf</filter-name>
|
||||||
|
<filter-class>org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter</filter-class>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>wsuf</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
</web-app>
|
Loading…
Reference in New Issue