* Issue #3872 Javax Websocket Packaging Moved JaxaxWebSocketConfiguration and SCI to config package. Limited classpath exposure in JavaxConfiguration (more needed) Updated tests with work around for those that needs more classes exposed Signed-off-by: Greg Wilkins <gregw@webtide.com> * Issue #3872 Javax Websocket Packaging Moved all remaining classes from org.eclipse.jetty.websocket.javax.server to org.eclipse.jetty.websocket.javax.server.internal. This works when running on the classpath, but the tests fail when running on the modulepath (eg in commandline mvn run). The issue appears to be that the tests don't load test classes from WEB-INF/lib or WEB-INF/classes. Instead the test classes were themselves in org.eclipse.jetty.websocket.javax.server, which is no longer exported from module-info.java. The hacked "fix" for this has been to create a org.eclipse.jetty.websocket.javax.server.tests package which is exported and to move all the tests to that. A better fix is needed. Signed-off-by: Greg Wilkins <gregw@webtide.com> * Issue #3872 Javax Websocket Packaging improve comments tighten exposed classes more Signed-off-by: Greg Wilkins <gregw@webtide.com> * Issue #3872 - fixing tests Signed-off-by: Lachlan Roberts <lachlan@webtide.com> * Issue #3872 - move ContainerDefaultConfigurator to config package Signed-off-by: Lachlan Roberts <lachlan@webtide.com> * Issue #3873 - fix javax websocket test classloader issues move websocket endpoints for test webapps to com.acme.websocket package Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
a6ab777150
commit
8f383faf78
|
@ -26,7 +26,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
|
||||
/**
|
||||
* Example of setting up a javax.websocket server with Jetty embedded
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
<Item>org.eclipse.jetty.webapp.JmxConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration</Item>
|
||||
</Array>
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JmxConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration</Item>
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<Item>org.eclipse.jetty.webapp.JmxConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration</Item>
|
||||
</Array>
|
||||
|
|
|
@ -20,13 +20,13 @@ import javax.servlet.ServletContainerInitializer;
|
|||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
|
||||
module org.eclipse.jetty.websocket.javax.server
|
||||
{
|
||||
exports org.eclipse.jetty.websocket.javax.server;
|
||||
exports org.eclipse.jetty.websocket.javax.server.config;
|
||||
|
||||
requires jetty.servlet.api;
|
||||
requires jetty.websocket.api;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.config;
|
||||
|
||||
import org.eclipse.jetty.webapp.AbstractConfiguration;
|
||||
import org.eclipse.jetty.webapp.FragmentConfiguration;
|
||||
|
@ -38,6 +38,7 @@ public class JavaxWebSocketConfiguration extends AbstractConfiguration
|
|||
addDependencies(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class, FragmentConfiguration.class);
|
||||
addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName());
|
||||
protectAndExpose("org.eclipse.jetty.websocket.servlet."); // For WebSocketUpgradeFilter
|
||||
protectAndExpose("org.eclipse.jetty.websocket.javax."); // TODO Do we need all classes?
|
||||
protectAndExpose("org.eclipse.jetty.websocket.javax.server.config.");
|
||||
hide("org.eclipse.jetty.websocket.javax.server.internal");
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ThreadClassLoaderScope;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketMapping;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter;
|
||||
|
|
@ -33,7 +33,7 @@ import javax.websocket.server.ServerEndpoint;
|
|||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator;
|
||||
|
||||
public class AnnotatedServerEndpointConfig implements ServerEndpointConfig
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -41,9 +41,7 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
|||
import org.eclipse.jetty.websocket.core.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.AnnotatedServerEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.UndefinedServerEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketMapping;
|
||||
|
||||
@ManagedObject("JSR356 Server Container")
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.internal;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
|
@ -27,8 +27,6 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
|
|||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.DelegatedJavaxServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.PathParamIdentifier;
|
||||
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
|
@ -27,7 +27,7 @@ import javax.websocket.Encoder;
|
|||
import javax.websocket.Extension;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator;
|
||||
|
||||
public class UndefinedServerEndpointConfig implements ServerEndpointConfig
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer
|
||||
org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer
|
|
@ -1 +1 @@
|
|||
org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator
|
||||
org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator
|
|
@ -1 +1 @@
|
|||
org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration
|
||||
org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration
|
|
@ -1,61 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.javax.server;
|
||||
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PathParamTest
|
||||
{
|
||||
private JavaxWebSocketServerContainer container;
|
||||
|
||||
@BeforeEach
|
||||
public void startContainer() throws Exception
|
||||
{
|
||||
container = new DummyServerContainer();
|
||||
container.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopContainer() throws Exception
|
||||
{
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@ServerEndpoint("/pathparam/basic/{name}")
|
||||
public static class BasicPathParamSocket
|
||||
{
|
||||
@OnMessage
|
||||
public void onMessage(String message, @PathParam("name") String name)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicPathParamSocket() throws DeploymentException
|
||||
{
|
||||
container.addEndpoint(BasicPathParamSocket.class);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
|
||||
/**
|
||||
* Tool to help debug JSR based websocket circumstances reported around browsers.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package org.eclipse.jetty.websocket.javax.server.examples;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
@ -45,9 +45,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.security.Constraint;
|
||||
import org.eclipse.jetty.util.security.Credential;
|
||||
import org.eclipse.jetty.websocket.javax.server.examples.GetHttpSessionSocket;
|
||||
import org.eclipse.jetty.websocket.javax.server.examples.MyAuthedSocket;
|
||||
import org.eclipse.jetty.websocket.javax.server.examples.StreamingEchoSocket;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -93,15 +91,15 @@ public class WebSocketServerExamplesTest
|
|||
}
|
||||
|
||||
static Server _server;
|
||||
static ServerConnector connector;
|
||||
static ServerConnector _connector;
|
||||
static ServletContextHandler _context;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception
|
||||
{
|
||||
_server = new Server();
|
||||
connector = new ServerConnector(_server);
|
||||
_server.addConnector(connector);
|
||||
_connector = new ServerConnector(_server);
|
||||
_server.addConnector(_connector);
|
||||
|
||||
_context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
_context.setContextPath("/");
|
||||
|
@ -116,7 +114,7 @@ public class WebSocketServerExamplesTest
|
|||
});
|
||||
|
||||
_server.start();
|
||||
System.setProperty("org.eclipse.jetty.websocket.port", Integer.toString(connector.getLocalPort()));
|
||||
System.setProperty("org.eclipse.jetty.websocket.port", Integer.toString(_connector.getLocalPort()));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
@ -155,7 +153,7 @@ public class WebSocketServerExamplesTest
|
|||
public void testMyAuthedSocket() throws Exception
|
||||
{
|
||||
//HttpClient is configured for BasicAuthentication with the XmlHttpClientProvider
|
||||
URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/secured/socket");
|
||||
URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/secured/socket");
|
||||
WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
ClientSocket clientEndpoint = new ClientSocket();
|
||||
|
@ -172,7 +170,7 @@ public class WebSocketServerExamplesTest
|
|||
@Test
|
||||
public void testStreamingEchoSocket() throws Exception
|
||||
{
|
||||
URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/echo");
|
||||
URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/echo");
|
||||
WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
ClientSocket clientEndpoint = new ClientSocket();
|
||||
|
@ -189,7 +187,7 @@ public class WebSocketServerExamplesTest
|
|||
@Test
|
||||
public void testGetHttpSessionSocket() throws Exception
|
||||
{
|
||||
URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/example");
|
||||
URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/example");
|
||||
WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
ClientSocket clientEndpoint = new ClientSocket();
|
|
@ -50,9 +50,9 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|||
import org.eclipse.jetty.websocket.core.internal.Parser;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession;
|
||||
import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSessionListener;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerFrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@ServerEndpoint("/echo")
|
||||
public class BasicEchoEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onMessage(String msg)
|
||||
{
|
||||
// reply with echo
|
||||
session.getAsyncRemote().sendText(msg);
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
session.addMessageHandler(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
public class BasicEchoEndpointConfigContextListener implements ServletContextListener
|
||||
{
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
javax.websocket.server.ServerContainer container = (javax.websocket.server.ServerContainer)sce.getServletContext()
|
||||
.getAttribute(javax.websocket.server.ServerContainer.class.getName());
|
||||
if (container == null)
|
||||
throw new IllegalStateException("No Websocket ServerContainer in " + sce.getServletContext());
|
||||
|
||||
// Build up a configuration with a specific path
|
||||
String path = "/echo";
|
||||
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, path);
|
||||
try
|
||||
{
|
||||
container.addEndpoint(builder.build());
|
||||
}
|
||||
catch (DeploymentException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to add endpoint via config file", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
/**
|
||||
* Example of adding a server WebSocket (extending {@link javax.websocket.Endpoint}) programmatically via config
|
||||
*/
|
||||
public class IdleTimeoutContextListener implements ServletContextListener
|
||||
{
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
|
||||
// Build up a configuration with a specific path
|
||||
String path = "/idle-onopen-endpoint";
|
||||
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(OnOpenIdleTimeoutEndpoint.class, path);
|
||||
try
|
||||
{
|
||||
container.addEndpoint(builder.build());
|
||||
}
|
||||
catch (DeploymentException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to add endpoint via config file", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.Session;
|
||||
|
||||
public class IdleTimeoutOnOpenEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
session.addMessageHandler(this);
|
||||
session.setMaxIdleTimeout(500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
// echo message back (this is an indication of timeout failure)
|
||||
session.getAsyncRemote().sendText(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.WebSocketTimeoutException;
|
||||
|
||||
@ServerEndpoint(value = "/idle-onopen-socket")
|
||||
public class IdleTimeoutOnOpenSocket
|
||||
{
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
session.setMaxIdleTimeout(500);
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public String onMessage(String msg)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Throwable cause)
|
||||
{
|
||||
if (!(cause instanceof WebSocketTimeoutException))
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
|
||||
public class LargeEchoContextListener implements ServletContextListener
|
||||
{
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
|
||||
container.setDefaultMaxTextMessageBufferSize(128 * 1024);
|
||||
}
|
||||
}
|
|
@ -16,14 +16,18 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.javax.server;
|
||||
package com.acme.websocket;
|
||||
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketMapping;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
public class DummyServerContainer extends JavaxWebSocketServerContainer
|
||||
@ServerEndpoint(value = "/echo/large")
|
||||
public class LargeEchoDefaultSocket
|
||||
{
|
||||
public DummyServerContainer()
|
||||
@OnMessage
|
||||
public void echo(javax.websocket.Session session, String msg)
|
||||
{
|
||||
super(new WebSocketMapping());
|
||||
// reply with echo
|
||||
session.getAsyncRemote().sendText(msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.Session;
|
||||
|
||||
public class OnOpenIdleTimeoutEndpoint extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
session.addMessageHandler(this);
|
||||
session.setMaxIdleTimeout(500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
// echo message back (this is an indication of timeout failure)
|
||||
session.getAsyncRemote().sendText(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
public class PongContextListener implements ServletContextListener
|
||||
{
|
||||
public static class Config extends ServerEndpointConfig.Configurator
|
||||
{
|
||||
@Override
|
||||
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response)
|
||||
{
|
||||
sec.getUserProperties().put("path", sec.getPath());
|
||||
super.modifyHandshake(sec, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
|
||||
try
|
||||
{
|
||||
ServerEndpointConfig.Configurator config = new Config();
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").configurator(config).build());
|
||||
}
|
||||
catch (DeploymentException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to add endpoint directly", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
|
||||
public class PongMessageEndpoint extends Endpoint implements MessageHandler.Whole<PongMessage>
|
||||
{
|
||||
private String path = "?";
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.session.addMessageHandler(this);
|
||||
this.path = (String)config.getUserProperties().get("path");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(PongMessage pong)
|
||||
{
|
||||
byte[] buf = toArray(pong.getApplicationData());
|
||||
String message = new String(buf, StandardCharsets.UTF_8);
|
||||
this.session.getAsyncRemote().sendText("PongMessageEndpoint.onMessage(PongMessage):[" + path + "]:" + message);
|
||||
}
|
||||
|
||||
public static byte[] toArray(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer.hasArray())
|
||||
{
|
||||
byte[] array = buffer.array();
|
||||
int from = buffer.arrayOffset() + buffer.position();
|
||||
return Arrays.copyOfRange(array, from, from + buffer.remaining());
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] to = new byte[buffer.remaining()];
|
||||
buffer.slice().get(to);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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 com.acme.websocket;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@ServerEndpoint(value = "/pong-socket", configurator = PongContextListener.Config.class)
|
||||
public class PongSocket
|
||||
{
|
||||
private String path = "?";
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.path = (String)config.getUserProperties().get("path");
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onPong(PongMessage pong)
|
||||
{
|
||||
byte[] buf = toArray(pong.getApplicationData());
|
||||
String message = new String(buf, StandardCharsets.UTF_8);
|
||||
this.session.getAsyncRemote().sendText("PongSocket.onPong(PongMessage)[" + path + "]:" + message);
|
||||
}
|
||||
|
||||
public static byte[] toArray(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer.hasArray())
|
||||
{
|
||||
byte[] array = buffer.array();
|
||||
int from = buffer.arrayOffset() + buffer.position();
|
||||
return Arrays.copyOfRange(array, from, from + buffer.remaining());
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] to = new byte[buffer.remaining()];
|
||||
buffer.slice().get(to);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.javax.tests;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class PathParamTest
|
||||
{
|
||||
private Server _server;
|
||||
private ServerConnector _connector;
|
||||
private ServletContextHandler _context;
|
||||
|
||||
@BeforeEach
|
||||
public void startContainer() throws Exception
|
||||
{
|
||||
_server = new Server();
|
||||
_connector = new ServerConnector(_server);
|
||||
_server.addConnector(_connector);
|
||||
|
||||
_context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
_context.setContextPath("/");
|
||||
_server.setHandler(_context);
|
||||
|
||||
JavaxWebSocketServletContainerInitializer.configure(_context, (context, container) ->
|
||||
container.addEndpoint(EchoParamSocket.class));
|
||||
|
||||
_server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void stopContainer() throws Exception
|
||||
{
|
||||
_server.stop();
|
||||
}
|
||||
|
||||
@ServerEndpoint("/pathparam/echo/{name}")
|
||||
public static class EchoParamSocket
|
||||
{
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message, @PathParam("name") String name)
|
||||
{
|
||||
session.getAsyncRemote().sendText(message+"-"+name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicPathParamSocket() throws Exception
|
||||
{
|
||||
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
|
||||
EventSocket clientEndpoint = new EventSocket();
|
||||
|
||||
URI serverUri = URI.create("ws://localhost:"+ _connector.getLocalPort()+"/pathparam/echo/myParam");
|
||||
Session session = container.connectToServer(clientEndpoint, serverUri);
|
||||
session.getBasicRemote().sendText("echo");
|
||||
|
||||
String resp = clientEndpoint.messageQueue.poll(1, TimeUnit.SECONDS);
|
||||
assertThat("Response echo", resp, is("echo-myParam"));
|
||||
session.close();
|
||||
clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -37,8 +37,8 @@ import org.eclipse.jetty.server.ServerConnector;
|
|||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
import org.eclipse.jetty.websocket.javax.client.EmptyClientEndpointConfig;
|
||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||
import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.javax.common.util.InvalidSignatureException;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidCloseIntSocket;
|
||||
import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidErrorErrorSocket;
|
||||
import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidErrorIntSocket;
|
||||
|
|
|
@ -21,16 +21,9 @@ package org.eclipse.jetty.websocket.javax.tests.server;
|
|||
import java.net.URI;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import com.acme.websocket.BasicEchoEndpoint;
|
||||
import com.acme.websocket.BasicEchoEndpointConfigContextListener;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
@ -41,7 +34,6 @@ import org.eclipse.jetty.websocket.core.Frame;
|
|||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||
import org.eclipse.jetty.websocket.javax.tests.WSEventTracker;
|
||||
import org.eclipse.jetty.websocket.javax.tests.WSServer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.framehandlers.FrameHandlerTracker;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -59,55 +51,6 @@ public class EndpointViaConfigTest
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(EndpointViaConfigTest.class);
|
||||
|
||||
@ServerEndpoint("/echo")
|
||||
public static class BasicEchoEndpoint extends WSEventTracker implements MessageHandler.Whole<String>
|
||||
{
|
||||
@Override
|
||||
public void onMessage(String msg)
|
||||
{
|
||||
super.onWsText(msg);
|
||||
// reply with echo
|
||||
session.getAsyncRemote().sendText(msg);
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
super.onWsOpen(session, config);
|
||||
this.session.addMessageHandler(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BasicEchoEndpointConfigContextListener implements ServletContextListener
|
||||
{
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
javax.websocket.server.ServerContainer container = (javax.websocket.server.ServerContainer)sce.getServletContext()
|
||||
.getAttribute(javax.websocket.server.ServerContainer.class.getName());
|
||||
if (container == null)
|
||||
throw new IllegalStateException("No Websocket ServerContainer in " + sce.getServletContext());
|
||||
|
||||
// Build up a configuration with a specific path
|
||||
String path = "/echo";
|
||||
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, path);
|
||||
try
|
||||
{
|
||||
container.addEndpoint(builder.build());
|
||||
}
|
||||
catch (DeploymentException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to add endpoint via config file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WorkDir testdir;
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,6 +21,9 @@ package org.eclipse.jetty.websocket.javax.tests.server;
|
|||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.acme.websocket.IdleTimeoutContextListener;
|
||||
import com.acme.websocket.IdleTimeoutOnOpenEndpoint;
|
||||
import com.acme.websocket.IdleTimeoutOnOpenSocket;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.log.StacklessLogging;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
@ -29,8 +32,6 @@ import org.eclipse.jetty.websocket.core.Frame;
|
|||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
import org.eclipse.jetty.websocket.javax.tests.Fuzzer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.WSServer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.server.sockets.IdleTimeoutOnOpenEndpoint;
|
||||
import org.eclipse.jetty.websocket.javax.tests.server.sockets.IdleTimeoutOnOpenSocket;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -59,7 +60,6 @@ public class IdleTimeoutTest
|
|||
|
||||
WebAppContext webapp = server.createWebAppContext();
|
||||
server.deployWebapp(webapp);
|
||||
// wsb.dump();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.Iterator;
|
|||
import java.util.ServiceLoader;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
|
|
@ -23,12 +23,8 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.Arrays;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import com.acme.websocket.LargeEchoDefaultSocket;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
@ -51,33 +47,6 @@ import static org.hamcrest.Matchers.is;
|
|||
@ExtendWith(WorkDirExtension.class)
|
||||
public class LargeContainerTest
|
||||
{
|
||||
@ServerEndpoint(value = "/echo/large")
|
||||
public static class LargeEchoDefaultSocket
|
||||
{
|
||||
@OnMessage
|
||||
public void echo(javax.websocket.Session session, String msg)
|
||||
{
|
||||
// reply with echo
|
||||
session.getAsyncRemote().sendText(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LargeEchoContextListener implements ServletContextListener
|
||||
{
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
|
||||
container.setDefaultMaxTextMessageBufferSize(128 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
public WorkDir testdir;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
|
@ -95,7 +64,6 @@ public class LargeContainerTest
|
|||
|
||||
WebAppContext webapp = wsb.createWebAppContext();
|
||||
wsb.deployWebapp(webapp);
|
||||
// wsb.dump();
|
||||
|
||||
WebSocketCoreClient client = new WebSocketCoreClient();
|
||||
try
|
||||
|
|
|
@ -35,7 +35,7 @@ import javax.websocket.server.ServerEndpointConfig;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
@ -19,33 +19,17 @@
|
|||
package org.eclipse.jetty.websocket.javax.tests.server;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import com.acme.websocket.PongContextListener;
|
||||
import com.acme.websocket.PongMessageEndpoint;
|
||||
import com.acme.websocket.PongSocket;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
|
@ -64,87 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertTimeout;
|
|||
|
||||
public class PingPongTest
|
||||
{
|
||||
@ServerEndpoint(value = "/pong-socket", configurator = PongContextListener.Config.class)
|
||||
public static class PongSocket
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(PongSocket.class);
|
||||
private String path = "?";
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.path = (String)config.getUserProperties().get("path");
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onPong(PongMessage pong)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("PongSocket.onPong(): PongMessage.appData={}", BufferUtil.toDetailString(pong.getApplicationData()));
|
||||
byte[] buf = BufferUtil.toArray(pong.getApplicationData());
|
||||
String message = new String(buf, StandardCharsets.UTF_8);
|
||||
this.session.getAsyncRemote().sendText("PongSocket.onPong(PongMessage)[" + path + "]:" + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PongMessageEndpoint extends Endpoint implements MessageHandler.Whole<PongMessage>
|
||||
{
|
||||
private String path = "?";
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
this.session = session;
|
||||
this.session.addMessageHandler(this);
|
||||
this.path = (String)config.getUserProperties().get("path");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(PongMessage pong)
|
||||
{
|
||||
byte[] buf = BufferUtil.toArray(pong.getApplicationData());
|
||||
String message = new String(buf, StandardCharsets.UTF_8);
|
||||
this.session.getAsyncRemote().sendText("PongMessageEndpoint.onMessage(PongMessage):[" + path + "]:" + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PongContextListener implements ServletContextListener
|
||||
{
|
||||
public static class Config extends ServerEndpointConfig.Configurator
|
||||
{
|
||||
@Override
|
||||
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response)
|
||||
{
|
||||
sec.getUserProperties().put("path", sec.getPath());
|
||||
super.modifyHandshake(sec, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
|
||||
try
|
||||
{
|
||||
ServerEndpointConfig.Configurator config = new Config();
|
||||
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").configurator(config).build());
|
||||
}
|
||||
catch (DeploymentException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to add endpoint directly", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static WSServer server;
|
||||
private static WebSocketCoreClient client;
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
|
||||
import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer;
|
||||
import org.eclipse.jetty.websocket.javax.tests.WSURI;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE;
|
||||
import static org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
version="3.0">
|
||||
|
||||
<listener>
|
||||
<listener-class>org.eclipse.jetty.websocket.javax.tests.server.EndpointViaConfigTest$BasicEchoEndpointConfigContextListener</listener-class>
|
||||
<listener-class>com.acme.websocket.BasicEchoEndpointConfigContextListener</listener-class>
|
||||
</listener>
|
||||
</web-app>
|
|
@ -7,6 +7,6 @@
|
|||
version="3.0">
|
||||
|
||||
<listener>
|
||||
<listener-class>org.eclipse.jetty.websocket.javax.tests.server.IdleTimeoutContextListener</listener-class>
|
||||
<listener-class>com.acme.websocket.IdleTimeoutContextListener</listener-class>
|
||||
</listener>
|
||||
</web-app>
|
|
@ -7,6 +7,6 @@
|
|||
version="3.0">
|
||||
|
||||
<listener>
|
||||
<listener-class>org.eclipse.jetty.websocket.javax.tests.server.LargeContainerTest$LargeEchoContextListener</listener-class>
|
||||
<listener-class>com.acme.websocket.LargeEchoContextListener</listener-class>
|
||||
</listener>
|
||||
</web-app>
|
|
@ -7,6 +7,6 @@
|
|||
version="3.0">
|
||||
|
||||
<listener>
|
||||
<listener-class>org.eclipse.jetty.websocket.javax.tests.server.PingPongTest$PongContextListener</listener-class>
|
||||
<listener-class>com.acme.websocket.PongContextListener</listener-class>
|
||||
</listener>
|
||||
</web-app>
|
|
@ -25,6 +25,7 @@ import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerI
|
|||
module org.eclipse.jetty.websocket.jetty.server
|
||||
{
|
||||
exports org.eclipse.jetty.websocket.server;
|
||||
exports org.eclipse.jetty.websocket.server.config;
|
||||
|
||||
requires jetty.servlet.api;
|
||||
requires org.eclipse.jetty.http;
|
||||
|
|
Loading…
Reference in New Issue