Merge branch 'master' into release-9
This commit is contained in:
commit
5d333c3f60
|
@ -25,7 +25,6 @@ import org.eclipse.jetty.deploy.PropertiesConfigurationManager;
|
|||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
|
@ -42,7 +41,7 @@ import org.eclipse.jetty.server.handler.RequestLogHandler;
|
|||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
|
||||
public class LikeJettyXml
|
||||
{
|
||||
|
@ -51,7 +50,7 @@ public class LikeJettyXml
|
|||
String jetty_home = System.getProperty("jetty.home","../../jetty-distribution/target/distribution");
|
||||
System.setProperty("jetty.home",jetty_home);
|
||||
|
||||
|
||||
|
||||
// === jetty.xml ===
|
||||
// Setup Threadpool
|
||||
QueuedThreadPool threadPool = new QueuedThreadPool();
|
||||
|
@ -61,7 +60,7 @@ public class LikeJettyXml
|
|||
Server server = new Server(threadPool);
|
||||
|
||||
// Scheduler
|
||||
server.addBean(new TimerScheduler());
|
||||
server.addBean(new ScheduledExecutorScheduler());
|
||||
|
||||
// HTTP Configuration
|
||||
HttpConfiguration http_config = new HttpConfiguration();
|
||||
|
@ -73,7 +72,7 @@ public class LikeJettyXml
|
|||
http_config.setSendServerVersion(true);
|
||||
http_config.setSendDateHeader(false);
|
||||
// httpConfig.addCustomizer(new ForwardedRequestCustomizer());
|
||||
|
||||
|
||||
// Handler Structure
|
||||
HandlerCollection handlers = new HandlerCollection();
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
|
@ -84,21 +83,21 @@ public class LikeJettyXml
|
|||
server.setDumpAfterStart(false);
|
||||
server.setDumpBeforeStop(false);
|
||||
server.setStopAtShutdown(true);
|
||||
|
||||
|
||||
// === jetty-jmx.xml ===
|
||||
|
||||
// === jetty-jmx.xml ===
|
||||
MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
|
||||
server.addBean(mbContainer);
|
||||
|
||||
|
||||
// === jetty-http.xml ===
|
||||
|
||||
// === jetty-http.xml ===
|
||||
ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(http_config));
|
||||
http.setPort(8080);
|
||||
http.setIdleTimeout(30000);
|
||||
server.addConnector(http);
|
||||
|
||||
|
||||
// === jetty-https.xml ===
|
||||
|
||||
// === jetty-https.xml ===
|
||||
// SSL Context Factory
|
||||
SslContextFactory sslContextFactory = new SslContextFactory();
|
||||
sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore");
|
||||
|
@ -114,11 +113,11 @@ public class LikeJettyXml
|
|||
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
||||
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
||||
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
|
||||
|
||||
|
||||
// SSL HTTP Configuration
|
||||
HttpConfiguration https_config = new HttpConfiguration(http_config);
|
||||
https_config.addCustomizer(new SecureRequestCustomizer());
|
||||
|
||||
|
||||
// SSL Connector
|
||||
ServerConnector sslConnector = new ServerConnector(server,
|
||||
new SslConnectionFactory(sslContextFactory,"http/1.1"),
|
||||
|
@ -141,15 +140,15 @@ public class LikeJettyXml
|
|||
|
||||
deployer.addAppProvider(webapp_provider);
|
||||
server.addBean(deployer);
|
||||
|
||||
|
||||
// === jetty-stats.xml ===
|
||||
|
||||
// === jetty-stats.xml ===
|
||||
StatisticsHandler stats = new StatisticsHandler();
|
||||
stats.setHandler(server.getHandler());
|
||||
server.setHandler(stats);
|
||||
|
||||
|
||||
// === jetty-requestlog.xml ===
|
||||
// === jetty-requestlog.xml ===
|
||||
NCSARequestLog requestLog = new NCSARequestLog();
|
||||
requestLog.setFilename(jetty_home + "/logs/jetty-yyyy_mm_dd.log");
|
||||
requestLog.setFilenameDateFormat("yyyy_MM_dd");
|
||||
|
@ -163,7 +162,7 @@ public class LikeJettyXml
|
|||
handlers.addHandler(requestLogHandler);
|
||||
|
||||
|
||||
// === jetty-lowresources.xml ===
|
||||
// === jetty-lowresources.xml ===
|
||||
LowResourceMonitor lowResourcesMonitor=new LowResourceMonitor(server);
|
||||
lowResourcesMonitor.setPeriod(1000);
|
||||
lowResourcesMonitor.setLowResourcesIdleTimeout(200);
|
||||
|
@ -173,8 +172,8 @@ public class LikeJettyXml
|
|||
lowResourcesMonitor.setMaxLowResourcesTime(5000);
|
||||
server.addBean(lowResourcesMonitor);
|
||||
|
||||
|
||||
// === test-realm.xml ===
|
||||
|
||||
// === test-realm.xml ===
|
||||
HashLoginService login = new HashLoginService();
|
||||
login.setName("Test Realm");
|
||||
login.setConfig(jetty_home + "/etc/realm.properties");
|
||||
|
@ -182,7 +181,7 @@ public class LikeJettyXml
|
|||
server.addBean(login);
|
||||
|
||||
|
||||
// Start the server
|
||||
// Start the server
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.annotations;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -29,6 +30,7 @@ import javax.servlet.annotation.HandlesTypes;
|
|||
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
||||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||
import org.eclipse.jetty.util.ArrayUtil;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -221,10 +223,10 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
|
||||
|
||||
|
||||
//add a listener which will call the servletcontainerinitializers when appropriate
|
||||
//add a bean which will call the servletcontainerinitializers when appropriate
|
||||
ServletContainerInitializerListener listener = new ServletContainerInitializerListener();
|
||||
listener.setWebAppContext(context);
|
||||
context.addEventListener(listener);
|
||||
context.addBean(listener, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,11 +22,10 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
@ -36,7 +35,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
*
|
||||
*
|
||||
*/
|
||||
public class ServletContainerInitializerListener implements ServletContextListener
|
||||
public class ServletContainerInitializerListener extends AbstractLifeCycle
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ServletContainerInitializerListener.class);
|
||||
protected WebAppContext _context = null;
|
||||
|
@ -47,10 +46,12 @@ public class ServletContainerInitializerListener implements ServletContextListen
|
|||
_context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
|
||||
|
||||
/**
|
||||
* Call the doStart method of the ServletContainerInitializers
|
||||
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
|
||||
*/
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
public void doStart()
|
||||
{
|
||||
List<ContainerInitializer> initializers = (List<ContainerInitializer>)_context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
|
||||
MultiMap classMap = (MultiMap)_context.getAttribute(AnnotationConfiguration.CLASS_INHERITANCE_MAP);
|
||||
|
@ -129,12 +130,14 @@ public class ServletContainerInitializerListener implements ServletContextListen
|
|||
addInheritedTypes (classMap, initializer, implementsOrExtends);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Nothing to do for ServletContainerInitializers on stop
|
||||
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop()
|
||||
*/
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
public void doStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -217,8 +217,6 @@ public class HttpClient extends ContainerLifeCycle
|
|||
cookieStore = cookieManager.getCookieStore();
|
||||
|
||||
super.doStart();
|
||||
|
||||
LOG.info("Started {}", this);
|
||||
}
|
||||
|
||||
protected SelectorManager newSelectorManager()
|
||||
|
@ -234,8 +232,6 @@ public class HttpClient extends ContainerLifeCycle
|
|||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
LOG.debug("Stopping {}", this);
|
||||
|
||||
cookieStore.removeAll();
|
||||
cookieStore = null;
|
||||
decoderFactories.clear();
|
||||
|
@ -251,8 +247,6 @@ public class HttpClient extends ContainerLifeCycle
|
|||
authenticationStore.clearAuthenticationResults();
|
||||
|
||||
super.doStop();
|
||||
|
||||
LOG.info("Stopped {}", this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -175,7 +175,8 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new RejectedExecutionException("Max requests per destination " + client.getMaxRequestsQueuedPerDestination() + " exceeded");
|
||||
LOG.debug("Max queued exceeded {}", request);
|
||||
abort(exchange, new RejectedExecutionException("Max requests per destination " + client.getMaxRequestsQueuedPerDestination() + " exceeded for " + this));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -208,7 +209,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
|
||||
if (next > maxConnections)
|
||||
{
|
||||
LOG.debug("Max connections {} reached for {}", current, this);
|
||||
LOG.debug("Max connections per destination {} exceeded for {}", current, this);
|
||||
// Try again the idle connections
|
||||
return idleConnections.poll();
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public class InputStreamResponseListener extends Response.Listener.Empty
|
|||
else if (bytes != null)
|
||||
{
|
||||
if (index < bytes.length)
|
||||
return bytes[index++];
|
||||
return bytes[index++] & 0xFF;
|
||||
length.addAndGet(-index);
|
||||
bytes = null;
|
||||
index = 0;
|
||||
|
|
|
@ -58,6 +58,8 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class HttpClientStreamTest extends AbstractHttpClientServerTest
|
||||
|
@ -150,6 +152,46 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest
|
|||
Assert.assertSame(response, result.getResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDownloadOfUTF8Content() throws Exception
|
||||
{
|
||||
final byte[] data = new byte[]{(byte)0xC3, (byte)0xA8}; // UTF-8 representation of è
|
||||
start(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
response.getOutputStream().write(data);
|
||||
}
|
||||
});
|
||||
|
||||
InputStreamResponseListener listener = new InputStreamResponseListener();
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(listener);
|
||||
Response response = listener.get(5, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
|
||||
InputStream input = listener.getInputStream();
|
||||
Assert.assertNotNull(input);
|
||||
|
||||
for (byte b : data)
|
||||
{
|
||||
int read = input.read();
|
||||
assertTrue(read >= 0);
|
||||
assertEquals(b & 0xFF, read);
|
||||
}
|
||||
|
||||
assertEquals(-1, input.read());
|
||||
|
||||
Result result = listener.await(5, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertFalse(result.isFailed());
|
||||
Assert.assertSame(response, result.getResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDownloadWithFailure() throws Exception
|
||||
{
|
||||
|
|
|
@ -19,11 +19,17 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.api.Connection;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -155,4 +161,56 @@ public class HttpDestinationTest extends AbstractHttpClientServerTest
|
|||
Assert.assertNull(connection1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Request_Failed_If_MaxRequestsQueuedPerDestination_Exceeded() throws Exception
|
||||
{
|
||||
int maxQueued = 1;
|
||||
client.setMaxRequestsQueuedPerDestination(maxQueued);
|
||||
client.setMaxConnectionsPerDestination(1);
|
||||
|
||||
// Make one request to open the connection and be sure everything is setup properly
|
||||
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send();
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
|
||||
// Send another request that is sent immediately
|
||||
final CountDownLatch successLatch = new CountDownLatch(1);
|
||||
final CountDownLatch failureLatch = new CountDownLatch(1);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.onRequestQueued(new Request.QueuedListener()
|
||||
{
|
||||
@Override
|
||||
public void onQueued(Request request)
|
||||
{
|
||||
// This request exceeds the maximum queued, should fail
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
Assert.assertTrue(result.isFailed());
|
||||
Assert.assertThat(result.getRequestFailure(), Matchers.instanceOf(RejectedExecutionException.class));
|
||||
failureLatch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
if (result.isSucceeded())
|
||||
successLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertTrue(failureLatch.await(5, TimeUnit.SECONDS));
|
||||
Assert.assertTrue(successLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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.client;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* IdleTimeoutTest
|
||||
*
|
||||
* Warning - this is a slow test. Uncomment the ignore to run it.
|
||||
*
|
||||
*/
|
||||
public class IdleTimeoutTest
|
||||
{
|
||||
public int _repetitions = 30;
|
||||
|
||||
@Slow
|
||||
@Ignore
|
||||
public void testIdleTimeoutOnBlockingConnector() throws Exception
|
||||
{
|
||||
|
||||
final HttpClient client = new HttpClient();
|
||||
client.setMaxConnectionsPerDestination(4);
|
||||
client.setIdleTimeout(500); // very short idle timeout
|
||||
client.start();
|
||||
|
||||
final CountDownLatch counter = new CountDownLatch(_repetitions);
|
||||
|
||||
Thread runner = new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i=0; i<_repetitions; i++)
|
||||
{
|
||||
ContentResponse response = client.GET("http://www.google.com/?i="+i);
|
||||
counter.countDown();
|
||||
System.err.println(counter.getCount());
|
||||
Thread.sleep(1000); //wait long enough for idle timeout to expire
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
runner.start();
|
||||
if (!counter.await(80, TimeUnit.SECONDS))
|
||||
Assert.fail("Test did not complete in time");
|
||||
}
|
||||
}
|
|
@ -134,7 +134,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
*/
|
||||
public void addApp(App app)
|
||||
{
|
||||
LOG.info("Deployable added: " + app.getOriginId());
|
||||
LOG.debug("Deployable added: {}",app.getOriginId());
|
||||
AppEntry entry = new AppEntry();
|
||||
entry.app = app;
|
||||
entry.setLifeCycleNode(_lifecycle.getNodeByName("undeployed"));
|
||||
|
@ -405,7 +405,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
if (! AppLifeCycle.UNDEPLOYED.equals(entry.lifecyleNode.getName()))
|
||||
requestAppGoal(entry.app,AppLifeCycle.UNDEPLOYED);
|
||||
it.remove();
|
||||
LOG.info("Deployable removed: " + entry.app);
|
||||
LOG.debug("Deployable removed: {}",entry.app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ public class DeploymentManager extends ContainerLifeCycle
|
|||
|
||||
public void undeployAll()
|
||||
{
|
||||
LOG.info("Undeploy All");
|
||||
LOG.debug("Undeploy All");
|
||||
for (AppEntry appentry : _apps)
|
||||
{
|
||||
requestAppGoal(appentry,"undeployed");
|
||||
|
|
|
@ -1,28 +1,33 @@
|
|||
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
|
||||
<head>
|
||||
<META http-equiv="Pragma" content="no-cache">
|
||||
<META http-equiv="Cache-Control" content="no-cache,no-store">
|
||||
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
|
||||
<title>Welcome to Jetty-9</title>
|
||||
<style type="text/css" title="jetty">
|
||||
@import url(jetty.css);
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header"></div>
|
||||
|
||||
<div id="content">
|
||||
<h1>Welcome to Jetty 9</h1>
|
||||
<html xmlns=\ "http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
|
||||
<head>
|
||||
<META http-equiv="Pragma" content="no-cache">
|
||||
<META http-equiv="Cache-Control" content="no-cache,no-store">
|
||||
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
|
||||
<title>Welcome to Jetty-9</title>
|
||||
<style type="text/css" title="jetty">
|
||||
@import url(jetty.css);
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
The Jetty project is a 100% Java <a href="http://en.wikipedia.org/wiki/Java_Servlet">Servlet</a> Container which supports asynchronous server and client implementations of the <a href="http://en.wikipedia.org/wiki/HTTP">HTTP</a>, <a href="http://en.wikipedia.org/wiki/WebSocket">Websocket</a> and <a href="http://en.wikipedia.org/wiki/SPDY">SPDY</a> protocols.
|
||||
The project is 100% <a href="http://en.wikipedia.org/wiki/Open_source">Open Source</a> and hosted by the <a href="http://www.eclipse.org">Eclipse Foundation</a> at <a href="http://www.eclipse.org/jetty/">http://www.eclipse.org/jetty</a>.
|
||||
</p>
|
||||
</div>
|
||||
<div id="header"></div>
|
||||
|
||||
<div id="links">
|
||||
<table>
|
||||
<div id="content">
|
||||
<h1>Welcome to Jetty 9</h1>
|
||||
|
||||
<p>
|
||||
The Jetty project is a 100% Java <a
|
||||
href="http://en.wikipedia.org/wiki/Java_Servlet">Servlet</a>
|
||||
Container which supports asynchronous server and client
|
||||
implementations of the <a href="http://en.wikipedia.org/wiki/HTTP">HTTP</a>,
|
||||
<a href="http://en.wikipedia.org/wiki/WebSocket">Websocket</a> and <a
|
||||
href="http://en.wikipedia.org/wiki/SPDY">SPDY</a> protocols. The
|
||||
project is 100% <a href="http://en.wikipedia.org/wiki/Open_source">Open Source</a> and hosted by the <a href="http://www.eclipse.org">Eclipse Foundation</a> at <a href="http://www.eclipse.org/jetty/">http://www.eclipse.org/jetty</a>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="links">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<h2>examples ...</h2>
|
||||
|
@ -31,28 +36,34 @@ The project is 100% <a href="http://en.wikipedia.org/wiki/Open_source">Open Sour
|
|||
<li><a href="/async-rest/">Async Rest</a></li>
|
||||
<li><a href="/proxy/apidocs/">Transparent Proxy to Javadoc</a></li>
|
||||
<li><a href="/proxy/xref/">Transparent Proxy to Xref</a></li>
|
||||
<li><a href="/oldContextPath/">Redirected Context</a></li>
|
||||
<li><a href="/oldContextPath/">Redirected Context</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<h2>information ... </h2>
|
||||
<ul>
|
||||
<li><a href="http://www.eclipse.org/jetty/">Jetty @ Eclipse Home</a></li>
|
||||
<li><a href="http://wiki.eclipse.org/Jetty">Jetty @ Eclipse Doco</a></li>
|
||||
<li><a href="http://docs.codehaus.org/display/JETTY/Jetty+Powered">Jetty Powered</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<h2>getting help ...</h2>
|
||||
<ul>
|
||||
<li><a href="http://www.eclipse.org/jetty/mailinglists.php">Mailing lists @ eclipse</a></li>
|
||||
<li><a href="http://www.webtide.com/advice/">Developer Advice</a></li>
|
||||
<li><a href="http://www.webtide.com/development">Custom Development</a></li>
|
||||
<li><a href="http://www.webtide.com/support">Production support</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
</td>
|
||||
<td>
|
||||
<h2>information ...</h2>
|
||||
<ul>
|
||||
<li><a href="http://www.eclipse.org/jetty/">Jetty @ Eclipse Home</a></li>
|
||||
<li><a href="http://wiki.eclipse.org/Jetty">Jetty @ Eclipse Doco</a></li>
|
||||
<li><a
|
||||
href="http://docs.codehaus.org/display/JETTY/Jetty+Powered">Jetty Powered</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<h2>getting help ...</h2>
|
||||
<ul>
|
||||
<li><a href="http://www.eclipse.org/jetty/mailinglists.php">Mailing lists @ eclipse</a></li>
|
||||
<li><a href="http://www.webtide.com/advice/">Developer Advice</a></li>
|
||||
<li><a href="http://www.webtide.com/development">Custom Development</a></li>
|
||||
<li><a href="http://www.webtide.com/support">Production support</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id='blog'>
|
||||
<h1>Jetty Blog</h1>
|
||||
<iframe src="http://webtide.intalio.com/blog.jsp" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,6 +3,7 @@ BODY
|
|||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #FFFFFF;
|
||||
font-size: 10pt;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
img
|
||||
|
@ -11,6 +12,33 @@ img
|
|||
}
|
||||
|
||||
|
||||
div#header
|
||||
{
|
||||
clear: both;
|
||||
background-image: url('images/jetty-header.jpg');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
height:200px;
|
||||
border-bottom: 3px ridge #cccccc;
|
||||
border-right: 3px ridge #cccccc;
|
||||
border-top: 3px groove #cccccc;
|
||||
border-left: 3px groove #cccccc;
|
||||
width: 850px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
div#content
|
||||
{
|
||||
clear: both;
|
||||
font-size: 10pt;
|
||||
font-weight: normal;
|
||||
color: #666666;
|
||||
margin-top: 30px;
|
||||
width: 850px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
div#links table
|
||||
{
|
||||
|
@ -67,40 +95,23 @@ div#links h2
|
|||
}
|
||||
|
||||
|
||||
div#header
|
||||
|
||||
div#blog
|
||||
{
|
||||
clear: both;
|
||||
background-image: url('images/jetty-header.jpg');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
height:200px;
|
||||
border-bottom: 3px ridge #cccccc;
|
||||
border-right: 3px ridge #cccccc;
|
||||
border-top: 3px groove #cccccc;
|
||||
border-left: 3px groove #cccccc;
|
||||
margin-top: 20px;
|
||||
width: 850px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
|
||||
div#content
|
||||
div#blog iframe
|
||||
{
|
||||
clear: both;
|
||||
font-size: 10pt;
|
||||
font-weight: normal;
|
||||
color: #666666;
|
||||
margin-top: 30px;
|
||||
width: 850px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 100%;
|
||||
height:350px;
|
||||
border: 2px dotted #cccccc;
|
||||
}
|
||||
|
||||
div#content h1
|
||||
{
|
||||
font-size: 14pt;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
|
||||
div#footer
|
||||
{
|
||||
|
@ -113,6 +124,11 @@ div#footer
|
|||
|
||||
|
||||
|
||||
h1
|
||||
{
|
||||
font-size: 14pt;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
A:link
|
||||
{
|
||||
|
|
|
@ -100,6 +100,7 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
|
|||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
super.onClose();
|
||||
LOG.debug("onClose {}",this);
|
||||
_writeFlusher.onClose();
|
||||
_fillInterest.onClose();
|
||||
|
|
|
@ -95,6 +95,7 @@ public abstract class IdleTimeout
|
|||
// If we have a new timeout, then check and reschedule
|
||||
if (idleTimeout>0 && isOpen())
|
||||
_idleTask.run();
|
||||
|
||||
}
|
||||
|
||||
/** This method should be called when non-idle activity has taken place.
|
||||
|
@ -119,6 +120,13 @@ public abstract class IdleTimeout
|
|||
if (_idleTimeout>0)
|
||||
_idleTask.run();
|
||||
}
|
||||
|
||||
public void onClose()
|
||||
{
|
||||
Scheduler.Task oldTimeout = _timeout.getAndSet(null);
|
||||
if (oldTimeout != null)
|
||||
oldTimeout.cancel();
|
||||
}
|
||||
|
||||
protected void close()
|
||||
{
|
||||
|
|
|
@ -45,6 +45,7 @@ abstract public class WriteFlusher
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(WriteFlusher.class);
|
||||
private static final boolean DEBUG = LOG.isDebugEnabled(); // Easy for the compiler to remove the code if DEBUG==false
|
||||
private static final ByteBuffer[] EMPTY_BUFFERS = new ByteBuffer[0];
|
||||
private static final EnumMap<StateType, Set<StateType>> __stateTransitions = new EnumMap<>(StateType.class);
|
||||
private static final State __IDLE = new IdleState();
|
||||
private static final State __WRITING = new WritingState();
|
||||
|
@ -243,7 +244,7 @@ abstract public class WriteFlusher
|
|||
private PendingState(ByteBuffer[] buffers, Callback callback)
|
||||
{
|
||||
super(StateType.PENDING);
|
||||
_buffers = buffers;
|
||||
_buffers = compact(buffers);
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
|
@ -263,6 +264,44 @@ abstract public class WriteFlusher
|
|||
if (_callback!=null)
|
||||
_callback.succeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compacting the buffers is needed because the semantic of WriteFlusher is
|
||||
* to write the buffers and if the caller sees that the buffer is consumed,
|
||||
* then it can recycle it.
|
||||
* If we do not compact, then it is possible that we store a consumed buffer,
|
||||
* which is then recycled and refilled; when the WriteFlusher is invoked to
|
||||
* complete the write, it will write the refilled bytes, garbling the content.
|
||||
*
|
||||
* @param buffers the buffers to compact
|
||||
* @return the compacted buffers
|
||||
*/
|
||||
private ByteBuffer[] compact(ByteBuffer[] buffers)
|
||||
{
|
||||
int length = buffers.length;
|
||||
|
||||
// Just one element, no need to compact
|
||||
if (length < 2)
|
||||
return buffers;
|
||||
|
||||
// How many still have content ?
|
||||
int consumed = 0;
|
||||
while (consumed < length && BufferUtil.isEmpty(buffers[consumed]))
|
||||
++consumed;
|
||||
|
||||
// All of them still have content, no need to compact
|
||||
if (consumed == 0)
|
||||
return buffers;
|
||||
|
||||
// None has content, return empty
|
||||
if (consumed == length)
|
||||
return EMPTY_BUFFERS;
|
||||
|
||||
int newLength = length - consumed;
|
||||
ByteBuffer[] result = new ByteBuffer[newLength];
|
||||
System.arraycopy(buffers, consumed, result, 0, newLength);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -306,7 +345,7 @@ abstract public class WriteFlusher
|
|||
if (updateState(__WRITING,pending))
|
||||
onIncompleteFlushed();
|
||||
else
|
||||
fail(new PendingState(buffers, callback));
|
||||
fail(pending);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.WritePendingException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -54,16 +46,23 @@ import org.mockito.invocation.InvocationOnMock;
|
|||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WriteFlusherTest
|
||||
{
|
||||
@Mock
|
||||
private EndPoint _endPointMock;
|
||||
|
||||
private WriteFlusher _flusher;
|
||||
|
||||
private final AtomicBoolean _flushIncomplete = new AtomicBoolean(false);
|
||||
private final ExecutorService executor = Executors.newFixedThreadPool(16);
|
||||
@Mock
|
||||
private EndPoint _endPointMock;
|
||||
private WriteFlusher _flusher;
|
||||
private ByteArrayEndPoint _endp;
|
||||
|
||||
@Before
|
||||
|
@ -400,6 +399,34 @@ public class WriteFlusherTest
|
|||
assertThat("callback completed", callback.isDone(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPendingWriteDoesNotStoreConsumedBuffers() throws Exception
|
||||
{
|
||||
int toWrite = _endp.getOutput().capacity();
|
||||
byte[] chunk1 = new byte[toWrite / 2];
|
||||
Arrays.fill(chunk1, (byte)1);
|
||||
ByteBuffer buffer1 = ByteBuffer.wrap(chunk1);
|
||||
byte[] chunk2 = new byte[toWrite];
|
||||
Arrays.fill(chunk1, (byte)2);
|
||||
ByteBuffer buffer2 = ByteBuffer.wrap(chunk2);
|
||||
|
||||
_flusher.write(new Callback.Adapter(), buffer1, buffer2);
|
||||
assertTrue(_flushIncomplete.get());
|
||||
assertFalse(buffer1.hasRemaining());
|
||||
|
||||
// Reuse buffer1
|
||||
buffer1.clear();
|
||||
Arrays.fill(chunk1, (byte)3);
|
||||
int remaining1 = buffer1.remaining();
|
||||
|
||||
// Complete the write
|
||||
_endp.takeOutput();
|
||||
_flusher.completeWrite();
|
||||
|
||||
// Make sure buffer1 is unchanged
|
||||
assertEquals(remaining1, buffer1.remaining());
|
||||
}
|
||||
|
||||
private class ExposingStateCallback extends FutureCallback
|
||||
{
|
||||
private boolean failed = false;
|
||||
|
|
|
@ -622,27 +622,25 @@ public class ObjectMBean implements DynamicMBean
|
|||
boolean convert = false;
|
||||
|
||||
// determine if we should convert
|
||||
Class<?> returnType = method.getReturnType();
|
||||
Class<?> return_type = method.getReturnType();
|
||||
|
||||
if ( returnType.isArray() )
|
||||
// get the component type
|
||||
Class<?> component_type = return_type;
|
||||
while ( component_type.isArray() )
|
||||
{
|
||||
returnType = returnType.getComponentType();
|
||||
component_type = component_type.getComponentType();
|
||||
}
|
||||
|
||||
// Test to see if the returnType or any of its super classes are managed objects
|
||||
convert = isAnnotationPresent(returnType, ManagedObject.class);
|
||||
convert = isAnnotationPresent(component_type, ManagedObject.class);
|
||||
|
||||
String uName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
|
||||
Class<?> oClass = onMBean ? this.getClass() : _managed.getClass();
|
||||
|
||||
LOG.debug("defineAttribute {} {}:{}:{}:{}",name,onMBean,readonly,oClass,description);
|
||||
|
||||
Class<?> type = null;
|
||||
Method setter = null;
|
||||
|
||||
type = returnType;//method.getReturnType();
|
||||
|
||||
|
||||
// dig out a setter if one exists
|
||||
if (!readonly)
|
||||
{
|
||||
|
@ -667,7 +665,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
continue;
|
||||
}
|
||||
setter = methods[m];
|
||||
if ( !type.equals(methods[m].getParameterTypes()[0]))
|
||||
if ( !component_type.equals(methods[m].getParameterTypes()[0]))
|
||||
{
|
||||
LOG.warn("Type conflict for mbean attr {} in {}", name, oClass);
|
||||
continue;
|
||||
|
@ -685,8 +683,8 @@ public class ObjectMBean implements DynamicMBean
|
|||
continue;
|
||||
}
|
||||
setter = methods[m];
|
||||
if ( !type.equals(methods[m].getParameterTypes()[0]))
|
||||
{
|
||||
if ( !return_type.equals(methods[m].getParameterTypes()[0]))
|
||||
{
|
||||
LOG.warn("Type conflict for mbean attr {} in {}", name, oClass);
|
||||
continue;
|
||||
}
|
||||
|
@ -696,18 +694,18 @@ public class ObjectMBean implements DynamicMBean
|
|||
|
||||
if (convert)
|
||||
{
|
||||
if (type==null)
|
||||
if (component_type==null)
|
||||
{
|
||||
LOG.warn("No mbean type for {} on {}", name, _managed.getClass());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (type.isPrimitive() && !type.isArray())
|
||||
if (component_type.isPrimitive() && !component_type.isArray())
|
||||
{
|
||||
LOG.warn("Cannot convert mbean primative {}", name);
|
||||
return null;
|
||||
}
|
||||
LOG.debug("passed convert checks {} for type {}", name, type);
|
||||
LOG.debug("passed convert checks {} for type {}", name, component_type);
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -721,7 +719,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
{
|
||||
_convert.add(name);
|
||||
|
||||
if (type.isArray())
|
||||
if (component_type.isArray())
|
||||
{
|
||||
info= new MBeanAttributeInfo(name,OBJECT_NAME_ARRAY_CLASS,description,true,setter!=null,method.getName().startsWith("is"));
|
||||
}
|
||||
|
|
|
@ -94,6 +94,9 @@ public class ServiceContextProvider extends AbstractContextProvider implements S
|
|||
if (context == null || serviceRef == null)
|
||||
return false;
|
||||
|
||||
if (context instanceof org.eclipse.jetty.webapp.WebAppContext)
|
||||
return false; //the ServiceWebAppProvider will deploy it
|
||||
|
||||
String watermark = (String)serviceRef.getProperty(OSGiWebappConstants.WATERMARK);
|
||||
if (watermark != null && !"".equals(watermark))
|
||||
return false; //this service represents a contexthandler that has already been registered as a service by another of our deployers
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -52,8 +51,8 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
|
||||
/**
|
||||
* <p>Implementation of a {@link Handler} that supports HTTP CONNECT.</p>
|
||||
|
@ -163,7 +162,7 @@ public class ConnectHandler extends HandlerWrapper
|
|||
}
|
||||
if (scheduler == null)
|
||||
{
|
||||
setScheduler(new TimerScheduler());
|
||||
setScheduler(new ScheduledExecutorScheduler());
|
||||
addBean(getScheduler());
|
||||
}
|
||||
if (bufferPool == null)
|
||||
|
|
|
@ -604,7 +604,7 @@ public class ProxyServlet extends HttpServlet
|
|||
if (!_prefix.startsWith("/"))
|
||||
throw new UnavailableException("Init parameter 'prefix' parameter must start with a '/'.");
|
||||
|
||||
_log.info(config.getServletName() + " @ " + _prefix + " to " + _proxyTo);
|
||||
_log.debug(config.getServletName() + " @ " + _prefix + " to " + _proxyTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<!-- java -jar start.jar -? -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure a Jetty Server instance with an ID "Server" -->
|
||||
<!-- Other configuration files may also configure the "Server" -->
|
||||
<!-- ID, in which case they are adding configuration to the same -->
|
||||
|
@ -49,13 +49,13 @@
|
|||
<Set name="detailedDump">false</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Add shared Scheduler instance -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.util.thread.TimerScheduler"/>
|
||||
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
|
@ -82,14 +82,14 @@
|
|||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
|
||||
<!-- Uncomment to enable handling of X-Forwarded- style headers
|
||||
|
||||
<!-- Uncomment to enable handling of X-Forwarded- style headers
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
-->
|
||||
</New>
|
||||
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set the default handler structure for the Server -->
|
||||
|
@ -99,7 +99,7 @@
|
|||
<!-- DefaultHandler, which handles any requests not handled by -->
|
||||
<!-- the context handlers. -->
|
||||
<!-- Other handlers may be added to the "Handlers" collection, -->
|
||||
<!-- for example the jetty-requestlog.xml file adds the -->
|
||||
<!-- for example the jetty-requestlog.xml file adds the -->
|
||||
<!-- RequestLogHandler after the default handler -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="handler">
|
||||
|
|
|
@ -48,8 +48,8 @@ import org.eclipse.jetty.util.component.Dumpable;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
|
||||
/**
|
||||
* <p>An abstract implementation of {@link Connector} that provides a {@link ConnectionFactory} mechanism
|
||||
|
@ -63,7 +63,7 @@ import org.eclipse.jetty.util.thread.TimerScheduler;
|
|||
* </li>
|
||||
* <li>The {@link Scheduler} service is used to monitor the idle timeouts of all connections and is also made available
|
||||
* to the connections to time such things as asynchronous request timeouts. The default is to use a new
|
||||
* {@link TimerScheduler} instance.
|
||||
* {@link ScheduledExecutorScheduler} instance.
|
||||
* </li>
|
||||
* <li>The {@link ByteBufferPool} service is made available to all connections to be used to acquire and release
|
||||
* {@link ByteBuffer} instances from a pool. The default is to use a new {@link ArrayByteBufferPool} instance.
|
||||
|
@ -151,12 +151,12 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
private long _idleTimeout = 30000;
|
||||
private String _defaultProtocol;
|
||||
private ConnectionFactory _defaultConnectionFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param server The server this connector will be added to. Must not be null.
|
||||
* @param executor An executor for this connector or null to use the servers executor
|
||||
* @param scheduler A scheduler for this connector or null to either a {@link Scheduler} set as a server bean or if none set, then a new {@link TimerScheduler} instance.
|
||||
* @param scheduler A scheduler for this connector or null to either a {@link Scheduler} set as a server bean or if none set, then a new {@link ScheduledExecutorScheduler} instance.
|
||||
* @param pool A buffer pool for this connector or null to either a {@link ByteBufferPool} set as a server bean or none set, the new {@link ArrayByteBufferPool} instance.
|
||||
* @param acceptors the number of acceptor threads to use, or 0 for a default value.
|
||||
* @param factories The Connection Factories to use.
|
||||
|
@ -173,7 +173,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
_executor=executor!=null?executor:_server.getThreadPool();
|
||||
if (scheduler==null)
|
||||
scheduler=_server.getBean(Scheduler.class);
|
||||
_scheduler=scheduler!=null?scheduler:new TimerScheduler();
|
||||
_scheduler=scheduler!=null?scheduler:new ScheduledExecutorScheduler();
|
||||
if (pool==null)
|
||||
pool=_server.getBean(ByteBufferPool.class);
|
||||
_byteBufferPool = pool!=null?pool:new ArrayByteBufferPool();
|
||||
|
@ -479,9 +479,9 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// protected void connectionOpened(Connection connection)
|
||||
// {
|
||||
// _stats.connectionOpened();
|
||||
|
@ -512,7 +512,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
{
|
||||
_endpoints.add(endp);
|
||||
}
|
||||
|
||||
|
||||
protected void onEndPointClosed(EndPoint endp)
|
||||
{
|
||||
_endpoints.remove(endp);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -35,6 +36,15 @@ import javax.servlet.http.HttpServletResponse;
|
|||
*/
|
||||
public interface Authentication
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class Failed extends QuietServletException
|
||||
{
|
||||
public Failed(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** A successful Authentication with User information.
|
||||
*/
|
||||
|
|
|
@ -32,9 +32,9 @@ import org.eclipse.jetty.util.annotation.Name;
|
|||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -42,7 +42,7 @@ import org.eclipse.jetty.util.thread.TimerScheduler;
|
|||
* <p>An instance of this class will monitor all the connectors of a server (or a set of connectors
|
||||
* configured with {@link #setMonitoredConnectors(Collection)}) for a low resources state.
|
||||
* Low resources can be detected by:<ul>
|
||||
* <li>{@link ThreadPool#isLowOnThreads()} if {@link Connector#getExecutor()} is
|
||||
* <li>{@link ThreadPool#isLowOnThreads()} if {@link Connector#getExecutor()} is
|
||||
* an instance of {@link ThreadPool} and {@link #setMonitorThreads(boolean)} is true.<li>
|
||||
* <li>If {@link #setMaxMemory(long)} is non zero then low resources is detected if the JVMs
|
||||
* {@link Runtime} instance has {@link Runtime#totalMemory()} minus {@link Runtime#freeMemory()}
|
||||
|
@ -51,11 +51,11 @@ import org.eclipse.jetty.util.thread.TimerScheduler;
|
|||
* of connections exceeds {@link #getMaxConnections()}</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>Once low resources state is detected, the cause is logged and all existing connections returned
|
||||
* by {@link Connector#getConnectedEndPoints()} have {@link EndPoint#setIdleTimeout(long)} set
|
||||
* to {@link #getLowResourcesIdleTimeout()}. New connections are not affected, however if the low
|
||||
* resources state persists for more than {@link #getMaxLowResourcesTime()}, then the
|
||||
* {@link #getLowResourcesIdleTimeout()} to all connections again. Once the low resources state is
|
||||
* <p>Once low resources state is detected, the cause is logged and all existing connections returned
|
||||
* by {@link Connector#getConnectedEndPoints()} have {@link EndPoint#setIdleTimeout(long)} set
|
||||
* to {@link #getLowResourcesIdleTimeout()}. New connections are not affected, however if the low
|
||||
* resources state persists for more than {@link #getMaxLowResourcesTime()}, then the
|
||||
* {@link #getLowResourcesIdleTimeout()} to all connections again. Once the low resources state is
|
||||
* cleared, the idle timeout is reset to the connector default given by {@link Connector#getIdleTimeout()}.
|
||||
* </p>
|
||||
*/
|
||||
|
@ -76,44 +76,44 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
private String _cause;
|
||||
private String _reasons;
|
||||
private long _lowStarted;
|
||||
|
||||
|
||||
|
||||
|
||||
private final Runnable _monitor = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
{
|
||||
if (isRunning())
|
||||
{
|
||||
monitor();
|
||||
_scheduler.schedule(_monitor,_period,TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public LowResourceMonitor(@Name("server") Server server)
|
||||
{
|
||||
_server=server;
|
||||
}
|
||||
|
||||
|
||||
@ManagedAttribute("Are the monitored connectors low on resources?")
|
||||
public boolean isLowOnResources()
|
||||
{
|
||||
return _low.get();
|
||||
}
|
||||
|
||||
|
||||
@ManagedAttribute("The reason(s) the monitored connectors are low on resources")
|
||||
public String getLowResourcesReasons()
|
||||
{
|
||||
return _reasons;
|
||||
}
|
||||
|
||||
|
||||
@ManagedAttribute("Get the timestamp in ms since epoch that low resources state started")
|
||||
public long getLowResourcesStarted()
|
||||
{
|
||||
return _lowStarted;
|
||||
}
|
||||
|
||||
|
||||
@ManagedAttribute("The monitored connectors. If null then all server connectors are monitored")
|
||||
public Collection<Connector> getMonitoredConnectors()
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
}
|
||||
|
||||
/**
|
||||
* @param periodMS The period in ms to monitor for low resources
|
||||
* @param periodMS The period in ms to monitor for low resources
|
||||
*/
|
||||
public void setPeriod(int periodMS)
|
||||
{
|
||||
|
@ -154,8 +154,8 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
}
|
||||
|
||||
/**
|
||||
* @param monitorThreads If true, check connectors executors to see if they are
|
||||
* {@link ThreadPool} instances that are low on threads.
|
||||
* @param monitorThreads If true, check connectors executors to see if they are
|
||||
* {@link ThreadPool} instances that are low on threads.
|
||||
*/
|
||||
public void setMonitorThreads(boolean monitorThreads)
|
||||
{
|
||||
|
@ -222,14 +222,14 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
protected void doStart() throws Exception
|
||||
{
|
||||
_scheduler = _server.getBean(Scheduler.class);
|
||||
|
||||
|
||||
if (_scheduler==null)
|
||||
{
|
||||
_scheduler=new LRMScheduler();
|
||||
_scheduler.start();
|
||||
}
|
||||
super.doStart();
|
||||
|
||||
|
||||
_scheduler.schedule(_monitor,_period,TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
@ -240,24 +240,24 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
_scheduler.stop();
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
|
||||
protected Connector[] getMonitoredOrServerConnectors()
|
||||
{
|
||||
if (_monitoredConnectors!=null && _monitoredConnectors.length>0)
|
||||
return _monitoredConnectors;
|
||||
return _server.getConnectors();
|
||||
}
|
||||
|
||||
|
||||
protected void monitor()
|
||||
{
|
||||
String reasons=null;
|
||||
String cause="";
|
||||
int connections=0;
|
||||
|
||||
|
||||
for(Connector connector : getMonitoredOrServerConnectors())
|
||||
{
|
||||
connections+=connector.getConnectedEndPoints().size();
|
||||
|
||||
|
||||
Executor executor = connector.getExecutor();
|
||||
if (executor instanceof ThreadPool)
|
||||
{
|
||||
|
@ -269,21 +269,21 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_maxConnections>0 && connections>_maxConnections)
|
||||
{
|
||||
reasons=low(reasons,"Max Connections exceeded: "+connections+">"+_maxConnections);
|
||||
cause+="C";
|
||||
}
|
||||
|
||||
|
||||
long memory=Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
|
||||
if (_maxMemory>0 && memory>_maxMemory)
|
||||
{
|
||||
reasons=low(reasons,"Max memory exceeded: "+memory+">"+_maxMemory);
|
||||
cause+="M";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (reasons!=null)
|
||||
{
|
||||
// Log the reasons if there is any change in the cause
|
||||
|
@ -292,7 +292,7 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
LOG.warn("Low Resources: {}",reasons);
|
||||
_cause=cause;
|
||||
}
|
||||
|
||||
|
||||
// Enter low resources state?
|
||||
if (_low.compareAndSet(false,true))
|
||||
{
|
||||
|
@ -300,12 +300,12 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
_lowStarted=System.currentTimeMillis();
|
||||
setLowResources();
|
||||
}
|
||||
|
||||
|
||||
// Too long in low resources state?
|
||||
if (_maxLowResourcesTime>0 && (System.currentTimeMillis()-_lowStarted)>_maxLowResourcesTime)
|
||||
setLowResources();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (_low.compareAndSet(true,false))
|
||||
{
|
||||
|
@ -316,7 +316,7 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setLowResources()
|
||||
{
|
||||
for(Connector connector : getMonitoredOrServerConnectors())
|
||||
|
@ -325,7 +325,7 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
endPoint.setIdleTimeout(_lowResourcesIdleTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void clearLowResources()
|
||||
{
|
||||
for(Connector connector : getMonitoredOrServerConnectors())
|
||||
|
@ -334,16 +334,16 @@ public class LowResourceMonitor extends AbstractLifeCycle
|
|||
endPoint.setIdleTimeout(connector.getIdleTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String low(String reasons, String newReason)
|
||||
{
|
||||
if (reasons==null)
|
||||
return newReason;
|
||||
return reasons+", "+newReason;
|
||||
}
|
||||
|
||||
|
||||
private static class LRMScheduler extends TimerScheduler
|
||||
|
||||
|
||||
private static class LRMScheduler extends ScheduledExecutorScheduler
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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.server;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** A ServletException that is logged less verbosely than
|
||||
* a normal ServletException.
|
||||
* <p>
|
||||
* Used for container generated exceptions that need only a message rather
|
||||
* than a stack trace.
|
||||
* </p>
|
||||
*/
|
||||
public class QuietServletException extends ServletException
|
||||
{
|
||||
public QuietServletException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public QuietServletException(String message, Throwable rootCause)
|
||||
{
|
||||
super(message,rootCause);
|
||||
}
|
||||
|
||||
public QuietServletException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public QuietServletException(Throwable rootCause)
|
||||
{
|
||||
super(rootCause);
|
||||
}
|
||||
}
|
|
@ -2096,11 +2096,11 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
_authentication=((Authentication.Deferred)_authentication).login(username,password,this);
|
||||
if (_authentication == null)
|
||||
throw new ServletException("Authentication failed for "+username+" in "+_authentication);
|
||||
throw new Authentication.Failed("Authentication failed for username '"+username+"'");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServletException("Already authenticated as "+_authentication);
|
||||
throw new Authentication.Failed("Authenticated failed for username '"+username+"'. Already authenticated as "+_authentication);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2097,6 +2097,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
if (!_enabled)
|
||||
throw new UnsupportedOperationException();
|
||||
ContextHandler.this.addEventListener(t);
|
||||
ContextHandler.this.addProgrammaticListener(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -185,7 +185,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
throw new ServletException("TEST handler exception");
|
||||
throw new QuietServletException("TEST handler exception");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.GenericServlet;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Dispatcher;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Servlet handling JSP Property Group mappings
|
||||
* <p>
|
||||
* This servlet is mapped to by any URL pattern for a JSP property group.
|
||||
* Resources handled by this servlet that are not directories will be passed
|
||||
* directly to the JSP servlet. Resources that are directories will be
|
||||
* passed directly to the default servlet.
|
||||
*/
|
||||
public class JspPropertyGroupServlet extends GenericServlet
|
||||
{
|
||||
private static final long serialVersionUID = 3681783214726776945L;
|
||||
|
||||
public final static String NAME = "__org.eclipse.jetty.servlet.JspPropertyGroupServlet__";
|
||||
private final ServletHandler _servletHandler;
|
||||
private final ContextHandler _contextHandler;
|
||||
private ServletHolder _dftServlet;
|
||||
private ServletHolder _jspServlet;
|
||||
private boolean _starJspMapped;
|
||||
|
||||
public JspPropertyGroupServlet(ContextHandler context, ServletHandler servletHandler)
|
||||
{
|
||||
_contextHandler=context;
|
||||
_servletHandler=servletHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException
|
||||
{
|
||||
String jsp_name = "jsp";
|
||||
ServletMapping servlet_mapping =_servletHandler.getServletMapping("*.jsp");
|
||||
if (servlet_mapping!=null)
|
||||
{
|
||||
_starJspMapped=true;
|
||||
|
||||
//now find the jsp servlet, ignoring the mapping that is for ourself
|
||||
ServletMapping[] mappings = _servletHandler.getServletMappings();
|
||||
for (ServletMapping m:mappings)
|
||||
{
|
||||
String[] paths = m.getPathSpecs();
|
||||
if (paths!=null)
|
||||
{
|
||||
for (String path:paths)
|
||||
{
|
||||
if ("*.jsp".equals(path) && !NAME.equals(m.getServletName()))
|
||||
servlet_mapping = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsp_name=servlet_mapping.getServletName();
|
||||
}
|
||||
_jspServlet=_servletHandler.getServlet(jsp_name);
|
||||
|
||||
String dft_name="default";
|
||||
ServletMapping default_mapping=_servletHandler.getServletMapping("/");
|
||||
if (default_mapping!=null)
|
||||
dft_name=default_mapping.getServletName();
|
||||
_dftServlet=_servletHandler.getServlet(dft_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
|
||||
{
|
||||
Request request=(req instanceof Request)?(Request)req:HttpConnection.getCurrentConnection().getHttpChannel().getRequest();
|
||||
|
||||
String servletPath=null;
|
||||
String pathInfo=null;
|
||||
if (request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI)!=null)
|
||||
{
|
||||
servletPath=(String)request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH);
|
||||
pathInfo=(String)request.getAttribute(Dispatcher.INCLUDE_PATH_INFO);
|
||||
if (servletPath==null)
|
||||
{
|
||||
servletPath=request.getServletPath();
|
||||
pathInfo=request.getPathInfo();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
servletPath = request.getServletPath();
|
||||
pathInfo = request.getPathInfo();
|
||||
}
|
||||
|
||||
String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
|
||||
|
||||
if (pathInContext.endsWith("/"))
|
||||
{
|
||||
_dftServlet.getServlet().service(req,res);
|
||||
}
|
||||
else if (_starJspMapped && pathInContext.toLowerCase().endsWith(".jsp"))
|
||||
{
|
||||
_jspServlet.getServlet().service(req,res);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Resource resource = _contextHandler.getResource(pathInContext);
|
||||
if (resource!=null && resource.isDirectory())
|
||||
_dftServlet.getServlet().service(req,res);
|
||||
else
|
||||
_jspServlet.getServlet().service(req,res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -54,6 +54,7 @@ import org.eclipse.jetty.security.IdentityService;
|
|||
import org.eclipse.jetty.security.SecurityHandler;
|
||||
import org.eclipse.jetty.server.Dispatcher;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.QuietServletException;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.ServletRequestHttpWrapper;
|
||||
import org.eclipse.jetty.server.ServletResponseHttpWrapper;
|
||||
|
@ -476,10 +477,20 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
else if (th instanceof ServletException)
|
||||
{
|
||||
LOG.warn(th);
|
||||
Throwable cause=((ServletException)th).getRootCause();
|
||||
if (cause!=null)
|
||||
if (th instanceof QuietServletException)
|
||||
{
|
||||
LOG.debug(th);
|
||||
LOG.warn(th.toString());
|
||||
}
|
||||
else
|
||||
LOG.warn(th);
|
||||
while (th instanceof ServletException)
|
||||
{
|
||||
Throwable cause=((ServletException)th).getRootCause();
|
||||
if (cause==null)
|
||||
break;
|
||||
th=cause;
|
||||
}
|
||||
}
|
||||
// handle or log exception
|
||||
else if (th instanceof EofException)
|
||||
|
@ -1392,6 +1403,7 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
|
@ -1443,6 +1455,7 @@ public class ServletHandler extends ScopedHandler
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (_filterHolder!=null)
|
||||
|
@ -1471,6 +1484,7 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
|
@ -1524,6 +1538,7 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
@ -1572,5 +1587,4 @@ public class ServletHandler extends ScopedHandler
|
|||
_contextHandler.destroyFilter(filter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -84,6 +84,12 @@
|
|||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jmx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,86 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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.servlets;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import javax.management.Attribute;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoSFilterJMXTest
|
||||
{
|
||||
@Test
|
||||
public void testDoSFilterJMX() throws Exception
|
||||
{
|
||||
Server server = new Server();
|
||||
Connector connector = new ServerConnector(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
|
||||
DoSFilter filter = new DoSFilter();
|
||||
FilterHolder holder = new FilterHolder(filter);
|
||||
String name = "dos";
|
||||
holder.setName(name);
|
||||
holder.setInitParameter(DoSFilter.MANAGED_ATTR_INIT_PARAM, "true");
|
||||
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||
context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
|
||||
|
||||
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
|
||||
server.addBean(mbeanContainer);
|
||||
|
||||
server.start();
|
||||
|
||||
String domain = DoSFilter.class.getPackage().getName();
|
||||
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null);
|
||||
Assert.assertEquals(1, mbeanNames.size());
|
||||
ObjectName objectName = mbeanNames.iterator().next();
|
||||
|
||||
boolean value = (Boolean)mbeanServer.getAttribute(objectName, "enabled");
|
||||
mbeanServer.setAttribute(objectName, new Attribute("enabled", !value));
|
||||
Assert.assertEquals(!value, filter.isEnabled());
|
||||
|
||||
String whitelist = (String)mbeanServer.getAttribute(objectName, "whitelist");
|
||||
String address = "127.0.0.1";
|
||||
Assert.assertFalse(whitelist.contains(address));
|
||||
boolean result = (Boolean)mbeanServer.invoke(objectName, "addWhitelistAddress", new Object[]{address}, new String[]{String.class.getName()});
|
||||
Assert.assertTrue(result);
|
||||
whitelist = (String)mbeanServer.getAttribute(objectName, "whitelist");
|
||||
Assert.assertTrue(whitelist.contains(address));
|
||||
|
||||
result = (Boolean)mbeanServer.invoke(objectName, "removeWhitelistAddress", new Object[]{address}, new String[]{String.class.getName()});
|
||||
Assert.assertTrue(result);
|
||||
whitelist = (String)mbeanServer.getAttribute(objectName, "whitelist");
|
||||
Assert.assertFalse(whitelist.contains(address));
|
||||
|
||||
server.stop();
|
||||
}
|
||||
}
|
|
@ -18,18 +18,21 @@
|
|||
|
||||
package org.eclipse.jetty.servlets;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.servlets.DoSFilter.RateTracker;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DoSFilterTest extends AbstractDoSFilterTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(DoSFilterTest.class);
|
||||
|
@ -70,6 +73,21 @@ public class DoSFilterTest extends AbstractDoSFilterTest
|
|||
assertFalse("Should not exceed as we sleep 300s for each hit and thus do less than 4 hits/s",exceeded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhitelist() throws Exception
|
||||
{
|
||||
DoSFilter filter = new DoSFilter();
|
||||
List<String> whitelist = new ArrayList<String>();
|
||||
whitelist.add("192.168.0.1");
|
||||
whitelist.add("10.0.0.0/8");
|
||||
Assert.assertTrue(filter.checkWhitelist(whitelist, "192.168.0.1"));
|
||||
Assert.assertFalse(filter.checkWhitelist(whitelist, "192.168.0.2"));
|
||||
Assert.assertFalse(filter.checkWhitelist(whitelist, "11.12.13.14"));
|
||||
Assert.assertTrue(filter.checkWhitelist(whitelist, "10.11.12.13"));
|
||||
Assert.assertTrue(filter.checkWhitelist(whitelist, "10.0.0.0"));
|
||||
Assert.assertFalse(filter.checkWhitelist(whitelist, "0.0.0.0"));
|
||||
}
|
||||
|
||||
private boolean hitRateTracker(DoSFilter doSFilter, int sleep) throws InterruptedException
|
||||
{
|
||||
boolean exceeded = false;
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.Queue;
|
|||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.net.ssl.SSLEngine;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
|
@ -50,8 +49,8 @@ import org.eclipse.jetty.util.FuturePromise;
|
|||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
|
||||
public class SPDYClient
|
||||
{
|
||||
|
@ -202,7 +201,7 @@ public class SPDYClient
|
|||
addBean(executor);
|
||||
|
||||
if (scheduler == null)
|
||||
scheduler = new TimerScheduler();
|
||||
scheduler = new ScheduledExecutorScheduler();
|
||||
this.scheduler = scheduler;
|
||||
addBean(scheduler);
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
|||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.FilterMapping;
|
||||
import org.eclipse.jetty.servlet.Holder;
|
||||
import org.eclipse.jetty.servlet.JspPropertyGroupServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler.JspConfig;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler.JspPropertyGroup;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler.TagLib;
|
||||
|
@ -1336,21 +1339,18 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
|
||||
if (paths.size() > 0)
|
||||
{
|
||||
String jspName = "jsp";
|
||||
Map.Entry entry = context.getServletHandler().getHolderEntry("test.jsp");
|
||||
if (entry != null)
|
||||
ServletHandler handler = context.getServletHandler();
|
||||
ServletHolder jsp_pg_servlet = handler.getServlet(JspPropertyGroupServlet.NAME);
|
||||
if (jsp_pg_servlet==null)
|
||||
{
|
||||
ServletHolder holder = (ServletHolder) entry.getValue();
|
||||
jspName = holder.getName();
|
||||
jsp_pg_servlet=new ServletHolder(JspPropertyGroupServlet.NAME,new JspPropertyGroupServlet(context,handler));
|
||||
handler.addServlet(jsp_pg_servlet);
|
||||
}
|
||||
|
||||
if (jspName != null)
|
||||
{
|
||||
ServletMapping mapping = new ServletMapping();
|
||||
mapping.setServletName(jspName);
|
||||
mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
|
||||
context.getServletHandler().addServletMapping(mapping);
|
||||
}
|
||||
ServletMapping mapping = new ServletMapping();
|
||||
mapping.setServletName(JspPropertyGroupServlet.NAME);
|
||||
mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
|
||||
context.getServletHandler().addServletMapping(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -459,7 +459,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
if (web_app.getFile()!=null && web_app.getFile().isDirectory())
|
||||
{
|
||||
// Copy directory
|
||||
LOG.info("Copy " + web_app + " to " + extractedWebAppDir);
|
||||
LOG.debug("Copy " + web_app + " to " + extractedWebAppDir);
|
||||
web_app.copyTo(extractedWebAppDir);
|
||||
}
|
||||
else
|
||||
|
@ -473,7 +473,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
//it hasn't been extracted before so extract it
|
||||
extractionLock.createNewFile();
|
||||
extractedWebAppDir.mkdir();
|
||||
LOG.info("Extract " + web_app + " to " + extractedWebAppDir);
|
||||
LOG.debug("Extract " + web_app + " to " + extractedWebAppDir);
|
||||
Resource jar_web_app = JarResource.newJarResource(web_app);
|
||||
jar_web_app.copyTo(extractedWebAppDir);
|
||||
extractionLock.delete();
|
||||
|
@ -486,7 +486,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
extractionLock.createNewFile();
|
||||
IO.delete(extractedWebAppDir);
|
||||
extractedWebAppDir.mkdir();
|
||||
LOG.info("Extract " + web_app + " to " + extractedWebAppDir);
|
||||
LOG.debug("Extract " + web_app + " to " + extractedWebAppDir);
|
||||
Resource jar_web_app = JarResource.newJarResource(web_app);
|
||||
jar_web_app.copyTo(extractedWebAppDir);
|
||||
extractionLock.delete();
|
||||
|
@ -530,7 +530,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
IO.delete(webInfLibDir);
|
||||
webInfLibDir.mkdir();
|
||||
|
||||
LOG.info("Copying WEB-INF/lib " + web_inf_lib + " to " + webInfLibDir);
|
||||
LOG.debug("Copying WEB-INF/lib " + web_inf_lib + " to " + webInfLibDir);
|
||||
web_inf_lib.copyTo(webInfLibDir);
|
||||
}
|
||||
|
||||
|
@ -541,7 +541,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
if (webInfClassesDir.exists())
|
||||
IO.delete(webInfClassesDir);
|
||||
webInfClassesDir.mkdir();
|
||||
LOG.info("Copying WEB-INF/classes from "+web_inf_classes+" to "+webInfClassesDir.getAbsolutePath());
|
||||
LOG.debug("Copying WEB-INF/classes from "+web_inf_classes+" to "+webInfClassesDir.getAbsolutePath());
|
||||
web_inf_classes.copyTo(webInfClassesDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,10 +93,7 @@ public class WebSocketMinVersionTest
|
|||
}
|
||||
catch(IllegalStateException e) {
|
||||
String respHeader = e.getMessage();
|
||||
Assert.assertThat("Response Header", respHeader, allOf(
|
||||
containsString("HTTP/1.1 400 Unsupported"),
|
||||
containsString("minVersion [8]"),
|
||||
containsString("[13, 8]")));
|
||||
Assert.assertThat("Response Header", respHeader, containsString("HTTP/1.1 400 Unsupported websocket version specification"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ public class HttpResponseHeaderParser
|
|||
if (parseHeader(line))
|
||||
{
|
||||
// Finished parsing entire header
|
||||
ByteBuffer copy = ByteBuffer.allocateDirect(buf.remaining());
|
||||
ByteBuffer copy = ByteBuffer.allocate(buf.remaining());
|
||||
BufferUtil.put(buf,copy);
|
||||
BufferUtil.flipToFlush(copy,0);
|
||||
this.response.setRemainingBuffer(copy);
|
||||
|
|
|
@ -117,7 +117,7 @@ public class UpgradeConnection extends AbstractConnection
|
|||
@Override
|
||||
public void onFillable()
|
||||
{
|
||||
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true);
|
||||
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),false);
|
||||
BufferUtil.clear(buffer);
|
||||
boolean readMore = false;
|
||||
try
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ServerReadThread extends Thread
|
|||
public void run()
|
||||
{
|
||||
ByteBufferPool bufferPool = conn.getBufferPool();
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,true);
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,false);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
int len = 0;
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.nio.ByteBuffer;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
|
||||
|
@ -104,7 +103,7 @@ public class TomcatServerQuirksTest
|
|||
|
||||
// Have server write frame.
|
||||
int length = bufferSize / 2;
|
||||
ByteBuffer serverFrame = ByteBuffer.allocateDirect(bufferSize);
|
||||
ByteBuffer serverFrame = ByteBuffer.allocate(bufferSize);
|
||||
serverFrame.put((byte)(0x80 | 0x01)); // FIN + TEXT
|
||||
serverFrame.put((byte)0x7E); // No MASK and 2 bytes length
|
||||
serverFrame.put((byte)(length >> 8)); // first length byte
|
||||
|
@ -114,7 +113,7 @@ public class TomcatServerQuirksTest
|
|||
serverFrame.put((byte)'x');
|
||||
}
|
||||
serverFrame.flip();
|
||||
byte buf[] = BufferUtil.toArray(serverFrame);
|
||||
byte buf[] = serverFrame.array();
|
||||
socket.write(buf,0,buf.length);
|
||||
socket.flush();
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ public class BlockheadServer
|
|||
LOG.debug("Read: waiting for {} frame(s) from server",expectedCount);
|
||||
int startCount = incomingFrames.size();
|
||||
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,true);
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,false);
|
||||
BufferUtil.clearToFill(buf);
|
||||
try
|
||||
{
|
||||
|
@ -403,7 +403,7 @@ public class BlockheadServer
|
|||
{
|
||||
LOG.debug("Entering echo thread");
|
||||
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,true);
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,false);
|
||||
BufferUtil.clearToFill(buf);
|
||||
long readBytes = 0;
|
||||
try
|
||||
|
|
|
@ -64,7 +64,7 @@ public class HttpResponseHeaderParserTest
|
|||
expected.add("");
|
||||
|
||||
// Prepare Buffer
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(512);
|
||||
ByteBuffer buf = ByteBuffer.allocate(512);
|
||||
for (String line : expected)
|
||||
{
|
||||
appendUtf8(buf,line + "\r\n");
|
||||
|
@ -104,7 +104,7 @@ public class HttpResponseHeaderParserTest
|
|||
expected.add("");
|
||||
|
||||
// Prepare Buffer
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(512);
|
||||
ByteBuffer buf = ByteBuffer.allocate(512);
|
||||
for (String line : expected)
|
||||
{
|
||||
appendUtf8(buf,line + "\r\n");
|
||||
|
|
|
@ -222,7 +222,7 @@ public class Generator
|
|||
/*
|
||||
* prepare the byte buffer to put frame into
|
||||
*/
|
||||
ByteBuffer buffer = bufferPool.acquire(windowSize,true);
|
||||
ByteBuffer buffer = bufferPool.acquire(windowSize,false);
|
||||
BufferUtil.clearToFill(buffer);
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
|
|
|
@ -73,6 +73,12 @@ public interface LogicalConnection extends OutgoingFrames, SuspendToken
|
|||
*/
|
||||
InetSocketAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
|
||||
* @return the idle timeout in milliseconds
|
||||
*/
|
||||
long getMaxIdleTimeout();
|
||||
|
||||
/**
|
||||
* The policy that the connection is running under.
|
||||
* @return the policy for the connection
|
||||
|
@ -109,6 +115,14 @@ public interface LogicalConnection extends OutgoingFrames, SuspendToken
|
|||
*/
|
||||
boolean isReading();
|
||||
|
||||
/**
|
||||
* Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
|
||||
*
|
||||
* @param ms
|
||||
* the number of milliseconds of idle timeout
|
||||
*/
|
||||
void setMaxIdleTimeout(long ms);
|
||||
|
||||
/**
|
||||
* Set where the connection should send the incoming frames to.
|
||||
* <p>
|
||||
|
|
|
@ -553,7 +553,7 @@ public class Parser
|
|||
if (payload == null)
|
||||
{
|
||||
frame.assertValid();
|
||||
payload = bufferPool.acquire(payloadLength,true);
|
||||
payload = bufferPool.acquire(payloadLength,false);
|
||||
BufferUtil.clearToFill(payload);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
|||
private ExtensionFactory extensionFactory;
|
||||
private long maximumMessageSize;
|
||||
private String protocolVersion;
|
||||
private long timeout;
|
||||
private Map<String, String[]> parameterMap = new HashMap<>();
|
||||
private WebSocketRemoteEndpoint remote;
|
||||
private IncomingFrames incomingHandler;
|
||||
|
@ -165,12 +164,12 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
|||
}
|
||||
|
||||
/**
|
||||
* The idle timeout in seconds
|
||||
* The idle timeout in milliseconds
|
||||
*/
|
||||
@Override
|
||||
public long getIdleTimeout()
|
||||
{
|
||||
return timeout;
|
||||
return connection.getMaxIdleTimeout();
|
||||
}
|
||||
|
||||
@ManagedAttribute(readonly = true)
|
||||
|
@ -320,12 +319,12 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the timeout in seconds
|
||||
* Set the timeout in milliseconds
|
||||
*/
|
||||
@Override
|
||||
public void setIdleTimeout(long seconds)
|
||||
public void setIdleTimeout(long ms)
|
||||
{
|
||||
this.timeout = seconds;
|
||||
connection.setMaxIdleTimeout(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -83,7 +83,7 @@ public class DeflateCompressionMethod implements CompressionMethod
|
|||
public ByteBuffer process()
|
||||
{
|
||||
// prepare the output buffer
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(bufferSize);
|
||||
ByteBuffer buf = ByteBuffer.allocate(bufferSize);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
while (!deflater.finished())
|
||||
|
|
|
@ -111,6 +111,13 @@ public class MuxChannel implements LogicalConnection, IncomingFrames, SuspendTok
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxIdleTimeout()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketPolicy getPolicy()
|
||||
{
|
||||
|
@ -205,6 +212,13 @@ public class MuxChannel implements LogicalConnection, IncomingFrames, SuspendTok
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxIdleTimeout(long ms)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextIncomingFrames(IncomingFrames incoming)
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ public class MuxGenerator
|
|||
|
||||
public void generate(long channelId, Frame frame, WriteCallback callback)
|
||||
{
|
||||
ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,true);
|
||||
ByteBuffer muxPayload = bufferPool.acquire(frame.getPayloadLength() + DATA_FRAME_OVERHEAD,false);
|
||||
BufferUtil.flipToFill(muxPayload);
|
||||
|
||||
// start building mux payload
|
||||
|
@ -90,7 +90,7 @@ public class MuxGenerator
|
|||
return; // nothing to do
|
||||
}
|
||||
|
||||
ByteBuffer payload = bufferPool.acquire(CONTROL_BUFFER_SIZE,true);
|
||||
ByteBuffer payload = bufferPool.acquire(CONTROL_BUFFER_SIZE,false);
|
||||
BufferUtil.flipToFill(payload);
|
||||
|
||||
writeChannelId(payload,0); // control channel
|
||||
|
|
|
@ -243,7 +243,7 @@ public class MuxParser
|
|||
private void parseDataFramePayload(ByteBuffer buffer)
|
||||
{
|
||||
int capacity = buffer.remaining();
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(capacity);
|
||||
ByteBuffer payload = ByteBuffer.allocate(capacity);
|
||||
payload.put(buffer);
|
||||
BufferUtil.flipToFlush(payload,0);
|
||||
muxframe.setPayload(payload);
|
||||
|
@ -336,7 +336,7 @@ public class MuxParser
|
|||
throw new MuxException(err);
|
||||
}
|
||||
|
||||
ByteBuffer ret = ByteBuffer.allocateDirect((int)size);
|
||||
ByteBuffer ret = ByteBuffer.allocate((int)size);
|
||||
BufferUtil.put(buffer,ret);
|
||||
BufferUtil.flipToFlush(ret,0);
|
||||
return ret;
|
||||
|
|
|
@ -347,6 +347,12 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
return ioState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxIdleTimeout()
|
||||
{
|
||||
return getEndPoint().getIdleTimeout();
|
||||
}
|
||||
|
||||
public Parser getParser()
|
||||
{
|
||||
return parser;
|
||||
|
@ -404,7 +410,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
{
|
||||
LOG.debug("{} onFillable()",policy.getBehavior());
|
||||
stats.countOnFillableEvents.incrementAndGet();
|
||||
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true);
|
||||
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),false);
|
||||
BufferUtil.clear(buffer);
|
||||
boolean readMore = false;
|
||||
try
|
||||
|
@ -568,6 +574,12 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
super.setInputBufferSize(inputBufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxIdleTimeout(long ms)
|
||||
{
|
||||
getEndPoint().setIdleTimeout(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSession(WebSocketSession session)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,7 @@ public class MessageInputStream extends InputStream implements MessageAppender
|
|||
public MessageInputStream(AnnotatedEventDriver driver)
|
||||
{
|
||||
this.driver = driver;
|
||||
this.buf = ByteBuffer.allocateDirect(BUFFER_SIZE);
|
||||
this.buf = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
BufferUtil.clearToFill(this.buf);
|
||||
size = 0;
|
||||
readPosition = this.buf.position();
|
||||
|
|
|
@ -37,12 +37,12 @@ public class ClosePayloadParserTest
|
|||
String expectedReason = "Game Over";
|
||||
|
||||
byte utf[] = expectedReason.getBytes(StringUtil.__UTF8_CHARSET);
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(utf.length + 2);
|
||||
ByteBuffer payload = ByteBuffer.allocate(utf.length + 2);
|
||||
payload.putChar((char)StatusCode.NORMAL);
|
||||
payload.put(utf,0,utf.length);
|
||||
payload.flip();
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(24);
|
||||
ByteBuffer buf = ByteBuffer.allocate(24);
|
||||
buf.put((byte)(0x80 | OpCode.CLOSE)); // fin + close
|
||||
buf.put((byte)(0x80 | payload.remaining()));
|
||||
MaskedByteBuffer.putMask(buf);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class GeneratorParserRoundtripTest
|
|||
|
||||
String message = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
|
||||
|
||||
ByteBuffer out = bufferPool.acquire(8192,true);
|
||||
ByteBuffer out = bufferPool.acquire(8192,false);
|
||||
try
|
||||
{
|
||||
// Generate Buffer
|
||||
|
@ -80,7 +80,7 @@ public class GeneratorParserRoundtripTest
|
|||
|
||||
String message = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
|
||||
|
||||
ByteBuffer out = bufferPool.acquire(8192,true);
|
||||
ByteBuffer out = bufferPool.acquire(8192,false);
|
||||
try
|
||||
{
|
||||
// Setup Frame
|
||||
|
|
|
@ -139,7 +139,7 @@ public class GeneratorTest
|
|||
|
||||
// Buffer to capture generated bytes (we do this to validate that the masking
|
||||
// is working correctly
|
||||
ByteBuffer completeBuf = ByteBuffer.allocateDirect(payload.length + expectedHeaderSize);
|
||||
ByteBuffer completeBuf = ByteBuffer.allocate(payload.length + expectedHeaderSize);
|
||||
BufferUtil.clearToFill(completeBuf);
|
||||
|
||||
// Generate and capture generator output
|
||||
|
|
|
@ -191,7 +191,7 @@ public class ParserTest
|
|||
@Test
|
||||
public void testParseCase6_4_3()
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(64);
|
||||
ByteBuffer payload = ByteBuffer.allocate(64);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5")); // good
|
||||
payload.put(TypeUtil.fromHexString("f4908080")); // INVALID
|
||||
|
@ -205,9 +205,9 @@ public class ParserTest
|
|||
|
||||
ByteBuffer buf = new UnitGenerator().generate(text);
|
||||
|
||||
ByteBuffer part1 = ByteBuffer.allocateDirect(17); // header + good
|
||||
ByteBuffer part2 = ByteBuffer.allocateDirect(4); // invalid
|
||||
ByteBuffer part3 = ByteBuffer.allocateDirect(10); // the rest (all good utf)
|
||||
ByteBuffer part1 = ByteBuffer.allocate(17); // header + good
|
||||
ByteBuffer part2 = ByteBuffer.allocate(4); // invalid
|
||||
ByteBuffer part3 = ByteBuffer.allocate(10); // the rest (all good utf)
|
||||
|
||||
BufferUtil.put(buf,part1);
|
||||
BufferUtil.put(buf,part2);
|
||||
|
@ -235,7 +235,7 @@ public class ParserTest
|
|||
@Test
|
||||
public void testParseNothing()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
// Put nothing in the buffer.
|
||||
buf.flip();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class PingPayloadParserTest
|
|||
@Test
|
||||
public void testBasicPingParsing()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
BufferUtil.clearToFill(buf);
|
||||
buf.put(new byte[]
|
||||
{ (byte)0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
|
|
|
@ -21,6 +21,9 @@ package org.eclipse.jetty.websocket.common;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jetty.websocket.common.Generator;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RFC6455ExamplesGeneratorTest
|
||||
|
@ -38,12 +41,12 @@ public class RFC6455ExamplesGeneratorTest
|
|||
ByteBuffer actual1 = generator.generate(text1);
|
||||
ByteBuffer actual2 = generator.generate(text2);
|
||||
|
||||
ByteBuffer expected1 = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected1 = ByteBuffer.allocate(5);
|
||||
|
||||
expected1.put(new byte[]
|
||||
{ (byte)0x01, (byte)0x03, (byte)0x48, (byte)0x65, (byte)0x6c });
|
||||
|
||||
ByteBuffer expected2 = ByteBuffer.allocateDirect(4);
|
||||
ByteBuffer expected2 = ByteBuffer.allocate(4);
|
||||
|
||||
expected2.put(new byte[]
|
||||
{ (byte)0x80, (byte)0x02, (byte)0x6c, (byte)0x6f });
|
||||
|
@ -67,7 +70,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
|
||||
ByteBuffer actual = gen.generate(pong);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(11);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// Unmasked Pong request
|
||||
expected.put(new byte[]
|
||||
|
@ -87,7 +90,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
Generator gen = new UnitGenerator();
|
||||
ByteBuffer actual = gen.generate(text);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(11);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// A single-frame masked text message
|
||||
expected.put(new byte[]
|
||||
|
@ -111,7 +114,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
|
||||
ByteBuffer actual = gen.generate(binary);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(dataSize + FUDGE);
|
||||
ByteBuffer expected = ByteBuffer.allocate(dataSize + FUDGE);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// 256 bytes binary message in a single unmasked frame
|
||||
expected.put(new byte[]
|
||||
|
@ -142,7 +145,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
|
||||
ByteBuffer actual = gen.generate(binary);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(dataSize + 10);
|
||||
ByteBuffer expected = ByteBuffer.allocate(dataSize + 10);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// 64k bytes binary message in a single unmasked frame
|
||||
expected.put(new byte[]
|
||||
|
@ -168,7 +171,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
Generator gen = new UnitGenerator();
|
||||
ByteBuffer actual = gen.generate(ping);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(10);
|
||||
ByteBuffer expected = ByteBuffer.allocate(10);
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89, (byte)0x05, (byte)0x48, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x6f });
|
||||
expected.flip(); // make readable
|
||||
|
@ -185,7 +188,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
|
||||
ByteBuffer actual = generator.generate(text);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(10);
|
||||
ByteBuffer expected = ByteBuffer.allocate(10);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x05, (byte)0x48, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x6f });
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RFC6455ExamplesParserTest
|
|||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
|
@ -75,7 +75,7 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testSingleMaskedPongRequest()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// Unmasked Pong request
|
||||
buf.put(new byte[]
|
||||
|
@ -98,7 +98,7 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testSingleMaskedTextMessage()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// A single-frame masked text message
|
||||
buf.put(new byte[]
|
||||
|
@ -123,7 +123,7 @@ public class RFC6455ExamplesParserTest
|
|||
{
|
||||
int dataSize = 256;
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(dataSize + 10);
|
||||
ByteBuffer buf = ByteBuffer.allocate(dataSize + 10);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// 256 bytes binary message in a single unmasked frame
|
||||
buf.put(new byte[]
|
||||
|
@ -162,7 +162,7 @@ public class RFC6455ExamplesParserTest
|
|||
{
|
||||
int dataSize = 1024 * 64;
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect((dataSize + 10));
|
||||
ByteBuffer buf = ByteBuffer.allocate((dataSize + 10));
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// 64 Kbytes binary message in a single unmasked frame
|
||||
buf.put(new byte[]
|
||||
|
@ -198,7 +198,7 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testSingleUnmaskedPingRequest()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// Unmasked Ping request
|
||||
buf.put(new byte[]
|
||||
|
@ -221,7 +221,7 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testSingleUnmaskedTextMessage()
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(16);
|
||||
ByteBuffer buf = ByteBuffer.allocate(16);
|
||||
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
|
||||
// A single-frame unmasked text message
|
||||
buf.put(new byte[]
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TextPayloadParserTest
|
|||
|
||||
Assert.assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(utf.length + 8);
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 8);
|
||||
buf.put((byte)0x81);
|
||||
buf.put((byte)(0x80 | 0x7E)); // 0x7E == 126 (a 2 byte payload length)
|
||||
buf.putShort((short)utf.length);
|
||||
|
@ -79,7 +79,7 @@ public class TextPayloadParserTest
|
|||
|
||||
Assert.assertThat("Must be a long length payload",utf.length,greaterThan(0xFFFF));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(utf.length + 32);
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 32);
|
||||
buf.put((byte)0x81);
|
||||
buf.put((byte)(0x80 | 0x7F)); // 0x7F == 127 (a 8 byte payload length)
|
||||
buf.putLong(utf.length);
|
||||
|
@ -115,7 +115,7 @@ public class TextPayloadParserTest
|
|||
|
||||
Assert.assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(utf.length + 10);
|
||||
ByteBuffer buf = ByteBuffer.allocate(utf.length + 10);
|
||||
buf.put((byte)0x81);
|
||||
buf.put((byte)(0x80 | 0x7E)); // 0x7E == 126 (a 2 byte payload length)
|
||||
buf.putShort((short)utf.length);
|
||||
|
@ -144,7 +144,7 @@ public class TextPayloadParserTest
|
|||
byte b1[] = part1.getBytes(StringUtil.__UTF8_CHARSET);
|
||||
byte b2[] = part2.getBytes(StringUtil.__UTF8_CHARSET);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer buf = ByteBuffer.allocate(32);
|
||||
|
||||
// part 1
|
||||
buf.put((byte)0x01); // no fin + text
|
||||
|
@ -180,7 +180,7 @@ public class TextPayloadParserTest
|
|||
String expectedText = "Hello World";
|
||||
byte utf[] = expectedText.getBytes(StringUtil.__UTF8_CHARSET);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(24);
|
||||
ByteBuffer buf = ByteBuffer.allocate(24);
|
||||
buf.put((byte)0x81);
|
||||
buf.put((byte)(0x80 | utf.length));
|
||||
MaskedByteBuffer.putMask(buf);
|
||||
|
@ -206,7 +206,7 @@ public class TextPayloadParserTest
|
|||
|
||||
byte utf[] = expectedText.getBytes(StringUtil.__UTF8);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(24);
|
||||
ByteBuffer buf = ByteBuffer.allocate(24);
|
||||
buf.put((byte)0x81);
|
||||
buf.put((byte)(0x80 | utf.length));
|
||||
MaskedByteBuffer.putMask(buf);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class UnitGenerator extends Generator
|
|||
{
|
||||
buflen += f.getPayloadLength() + Generator.OVERHEAD;
|
||||
}
|
||||
ByteBuffer completeBuf = ByteBuffer.allocateDirect(buflen);
|
||||
ByteBuffer completeBuf = ByteBuffer.allocate(buflen);
|
||||
BufferUtil.clearToFill(completeBuf);
|
||||
|
||||
// Generate frames
|
||||
|
|
|
@ -58,7 +58,7 @@ public class WebSocketFrameTest
|
|||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(OpCode.CLOSE).setFin(false);
|
||||
ByteBuffer actual = laxGenerator.generate(frame);
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(2);
|
||||
ByteBuffer expected = ByteBuffer.allocate(2);
|
||||
expected.put((byte)0x08);
|
||||
expected.put((byte)0x00);
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class WebSocketFrameTest
|
|||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(OpCode.PING).setFin(false);
|
||||
ByteBuffer actual = laxGenerator.generate(frame);
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(2);
|
||||
ByteBuffer expected = ByteBuffer.allocate(2);
|
||||
expected.put((byte)0x09);
|
||||
expected.put((byte)0x00);
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class WebSocketFrameTest
|
|||
{
|
||||
CloseInfo close = new CloseInfo(StatusCode.NORMAL);
|
||||
ByteBuffer actual = strictGenerator.generate(close.asFrame());
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(4);
|
||||
ByteBuffer expected = ByteBuffer.allocate(4);
|
||||
expected.put((byte)0x88);
|
||||
expected.put((byte)0x02);
|
||||
expected.put((byte)0x03);
|
||||
|
@ -96,7 +96,7 @@ public class WebSocketFrameTest
|
|||
{
|
||||
WebSocketFrame frame = new WebSocketFrame(OpCode.PING);
|
||||
ByteBuffer actual = strictGenerator.generate(frame);
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(2);
|
||||
ByteBuffer expected = ByteBuffer.allocate(2);
|
||||
expected.put((byte)0x89);
|
||||
expected.put((byte)0x00);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -96,7 +96,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -136,7 +136,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -176,7 +176,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -217,7 +217,7 @@ public class TestABCase1_1
|
|||
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -255,7 +255,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -284,7 +284,7 @@ public class TestABCase1_1
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x00 });
|
||||
|
@ -299,7 +299,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 125;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -332,7 +332,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 126;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -366,7 +366,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 127;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -400,7 +400,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 128;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -434,7 +434,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 65535;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -470,7 +470,7 @@ public class TestABCase1_1
|
|||
{
|
||||
int length = 65536;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
@ -506,7 +506,7 @@ public class TestABCase1_1
|
|||
public void testParseEmptyTextCase1_1_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x00 });
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 125;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ public class TestABCase1_2
|
|||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -88,7 +88,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 126;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -102,7 +102,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -130,7 +130,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 127;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -173,7 +173,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 128;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -216,7 +216,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 65535;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -256,7 +256,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 65536;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(length);
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
|
@ -271,7 +271,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -300,7 +300,7 @@ public class TestABCase1_2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
@ -315,7 +315,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 125;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -348,7 +348,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 126;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -382,7 +382,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 127;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -416,7 +416,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 128;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -450,7 +450,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 65535;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -486,7 +486,7 @@ public class TestABCase1_2
|
|||
{
|
||||
int length = 65536;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(length + 11);
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
@ -521,7 +521,7 @@ public class TestABCase1_2
|
|||
public void testParseEmptyBinaryCase1_2_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
|
|
@ -58,7 +58,7 @@ public class TestABCase2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(pingFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(bytes.length + 32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(bytes.length + 32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -83,7 +83,7 @@ public class TestABCase2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(pingFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -108,7 +108,7 @@ public class TestABCase2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(pingFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89, (byte)0x00 });
|
||||
|
@ -129,7 +129,7 @@ public class TestABCase2
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(pingFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -183,7 +183,7 @@ public class TestABCase2
|
|||
bytes[i] = Integer.valueOf(Integer.toOctalString(i)).byteValue();
|
||||
}
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(bytes.length + 32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(bytes.length + 32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -213,7 +213,7 @@ public class TestABCase2
|
|||
{
|
||||
byte[] bytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -241,7 +241,7 @@ public class TestABCase2
|
|||
@Test
|
||||
public void testParseEmptyPingCase2_1()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89, (byte)0x00 });
|
||||
|
@ -267,7 +267,7 @@ public class TestABCase2
|
|||
String message = "Hello, world!";
|
||||
byte[] messageBytes = message.getBytes();
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x89 });
|
||||
|
@ -298,7 +298,7 @@ public class TestABCase2
|
|||
byte[] bytes = new byte[126];
|
||||
Arrays.fill(bytes,(byte)0x00);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(bytes.length + Generator.OVERHEAD);
|
||||
ByteBuffer expected = ByteBuffer.allocate(bytes.length + Generator.OVERHEAD);
|
||||
|
||||
byte b;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TestABCase4
|
|||
@Test
|
||||
public void testParserControlOpCode11Case4_2_1()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x8b, 0x00 });
|
||||
|
@ -73,7 +73,7 @@ public class TestABCase4
|
|||
@Test
|
||||
public void testParserControlOpCode12WithPayloadCase4_2_2()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x8c, 0x01, 0x00 });
|
||||
|
@ -96,7 +96,7 @@ public class TestABCase4
|
|||
@Test
|
||||
public void testParserNonControlOpCode3Case4_1_1()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x83, 0x00 });
|
||||
|
@ -118,7 +118,7 @@ public class TestABCase4
|
|||
@Test
|
||||
public void testParserNonControlOpCode4WithPayloadCase4_1_2()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x84, 0x01, 0x00 });
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TestABCase7_3
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(close.asFrame());
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88, (byte)0x00 });
|
||||
|
@ -66,7 +66,7 @@ public class TestABCase7_3
|
|||
@Test
|
||||
public void testCase7_3_1ParseEmptyClose()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88, (byte)0x00 });
|
||||
|
@ -100,7 +100,7 @@ public class TestABCase7_3
|
|||
@Test
|
||||
public void testCase7_3_2Parse1BytePayloadClose()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88, 0x01, 0x00 });
|
||||
|
@ -127,7 +127,7 @@ public class TestABCase7_3
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(close.asFrame());
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88, (byte)0x02, 0x03, (byte)0xe8 });
|
||||
|
@ -140,7 +140,7 @@ public class TestABCase7_3
|
|||
@Test
|
||||
public void testCase7_3_3ParseCloseWithStatus()
|
||||
{
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(5);
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88, (byte)0x02, 0x03, (byte)0xe8 });
|
||||
|
@ -172,7 +172,7 @@ public class TestABCase7_3
|
|||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(close.asFrame());
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88 });
|
||||
|
@ -194,7 +194,7 @@ public class TestABCase7_3
|
|||
String message = "bad cough";
|
||||
byte[] messageBytes = message.getBytes();
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer expected = ByteBuffer.allocate(32);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88 });
|
||||
|
@ -232,7 +232,7 @@ public class TestABCase7_3
|
|||
|
||||
Generator generator = new UnitGenerator();
|
||||
ByteBuffer actual = generator.generate(close.asFrame());
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(132);
|
||||
ByteBuffer expected = ByteBuffer.allocate(132);
|
||||
|
||||
byte messageBytes[] = message.toString().getBytes(StringUtil.__UTF8_CHARSET);
|
||||
|
||||
|
@ -262,7 +262,7 @@ public class TestABCase7_3
|
|||
|
||||
byte[] messageBytes = message.toString().getBytes(StringUtil.__UTF8_CHARSET);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(132);
|
||||
ByteBuffer expected = ByteBuffer.allocate(132);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x88 });
|
||||
|
@ -301,7 +301,7 @@ public class TestABCase7_3
|
|||
|
||||
WebSocketFrame closeFrame = new WebSocketFrame(OpCode.CLOSE);
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(WebSocketFrame.MAX_CONTROL_PAYLOAD + 1); // 126 which is too big for control
|
||||
ByteBuffer bb = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD + 1); // 126 which is too big for control
|
||||
|
||||
bb.putChar((char)1000);
|
||||
bb.put(messageBytes);
|
||||
|
@ -320,7 +320,7 @@ public class TestABCase7_3
|
|||
byte[] messageBytes = new byte[124];
|
||||
Arrays.fill(messageBytes,(byte)'*');
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer expected = ByteBuffer.allocate(256);
|
||||
|
||||
byte b;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class DeflateCompressionMethodTest
|
|||
method.compress().end();
|
||||
|
||||
// decompress
|
||||
ByteBuffer decompressed = ByteBuffer.allocateDirect(msg.length());
|
||||
ByteBuffer decompressed = ByteBuffer.allocate(msg.length());
|
||||
LOG.debug("decompressed(a): {}",BufferUtil.toDetailString(decompressed));
|
||||
method.decompress().begin();
|
||||
method.decompress().input(compressed);
|
||||
|
@ -89,7 +89,7 @@ public class DeflateCompressionMethodTest
|
|||
CompressionMethod method = new DeflateCompressionMethod();
|
||||
|
||||
// Decompressed Data Holder
|
||||
ByteBuffer decompressed = ByteBuffer.allocateDirect(32);
|
||||
ByteBuffer decompressed = ByteBuffer.allocate(32);
|
||||
BufferUtil.flipToFill(decompressed);
|
||||
|
||||
// Perform Decompress on Buf 1
|
||||
|
|
|
@ -179,7 +179,7 @@ public class FrameCompressionExtensionTest
|
|||
compressor.finish();
|
||||
|
||||
// Perform compression
|
||||
ByteBuffer outbuf = ByteBuffer.allocateDirect(64);
|
||||
ByteBuffer outbuf = ByteBuffer.allocate(64);
|
||||
BufferUtil.clearToFill(outbuf);
|
||||
|
||||
while (!compressor.finished())
|
||||
|
|
|
@ -88,7 +88,7 @@ public class MuxGeneratorWrite139SizeTest
|
|||
public void testWrite139Size()
|
||||
{
|
||||
System.err.printf("Running %s.%s - value: %,d%n",this.getClass().getName(),testname.getMethodName(),value);
|
||||
ByteBuffer bbuf = ByteBuffer.allocateDirect(10);
|
||||
ByteBuffer bbuf = ByteBuffer.allocate(10);
|
||||
generator.write139Size(bbuf,value);
|
||||
BufferUtil.flipToFlush(bbuf,0);
|
||||
byte actual[] = BufferUtil.toArray(bbuf);
|
||||
|
|
|
@ -92,7 +92,7 @@ public class MuxGeneratorWriteChannelIdTest
|
|||
public void testReadChannelId()
|
||||
{
|
||||
System.err.printf("Running %s.%s - channelId: %,d%n",this.getClass().getName(),testname.getMethodName(),channelId);
|
||||
ByteBuffer bbuf = ByteBuffer.allocateDirect(10);
|
||||
ByteBuffer bbuf = ByteBuffer.allocate(10);
|
||||
generator.writeChannelId(bbuf,channelId);
|
||||
BufferUtil.flipToFlush(bbuf,0);
|
||||
byte actual[] = BufferUtil.toArray(bbuf);
|
||||
|
|
|
@ -91,6 +91,13 @@ public class LocalWebSocketConnection implements LogicalConnection, IncomingFram
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxIdleTimeout()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketPolicy getPolicy()
|
||||
{
|
||||
|
@ -148,6 +155,13 @@ public class LocalWebSocketConnection implements LogicalConnection, IncomingFram
|
|||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxIdleTimeout(long ms)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextIncomingFrames(IncomingFrames incoming)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Map;
|
|||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -39,8 +38,8 @@ import org.eclipse.jetty.server.HttpConnection;
|
|||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.eclipse.jetty.util.thread.TimerScheduler;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
|
@ -83,7 +82,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
/**
|
||||
* Have the factory maintain 1 and only 1 scheduler. All connections share this scheduler.
|
||||
*/
|
||||
private final Scheduler scheduler = new TimerScheduler();
|
||||
private final Scheduler scheduler = new ScheduledExecutorScheduler();
|
||||
private final String supportedVersions;
|
||||
private final WebSocketPolicy basePolicy;
|
||||
private final EventDriverFactory eventDriverFactory;
|
||||
|
@ -308,7 +307,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.eclipse.jetty.websocket.server.WebSocketServletFactory#register(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
|
@ -349,7 +348,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
* <p>
|
||||
* This method will not normally return, but will instead throw a UpgradeConnectionException, to exit HTTP handling and initiate WebSocket handling of the
|
||||
* connection.
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* The request to upgrade
|
||||
* @param response
|
||||
|
|
|
@ -101,7 +101,7 @@ public class Fuzzer
|
|||
{
|
||||
buflen += f.getPayloadLength() + Generator.OVERHEAD;
|
||||
}
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(buflen);
|
||||
ByteBuffer buf = ByteBuffer.allocate(buflen);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
// Generate frames
|
||||
|
@ -271,7 +271,7 @@ public class Fuzzer
|
|||
{
|
||||
buflen += f.getPayloadLength() + Generator.OVERHEAD;
|
||||
}
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(buflen);
|
||||
ByteBuffer buf = ByteBuffer.allocate(buflen);
|
||||
BufferUtil.clearToFill(buf);
|
||||
|
||||
// Generate frames
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.server.ab;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
|
@ -298,7 +299,9 @@ public class TestABCase6 extends AbstractABCase
|
|||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
|
||||
fuzzer.send(new WebSocketFrame(OpCode.TEXT).setPayload(part1).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part2).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part3).setFin(true));
|
||||
|
||||
fuzzer.expect(expect);
|
||||
|
@ -335,7 +338,9 @@ public class TestABCase6 extends AbstractABCase
|
|||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.TEXT).setPayload(part1).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part2).setFin(false));
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(new WebSocketFrame(OpCode.CONTINUATION).setPayload(part3).setFin(true));
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
|
@ -355,7 +360,7 @@ public class TestABCase6 extends AbstractABCase
|
|||
// Disable Long Stacks from Parser (we know this test will throw an exception)
|
||||
enableStacks(Parser.class,false);
|
||||
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(64);
|
||||
ByteBuffer payload = ByteBuffer.allocate(64);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5")); // good
|
||||
payload.put(TypeUtil.fromHexString("f4908080")); // INVALID
|
||||
|
@ -389,10 +394,12 @@ public class TestABCase6 extends AbstractABCase
|
|||
part3.limit(splits[2]);
|
||||
|
||||
fuzzer.send(part1); // the header + good utf
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(part2); // the bad UTF
|
||||
|
||||
fuzzer.expect(expect);
|
||||
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.sendExpectingIOException(part3); // the rest (shouldn't work)
|
||||
}
|
||||
finally
|
||||
|
@ -429,7 +436,9 @@ public class TestABCase6 extends AbstractABCase
|
|||
ByteBuffer net = fuzzer.asNetworkBuffer(send);
|
||||
fuzzer.send(net,6);
|
||||
fuzzer.send(net,11);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,1);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
fuzzer.send(net,100); // the rest
|
||||
|
||||
fuzzer.expect(expect);
|
||||
|
|
|
@ -367,7 +367,7 @@ public class TestABCase7 extends AbstractABCase
|
|||
@Test
|
||||
public void testCase7_3_6() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.put((byte)0xE8);
|
||||
payload.put((byte)0x03);
|
||||
|
@ -408,7 +408,7 @@ public class TestABCase7 extends AbstractABCase
|
|||
@Test
|
||||
public void testCase7_5_1() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.put((byte)0x03); // normal close
|
||||
payload.put((byte)0xE8);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
|
|||
@Test
|
||||
public void testBadStatusCode() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.putChar((char)statusCode);
|
||||
BufferUtil.flipToFlush(payload,0);
|
||||
|
@ -118,7 +118,7 @@ public class TestABCase7_BadStatusCodes extends AbstractABCase
|
|||
@Test
|
||||
public void testBadStatusCodeWithReason() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.putChar((char)statusCode);
|
||||
payload.put(StringUtil.getBytes("Reason"));
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
|
|||
@Test
|
||||
public void testStatusCode() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.putChar((char)statusCode);
|
||||
BufferUtil.flipToFlush(payload,0);
|
||||
|
@ -113,7 +113,7 @@ public class TestABCase7_GoodStatusCodes extends AbstractABCase
|
|||
@Test
|
||||
public void testStatusCodeWithReason() throws Exception
|
||||
{
|
||||
ByteBuffer payload = ByteBuffer.allocateDirect(256);
|
||||
ByteBuffer payload = ByteBuffer.allocate(256);
|
||||
BufferUtil.clearToFill(payload);
|
||||
payload.putChar((char)statusCode);
|
||||
payload.put(StringUtil.getBytes("Reason"));
|
||||
|
|
|
@ -479,7 +479,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
{
|
||||
LOG.debug("Read: waiting for {} frame(s) from server",expectedCount);
|
||||
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,true);
|
||||
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,false);
|
||||
BufferUtil.clearToFill(buf);
|
||||
try
|
||||
{
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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.examples;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.server.examples.echo.BigEchoSocket;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class MyCustomCreationServlet extends WebSocketServlet
|
||||
{
|
||||
public static class MyCustomCreator implements WebSocketCreator
|
||||
{
|
||||
@Override
|
||||
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
|
||||
{
|
||||
String query = req.getQueryString();
|
||||
|
||||
// Start looking at the UpgradeRequest to determine what you want to do
|
||||
if ((query == null) || (query.length() <= 0))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Let UPGRADE request for websocket fail with
|
||||
// status code 403 (FORBIDDEN) [per RFC-6455]
|
||||
resp.sendForbidden("Unspecified query");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// An input or output exception occurs
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// No UPGRADE
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create the websocket we want to
|
||||
if (query.contains("bigecho"))
|
||||
{
|
||||
return new BigEchoSocket();
|
||||
}
|
||||
else if (query.contains("echo"))
|
||||
{
|
||||
return new MyEchoSocket();
|
||||
}
|
||||
|
||||
// Let UPGRADE fail with 503 (UNAVAILABLE)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WebSocketServletFactory factory)
|
||||
{
|
||||
factory.setCreator(new MyCustomCreator());
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class EchoBroadcastPingSocket extends EchoBroadcastSocket
|
|||
while (!latch.await(10,TimeUnit.SECONDS))
|
||||
{
|
||||
System.err.println("Ping");
|
||||
ByteBuffer data = ByteBuffer.allocateDirect(3);
|
||||
ByteBuffer data = ByteBuffer.allocate(3);
|
||||
data.put(new byte[]
|
||||
{ (byte)1, (byte)2, (byte)3 });
|
||||
data.flip();
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.helper;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -36,6 +34,8 @@ import org.eclipse.jetty.util.BufferUtil;
|
|||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SafariD00
|
||||
{
|
||||
private URI uri;
|
||||
|
@ -52,7 +52,7 @@ public class SafariD00
|
|||
|
||||
/**
|
||||
* Open the Socket to the destination endpoint and
|
||||
*
|
||||
*
|
||||
* @return the open java Socket.
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ public class SafariD00
|
|||
|
||||
/**
|
||||
* Issue an Http websocket (Draft-0) upgrade request using the Safari particulars.
|
||||
*
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public void issueHandshake() throws IOException
|
||||
|
@ -135,7 +135,7 @@ public class SafariD00
|
|||
len += (msg.length() + 2);
|
||||
}
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(len);
|
||||
ByteBuffer buf = ByteBuffer.allocate(len);
|
||||
|
||||
for (String msg : msgs)
|
||||
{
|
||||
|
|
|
@ -42,15 +42,17 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
|||
* <pre>
|
||||
* package my.example;
|
||||
*
|
||||
* import javax.servlet.http.HttpServletRequest;
|
||||
* import org.eclipse.jetty.websocket.WebSocket;
|
||||
* import org.eclipse.jetty.websocket.server.WebSocketServlet;
|
||||
* import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
* import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
*
|
||||
* public class MyEchoServlet extends WebSocketServlet
|
||||
* {
|
||||
* @Override
|
||||
* public void registerWebSockets(WebSocketServerFactory factory)
|
||||
* public void configure(WebSocketServletFactory factory)
|
||||
* {
|
||||
* // set a 10 second idle timeout
|
||||
* factory.getPolicy().setIdleTimeout(10000);
|
||||
* // register my socket
|
||||
* factory.register(MyEchoSocket.class);
|
||||
* }
|
||||
* }
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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 examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class MyExampleServlet extends WebSocketServlet
|
||||
{
|
||||
@Override
|
||||
public void configure(WebSocketServletFactory factory)
|
||||
{
|
||||
// set a 10 second timeout
|
||||
factory.getPolicy().setIdleTimeout(10000);
|
||||
// register my socket
|
||||
factory.register(MyExampleSocket.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 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 examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
|
||||
/**
|
||||
* Example WebSocket, simple echo
|
||||
*/
|
||||
public class MyExampleSocket extends WebSocketAdapter
|
||||
{
|
||||
@Override
|
||||
public void onWebSocketText(String message)
|
||||
{
|
||||
// Echo message back, asynchronously
|
||||
getSession().getRemote().sendStringByFuture(message);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
# format, either plain text or OBF:.
|
||||
#
|
||||
jetty: MD5:164c88b302622e17050af52c89945d44,user
|
||||
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin
|
||||
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user
|
||||
other: OBF:1xmk1w261u9r1w1c1xmq,user
|
||||
plain: plain,user
|
||||
user: password,user
|
||||
|
|
|
@ -110,7 +110,7 @@ public class Dump extends HttpServlet
|
|||
@Override
|
||||
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
if (!request.isUserInRole("user"))
|
||||
if (request.getRemoteUser()==null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -23,17 +23,80 @@ import java.util.Set;
|
|||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.annotation.HandlesTypes;
|
||||
|
||||
@HandlesTypes ({javax.servlet.Servlet.class, Foo.class})
|
||||
public class FooInitializer implements ServletContainerInitializer
|
||||
{
|
||||
public static class BarListener implements ServletContextListener
|
||||
{
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
|
||||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
throw new IllegalStateException("BAR LISTENER CALLED!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
|
||||
*/
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class FooListener implements ServletContextListener
|
||||
{
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
|
||||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
//Can add a ServletContextListener from a ServletContainerInitializer
|
||||
sce.getServletContext().setAttribute("com.acme.AnnotationTest.listenerTest", Boolean.TRUE);
|
||||
|
||||
//Can't add a ServletContextListener from a ServletContextListener
|
||||
try
|
||||
{
|
||||
sce.getServletContext().addListener(new BarListener());
|
||||
sce.getServletContext().setAttribute("com.acme.AnnotationTest.listenerRegoTest", Boolean.FALSE);
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
sce.getServletContext().setAttribute("com.acme.AnnotationTest.listenerRegoTest", Boolean.TRUE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sce.getServletContext().setAttribute("com.acme.AnnotationTest.listenerRegoTest", Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
|
||||
*/
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void onStartup(Set<Class<?>> classes, ServletContext context)
|
||||
{
|
||||
context.setAttribute("com.acme.Foo", new ArrayList<Class>(classes));
|
||||
ServletRegistration.Dynamic reg = context.addServlet("AnnotationTest", "com.acme.AnnotationTest");
|
||||
context.setAttribute("com.acme.AnnotationTest.complete", (reg == null));
|
||||
context.addListener(new FooListener());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,6 +245,14 @@ public class AnnotationTest extends HttpServlet
|
|||
Boolean complete = (Boolean)config.getServletContext().getAttribute("com.acme.AnnotationTest.complete");
|
||||
out.println("<br/><b>Result: "+(complete.booleanValue()?"PASS":"FAIL")+"</b>");
|
||||
|
||||
out.println("<h2>ServletContextListener Programmatic Registration from ServletContainerInitializer</h2>");
|
||||
Boolean programmaticListener = (Boolean)config.getServletContext().getAttribute("com.acme.AnnotationTest.listenerTest");
|
||||
out.println("<br/><b>Result: "+(programmaticListener.booleanValue()?"PASS":"FAIL")+"</b>");
|
||||
|
||||
out.println("<h2>ServletContextListener Programmatic Registration Prevented from ServletContextListener</h2>");
|
||||
Boolean programmaticListenerPrevention = (Boolean)config.getServletContext().getAttribute("com.acme.AnnotationTest.listenerRegoTest");
|
||||
out.println("<br/><b>Result: "+(programmaticListenerPrevention.booleanValue()?"PASS":"FAIL")+"</b>");
|
||||
|
||||
out.println("<h2>@PostConstruct Callback</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@PostConstruct");
|
||||
|
|
Loading…
Reference in New Issue