308851 Converted all jetty-client tests to JUnit 4
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3457 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
6190961f31
commit
c8375b286a
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
|
||||||
|
@ -22,8 +26,6 @@ import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.io.Buffer;
|
import org.eclipse.jetty.io.Buffer;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
|
@ -32,17 +34,20 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.StdErrLog;
|
import org.eclipse.jetty.util.log.StdErrLog;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
public abstract class AbstractHttpExchangeCancelTest
|
||||||
{
|
{
|
||||||
private Server server;
|
private Server server;
|
||||||
private Connector connector;
|
private Connector connector;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
server = new Server();
|
server = new Server();
|
||||||
connector = new SelectChannelConnector();
|
connector = new SelectChannelConnector();
|
||||||
|
@ -51,13 +56,15 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@After
|
||||||
protected void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
server.stop();
|
server.stop();
|
||||||
server.join();
|
server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnSend1() throws Exception
|
public void testHttpExchangeCancelOnSend1() throws Exception
|
||||||
{
|
{
|
||||||
// One of the first things that HttpClient.send() does
|
// One of the first things that HttpClient.send() does
|
||||||
|
@ -93,6 +100,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnSend2() throws Exception
|
public void testHttpExchangeCancelOnSend2() throws Exception
|
||||||
{
|
{
|
||||||
// One of the first things that HttpClient.send() does
|
// One of the first things that HttpClient.send() does
|
||||||
|
@ -129,6 +138,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnRequestCommitted() throws Exception
|
public void testHttpExchangeCancelOnRequestCommitted() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -152,6 +163,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnRequestComplete() throws Exception
|
public void testHttpExchangeCancelOnRequestComplete() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -175,6 +188,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnResponseStatus() throws Exception
|
public void testHttpExchangeCancelOnResponseStatus() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -198,6 +213,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnResponseHeader() throws Exception
|
public void testHttpExchangeCancelOnResponseHeader() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -221,6 +238,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnResponseHeadersComplete() throws Exception
|
public void testHttpExchangeCancelOnResponseHeadersComplete() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -244,6 +263,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnResponseContent() throws Exception
|
public void testHttpExchangeCancelOnResponseContent() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -267,6 +288,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeCancelOnResponseComplete() throws Exception
|
public void testHttpExchangeCancelOnResponseComplete() throws Exception
|
||||||
{
|
{
|
||||||
TestHttpExchange exchange = new TestHttpExchange()
|
TestHttpExchange exchange = new TestHttpExchange()
|
||||||
|
@ -290,6 +313,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertEquals(HttpExchange.STATUS_COMPLETED, status);
|
assertEquals(HttpExchange.STATUS_COMPLETED, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeOnServerException() throws Exception
|
public void testHttpExchangeOnServerException() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -313,6 +338,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHttpExchangeOnExpire() throws Exception
|
public void testHttpExchangeOnExpire() throws Exception
|
||||||
{
|
{
|
||||||
HttpClient httpClient = getHttpClient();
|
HttpClient httpClient = getHttpClient();
|
||||||
|
@ -338,15 +365,19 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
assertFalse(exchange.isAssociated());
|
assertFalse(exchange.isAssociated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected abstract HttpClient getHttpClient();
|
protected abstract HttpClient getHttpClient();
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected Address newAddress()
|
protected Address newAddress()
|
||||||
{
|
{
|
||||||
return new Address("localhost", connector.getLocalPort());
|
return new Address("localhost", connector.getLocalPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private static class EmptyHandler extends AbstractHandler
|
private static class EmptyHandler extends AbstractHandler
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
|
@ -382,28 +413,33 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected static class TestHttpExchange extends ContentExchange
|
protected static class TestHttpExchange extends ContentExchange
|
||||||
{
|
{
|
||||||
private boolean responseCompleted;
|
private boolean responseCompleted;
|
||||||
private boolean failed = false;
|
private boolean failed = false;
|
||||||
private boolean expired = false;
|
private boolean expired = false;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected TestHttpExchange()
|
protected TestHttpExchange()
|
||||||
{
|
{
|
||||||
super(true);
|
super(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void onResponseComplete() throws IOException
|
protected synchronized void onResponseComplete() throws IOException
|
||||||
{
|
{
|
||||||
this.responseCompleted = true;
|
this.responseCompleted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public synchronized boolean isResponseCompleted()
|
public synchronized boolean isResponseCompleted()
|
||||||
{
|
{
|
||||||
return responseCompleted;
|
return responseCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void onException(Throwable ex)
|
protected synchronized void onException(Throwable ex)
|
||||||
{
|
{
|
||||||
|
@ -414,17 +450,20 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public synchronized boolean isFailed()
|
public synchronized boolean isFailed()
|
||||||
{
|
{
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void onExpire()
|
protected synchronized void onExpire()
|
||||||
{
|
{
|
||||||
this.expired = true;
|
this.expired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public synchronized boolean isExpired()
|
public synchronized boolean isExpired()
|
||||||
{
|
{
|
||||||
return expired;
|
return expired;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -22,13 +24,15 @@ import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public class AsyncCallbackHttpExchangeTest extends TestCase
|
public class AsyncCallbackHttpExchangeTest
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* If the HttpExchange callbacks are called holding the lock on HttpExchange,
|
* If the HttpExchange callbacks are called holding the lock on HttpExchange,
|
||||||
* it will be impossible for the callback to perform some work asynchronously
|
* it will be impossible for the callback to perform some work asynchronously
|
||||||
|
@ -37,6 +41,7 @@ public class AsyncCallbackHttpExchangeTest extends TestCase
|
||||||
*
|
*
|
||||||
* @throws Exception if the test fails
|
* @throws Exception if the test fails
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testAsyncCallback() throws Exception
|
public void testAsyncCallback() throws Exception
|
||||||
{
|
{
|
||||||
ExecutorService executor = Executors.newCachedThreadPool();
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
@ -56,22 +61,26 @@ public class AsyncCallbackHttpExchangeTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private class TestHttpExchange extends HttpExchange
|
private class TestHttpExchange extends HttpExchange
|
||||||
{
|
{
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
private final AtomicReference<Exception> failure;
|
private final AtomicReference<Exception> failure;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private TestHttpExchange(ExecutorService executor, AtomicReference<Exception> failure)
|
private TestHttpExchange(ExecutorService executor, AtomicReference<Exception> failure)
|
||||||
{
|
{
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.failure = failure;
|
this.failure = failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected void onRequestCommitted() throws IOException
|
protected void onRequestCommitted() throws IOException
|
||||||
{
|
{
|
||||||
Future<Integer> future = executor.submit(new Callable<Integer>()
|
Future<Integer> future = executor.submit(new Callable<Integer>()
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public Integer call() throws Exception
|
public Integer call() throws Exception
|
||||||
{
|
{
|
||||||
// Method getStatus() reads synchronized state
|
// Method getStatus() reads synchronized state
|
||||||
|
|
|
@ -13,11 +13,16 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public class AsyncSslSecurityListenerTest extends SslSecurityListenerTest
|
public class AsyncSslSecurityListenerTest extends SslSecurityListenerTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Before
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
_type = HttpClient.CONNECTOR_SELECT_CHANNEL;
|
_type = HttpClient.CONNECTOR_SELECT_CHANNEL;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
|
@ -22,8 +26,10 @@ public class BlockingHttpExchangeCancelTest extends AbstractHttpExchangeCancelTe
|
||||||
{
|
{
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Before
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
httpClient = new HttpClient();
|
httpClient = new HttpClient();
|
||||||
|
@ -31,13 +37,16 @@ public class BlockingHttpExchangeCancelTest extends AbstractHttpExchangeCancelTe
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@After
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
httpClient.stop();
|
httpClient.stop();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected HttpClient getHttpClient()
|
protected HttpClient getHttpClient()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
@ -7,26 +9,27 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CachedHeadersIsolationTest extends TestCase
|
/* ------------------------------------------------------------ */
|
||||||
|
public class CachedHeadersIsolationTest
|
||||||
{
|
{
|
||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
|
||||||
server = new Server();
|
server = new Server();
|
||||||
|
|
||||||
Connector connector = new SelectChannelConnector();
|
Connector connector = new SelectChannelConnector();
|
||||||
|
@ -35,7 +38,7 @@ public class CachedHeadersIsolationTest extends TestCase
|
||||||
|
|
||||||
server.setHandler(new AbstractHandler()
|
server.setHandler(new AbstractHandler()
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
|
||||||
ServletException
|
ServletException
|
||||||
{
|
{
|
||||||
|
@ -58,14 +61,16 @@ public class CachedHeadersIsolationTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void tearDown() throws Exception
|
@After
|
||||||
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
super.tearDown();
|
|
||||||
server.stop();
|
server.stop();
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHeaderWhenReadEarly() throws Exception
|
public void testHeaderWhenReadEarly() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -88,6 +93,8 @@ public class CachedHeadersIsolationTest extends TestCase
|
||||||
assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name"));
|
assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHeaderWhenReadLate() throws Exception
|
public void testHeaderWhenReadLate() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -27,8 +30,6 @@ import javax.servlet.ServletInputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.client.security.Realm;
|
import org.eclipse.jetty.client.security.Realm;
|
||||||
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
|
@ -45,9 +46,11 @@ import org.eclipse.jetty.servlet.DefaultServlet;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.util.IO;
|
import org.eclipse.jetty.util.IO;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ContentExchangeTest
|
public class ContentExchangeTest
|
||||||
extends TestCase
|
|
||||||
{
|
{
|
||||||
private static String _content =
|
private static String _content =
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
|
||||||
|
@ -71,6 +74,8 @@ public class ContentExchangeTest
|
||||||
private String _baseUrl;
|
private String _baseUrl;
|
||||||
private String _requestContent;
|
private String _requestContent;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -91,6 +96,8 @@ public class ContentExchangeTest
|
||||||
_baseUrl = _protocol+"://localhost:"+port+ "/";
|
_baseUrl = _protocol+"://localhost:"+port+ "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -101,6 +108,8 @@ public class ContentExchangeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPut() throws Exception
|
public void testPut() throws Exception
|
||||||
{
|
{
|
||||||
startClient(_realm);
|
startClient(_realm);
|
||||||
|
@ -124,6 +133,8 @@ public class ContentExchangeTest
|
||||||
assertEquals(_content,content);
|
assertEquals(_content,content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGet() throws Exception
|
public void testGet() throws Exception
|
||||||
{
|
{
|
||||||
startClient(_realm);
|
startClient(_realm);
|
||||||
|
@ -148,6 +159,8 @@ public class ContentExchangeTest
|
||||||
assertEquals(_content,content);
|
assertEquals(_content,content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testHead() throws Exception
|
public void testHead() throws Exception
|
||||||
{
|
{
|
||||||
startClient(_realm);
|
startClient(_realm);
|
||||||
|
@ -166,6 +179,8 @@ public class ContentExchangeTest
|
||||||
assertEquals(HttpStatus.OK_200,responseStatus);
|
assertEquals(HttpStatus.OK_200,responseStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPost() throws Exception
|
public void testPost() throws Exception
|
||||||
{
|
{
|
||||||
startClient(_realm);
|
startClient(_realm);
|
||||||
|
@ -186,6 +201,7 @@ public class ContentExchangeTest
|
||||||
assertEquals(_content,_requestContent);
|
assertEquals(_content,_requestContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void configureServer(Server server)
|
protected void configureServer(Server server)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -209,6 +225,7 @@ public class ContentExchangeTest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void startClient(Realm realm)
|
protected void startClient(Realm realm)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -221,12 +238,14 @@ public class ContentExchangeTest
|
||||||
_client.start();
|
_client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void configureClient(HttpClient client)
|
protected void configureClient(HttpClient client)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
|
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void stopClient()
|
protected void stopClient()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -237,41 +256,49 @@ public class ContentExchangeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected String getBasePath()
|
protected String getBasePath()
|
||||||
{
|
{
|
||||||
return _docRoot.getAbsolutePath();
|
return _docRoot.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected String getBaseUrl()
|
protected String getBaseUrl()
|
||||||
{
|
{
|
||||||
return _baseUrl;
|
return _baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected HttpClient getClient()
|
protected HttpClient getClient()
|
||||||
{
|
{
|
||||||
return _client;
|
return _client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected Realm getRealm()
|
protected Realm getRealm()
|
||||||
{
|
{
|
||||||
return _realm;
|
return _realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected String getContent()
|
protected String getContent()
|
||||||
{
|
{
|
||||||
return _content;
|
return _content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void setProtocol(String protocol)
|
protected void setProtocol(String protocol)
|
||||||
{
|
{
|
||||||
_protocol = protocol;
|
_protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void setRealm(Realm realm)
|
protected void setRealm(Realm realm)
|
||||||
{
|
{
|
||||||
_realm = realm;
|
_realm = realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public static void copyStream(InputStream in, OutputStream out)
|
public static void copyStream(InputStream in, OutputStream out)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -293,13 +320,16 @@ public class ContentExchangeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected class TestHandler extends AbstractHandler {
|
protected class TestHandler extends AbstractHandler {
|
||||||
private final String resourcePath;
|
private final String resourcePath;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public TestHandler(String repositoryPath) {
|
public TestHandler(String repositoryPath) {
|
||||||
this.resourcePath = repositoryPath;
|
this.resourcePath = repositoryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String target, Request baseRequest,
|
public void handle(String target, Request baseRequest,
|
||||||
HttpServletRequest request, HttpServletResponse response)
|
HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -31,94 +33,126 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public class ErrorStatusTest
|
public class ErrorStatusTest
|
||||||
extends ContentExchangeTest
|
extends ContentExchangeTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPutBadRequest()
|
public void testPutBadRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPutFail(HttpStatus.BAD_REQUEST_400);
|
doPutFail(HttpStatus.BAD_REQUEST_400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPutUnauthorized()
|
public void testPutUnauthorized()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPutFail(HttpStatus.UNAUTHORIZED_401);
|
doPutFail(HttpStatus.UNAUTHORIZED_401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPutForbidden()
|
public void testPutForbidden()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPutFail(HttpStatus.FORBIDDEN_403);
|
doPutFail(HttpStatus.FORBIDDEN_403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPutNotFound()
|
public void testPutNotFound()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPutFail(HttpStatus.NOT_FOUND_404);
|
doPutFail(HttpStatus.NOT_FOUND_404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPutServerError()
|
public void testPutServerError()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPutFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
doPutFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGetBadRequest()
|
public void testGetBadRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doGetFail(HttpStatus.BAD_REQUEST_400);
|
doGetFail(HttpStatus.BAD_REQUEST_400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGetUnauthorized()
|
public void testGetUnauthorized()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doGetFail(HttpStatus.UNAUTHORIZED_401);
|
doGetFail(HttpStatus.UNAUTHORIZED_401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGetNotFound()
|
public void testGetNotFound()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doGetFail(HttpStatus.NOT_FOUND_404);
|
doGetFail(HttpStatus.NOT_FOUND_404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGetServerError()
|
public void testGetServerError()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doGetFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
doGetFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPostBadRequest()
|
public void testPostBadRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPostFail(HttpStatus.BAD_REQUEST_400);
|
doPostFail(HttpStatus.BAD_REQUEST_400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPostUnauthorized()
|
public void testPostUnauthorized()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPostFail(HttpStatus.UNAUTHORIZED_401);
|
doPostFail(HttpStatus.UNAUTHORIZED_401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPostForbidden()
|
public void testPostForbidden()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPostFail(HttpStatus.FORBIDDEN_403);
|
doPostFail(HttpStatus.FORBIDDEN_403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPostNotFound()
|
public void testPostNotFound()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPostFail(HttpStatus.NOT_FOUND_404);
|
doPostFail(HttpStatus.NOT_FOUND_404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testPostServerError()
|
public void testPostServerError()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
doPostFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
doPostFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void doPutFail(int status)
|
protected void doPutFail(int status)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -140,6 +174,7 @@ public class ErrorStatusTest
|
||||||
assertEquals(status, responseStatus);
|
assertEquals(status, responseStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void doGetFail(int status)
|
protected void doGetFail(int status)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -164,6 +199,7 @@ public class ErrorStatusTest
|
||||||
assertEquals(status, responseStatus);
|
assertEquals(status, responseStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void doPostFail(int status)
|
protected void doPostFail(int status)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -185,6 +221,7 @@ public class ErrorStatusTest
|
||||||
assertEquals(status, responseStatus);
|
assertEquals(status, responseStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void configureServer(Server server)
|
protected void configureServer(Server server)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -208,7 +245,9 @@ public class ErrorStatusTest
|
||||||
server.setHandler( handlers );
|
server.setHandler( handlers );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected static class StatusHandler extends AbstractHandler {
|
protected static class StatusHandler extends AbstractHandler {
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String target, Request baseRequest,
|
public void handle(String target, Request baseRequest,
|
||||||
HttpServletRequest request, HttpServletResponse response)
|
HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -21,8 +23,6 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.client.security.Realm;
|
import org.eclipse.jetty.client.security.Realm;
|
||||||
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
|
@ -31,13 +31,13 @@ import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class HttpGetRedirectTest
|
public class HttpGetRedirectTest
|
||||||
extends TestCase
|
|
||||||
{
|
{
|
||||||
private static String _content =
|
private static String _content =
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
|
||||||
|
@ -62,6 +62,8 @@ public class HttpGetRedirectTest
|
||||||
private String _requestUrl2;
|
private String _requestUrl2;
|
||||||
private RedirectHandler _handler;
|
private RedirectHandler _handler;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -81,6 +83,8 @@ public class HttpGetRedirectTest
|
||||||
_handler._toURL=_protocol+"://localhost:"+connector.getLocalPort()+ "/moved.txt";
|
_handler._toURL=_protocol+"://localhost:"+connector.getLocalPort()+ "/moved.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -91,6 +95,8 @@ public class HttpGetRedirectTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGet() throws Exception
|
public void testGet() throws Exception
|
||||||
{
|
{
|
||||||
startClient(_realm);
|
startClient(_realm);
|
||||||
|
@ -115,6 +121,7 @@ public class HttpGetRedirectTest
|
||||||
stopClient();
|
stopClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void configureServer(Server server)
|
protected void configureServer(Server server)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -128,6 +135,7 @@ public class HttpGetRedirectTest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void startClient(Realm realm)
|
protected void startClient(Realm realm)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -139,6 +147,7 @@ public class HttpGetRedirectTest
|
||||||
_client.start();
|
_client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void stopClient()
|
protected void stopClient()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -149,22 +158,26 @@ public class HttpGetRedirectTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected String getBasePath()
|
protected String getBasePath()
|
||||||
{
|
{
|
||||||
return _docRoot.getAbsolutePath();
|
return _docRoot.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void setProtocol(String protocol)
|
protected void setProtocol(String protocol)
|
||||||
{
|
{
|
||||||
_protocol = protocol;
|
_protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void setRealm(Realm realm)
|
protected void setRealm(Realm realm)
|
||||||
{
|
{
|
||||||
_realm = realm;
|
_realm = realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private static class RedirectHandler
|
private static class RedirectHandler
|
||||||
extends AbstractHandler
|
extends AbstractHandler
|
||||||
{
|
{
|
||||||
|
@ -174,6 +187,7 @@ public class HttpGetRedirectTest
|
||||||
private int _redirectCount = 0;
|
private int _redirectCount = 0;
|
||||||
private String _toURL;
|
private String _toURL;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public RedirectHandler( final int code, final String fromURI, final String toURL, final int maxRedirects )
|
public RedirectHandler( final int code, final String fromURI, final String toURL, final int maxRedirects )
|
||||||
{
|
{
|
||||||
this._code = code;
|
this._code = code;
|
||||||
|
@ -186,6 +200,7 @@ public class HttpGetRedirectTest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
|
@ -21,8 +25,10 @@ public class NonBlockingHttpExchangeCancelTest extends AbstractHttpExchangeCance
|
||||||
{
|
{
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Before
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
httpClient = new HttpClient();
|
httpClient = new HttpClient();
|
||||||
|
@ -30,13 +36,16 @@ public class NonBlockingHttpExchangeCancelTest extends AbstractHttpExchangeCance
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@After
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
httpClient.stop();
|
httpClient.stop();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected HttpClient getHttpClient()
|
protected HttpClient getHttpClient()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -25,8 +28,6 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.client.security.Realm;
|
import org.eclipse.jetty.client.security.Realm;
|
||||||
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
|
@ -45,16 +46,16 @@ import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Functional testing for HttpExchange.
|
* Functional testing for HttpExchange.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SecurityListenerTest extends TestCase
|
public class SecurityListenerTest
|
||||||
{
|
{
|
||||||
|
|
||||||
private Server _server;
|
private Server _server;
|
||||||
private int _port;
|
private int _port;
|
||||||
private HttpClient _httpClient;
|
private HttpClient _httpClient;
|
||||||
|
@ -62,8 +63,9 @@ public class SecurityListenerTest extends TestCase
|
||||||
private Realm _jettyRealm;
|
private Realm _jettyRealm;
|
||||||
private static final String APP_CONTEXT = "localhost /";
|
private static final String APP_CONTEXT = "localhost /";
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void setUp() throws Exception
|
@Before
|
||||||
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
startServer();
|
startServer();
|
||||||
_httpClient=new HttpClient();
|
_httpClient=new HttpClient();
|
||||||
|
@ -92,13 +94,16 @@ public class SecurityListenerTest extends TestCase
|
||||||
_httpClient.setRealmResolver( new SimpleRealmResolver(_jettyRealm) );
|
_httpClient.setRealmResolver( new SimpleRealmResolver(_jettyRealm) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void tearDown() throws Exception
|
@After
|
||||||
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
stopServer();
|
stopServer();
|
||||||
_httpClient.stop();
|
_httpClient.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
// @Test
|
||||||
public void xtestPerf() throws Exception
|
public void xtestPerf() throws Exception
|
||||||
{
|
{
|
||||||
sender(1);
|
sender(1);
|
||||||
|
@ -112,6 +117,7 @@ public class SecurityListenerTest extends TestCase
|
||||||
sender(10000);
|
sender(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void sender(final int nb) throws Exception
|
public void sender(final int nb) throws Exception
|
||||||
{
|
{
|
||||||
final CountDownLatch latch=new CountDownLatch(nb);
|
final CountDownLatch latch=new CountDownLatch(nb);
|
||||||
|
@ -204,6 +210,8 @@ public class SecurityListenerTest extends TestCase
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testDestinationSecurityCaching() throws Exception
|
public void testDestinationSecurityCaching() throws Exception
|
||||||
{
|
{
|
||||||
final CyclicBarrier barrier = new CyclicBarrier(2);
|
final CyclicBarrier barrier = new CyclicBarrier(2);
|
||||||
|
@ -248,6 +256,7 @@ public class SecurityListenerTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public static void copyStream(InputStream in, OutputStream out)
|
public static void copyStream(InputStream in, OutputStream out)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -269,6 +278,7 @@ public class SecurityListenerTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private void startServer() throws Exception
|
private void startServer() throws Exception
|
||||||
{
|
{
|
||||||
_server = new Server();
|
_server = new Server();
|
||||||
|
@ -332,7 +342,7 @@ public class SecurityListenerTest extends TestCase
|
||||||
_port = connector.getLocalPort();
|
_port = connector.getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private void stopServer() throws Exception
|
private void stopServer() throws Exception
|
||||||
{
|
{
|
||||||
_server.stop();
|
_server.stop();
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -28,8 +31,6 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.client.security.HashRealmResolver;
|
import org.eclipse.jetty.client.security.HashRealmResolver;
|
||||||
import org.eclipse.jetty.client.security.Realm;
|
import org.eclipse.jetty.client.security.Realm;
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
|
@ -49,11 +50,15 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.ssl.SslSocketConnector;
|
import org.eclipse.jetty.server.ssl.SslSocketConnector;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Functional testing.
|
* Functional testing.
|
||||||
*/
|
*/
|
||||||
public class SslSecurityListenerTest extends TestCase
|
public class SslSecurityListenerTest
|
||||||
{
|
{
|
||||||
protected Server _server;
|
protected Server _server;
|
||||||
protected int _port;
|
protected int _port;
|
||||||
|
@ -62,8 +67,9 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
protected int _type = HttpClient.CONNECTOR_SOCKET;
|
protected int _type = HttpClient.CONNECTOR_SOCKET;
|
||||||
private static final String APP_CONTEXT = "localhost /";
|
private static final String APP_CONTEXT = "localhost /";
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void setUp() throws Exception
|
@Before
|
||||||
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
startServer();
|
startServer();
|
||||||
_httpClient = new HttpClient();
|
_httpClient = new HttpClient();
|
||||||
|
@ -73,16 +79,19 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
|
|
||||||
_jettyRealm = new Realm()
|
_jettyRealm = new Realm()
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
return "MyRealm";
|
return "MyRealm";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public String getPrincipal()
|
public String getPrincipal()
|
||||||
{
|
{
|
||||||
return "jetty";
|
return "jetty";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public String getCredentials()
|
public String getCredentials()
|
||||||
{
|
{
|
||||||
return "jetty";
|
return "jetty";
|
||||||
|
@ -94,8 +103,9 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
_httpClient.setRealmResolver(resolver);
|
_httpClient.setRealmResolver(resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void tearDown() throws Exception
|
@After
|
||||||
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
_httpClient.stop();
|
_httpClient.stop();
|
||||||
|
@ -103,6 +113,8 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
stopServer();
|
stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testSslGet() throws Exception
|
public void testSslGet() throws Exception
|
||||||
{
|
{
|
||||||
// TODO Resolve problems on IBM JVM https://bugs.eclipse.org/bugs/show_bug.cgi?id=304532
|
// TODO Resolve problems on IBM JVM https://bugs.eclipse.org/bugs/show_bug.cgi?id=304532
|
||||||
|
@ -117,6 +129,7 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
|
|
||||||
ContentExchange httpExchange = new ContentExchange(true)
|
ContentExchange httpExchange = new ContentExchange(true)
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected void onResponseComplete() throws IOException
|
protected void onResponseComplete() throws IOException
|
||||||
{
|
{
|
||||||
|
@ -138,6 +151,7 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void startServer() throws Exception
|
protected void startServer() throws Exception
|
||||||
{
|
{
|
||||||
_server = new Server();
|
_server = new Server();
|
||||||
|
@ -180,7 +194,7 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
|
|
||||||
Handler testHandler = new AbstractHandler()
|
Handler testHandler = new AbstractHandler()
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
// System.err.println("passed authentication!\n"+((Request)request).getConnection().getRequestFields());
|
// System.err.println("passed authentication!\n"+((Request)request).getConnection().getRequestFields());
|
||||||
|
@ -216,6 +230,7 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
_port = connector.getLocalPort();
|
_port = connector.getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public static void copyStream(InputStream in, OutputStream out)
|
public static void copyStream(InputStream in, OutputStream out)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -237,6 +252,7 @@ public class SslSecurityListenerTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private void stopServer() throws Exception
|
private void stopServer() throws Exception
|
||||||
{
|
{
|
||||||
_server.stop();
|
_server.stop();
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
@ -21,8 +23,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
import org.eclipse.jetty.io.Buffer;
|
import org.eclipse.jetty.io.Buffer;
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
|
@ -34,11 +34,15 @@ import org.eclipse.jetty.websocket.WebSocket;
|
||||||
import org.eclipse.jetty.websocket.WebSocketBuffers;
|
import org.eclipse.jetty.websocket.WebSocketBuffers;
|
||||||
import org.eclipse.jetty.websocket.WebSocketConnectionD00;
|
import org.eclipse.jetty.websocket.WebSocketConnectionD00;
|
||||||
import org.eclipse.jetty.websocket.WebSocketHandler;
|
import org.eclipse.jetty.websocket.WebSocketHandler;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Functional testing for HttpExchange.
|
* Functional testing for HttpExchange.
|
||||||
*/
|
*/
|
||||||
public class WebSocketUpgradeTest extends TestCase
|
public class WebSocketUpgradeTest
|
||||||
{
|
{
|
||||||
protected Server _server;
|
protected Server _server;
|
||||||
protected int _port;
|
protected int _port;
|
||||||
|
@ -49,8 +53,9 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
protected TestWebSocket _websocket;
|
protected TestWebSocket _websocket;
|
||||||
final BlockingQueue<Object> _results = new ArrayBlockingQueue<Object>(100);
|
final BlockingQueue<Object> _results = new ArrayBlockingQueue<Object>(100);
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void setUp() throws Exception
|
@Before
|
||||||
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
startServer();
|
startServer();
|
||||||
_httpClient=new HttpClient();
|
_httpClient=new HttpClient();
|
||||||
|
@ -62,25 +67,29 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
_httpClient.start();
|
_httpClient.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* ------------------------------------------------------------ */
|
||||||
protected void tearDown() throws Exception
|
@After
|
||||||
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
_httpClient.stop();
|
_httpClient.stop();
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
stopServer();
|
stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Test
|
||||||
public void testGetWithContentExchange() throws Exception
|
public void testGetWithContentExchange() throws Exception
|
||||||
{
|
{
|
||||||
final WebSocket clientWS = new WebSocket.OnTextMessage()
|
final WebSocket clientWS = new WebSocket.OnTextMessage()
|
||||||
{
|
{
|
||||||
Connection _connection;
|
Connection _connection;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onClose(int closeCode, String message)
|
public void onClose(int closeCode, String message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onOpen(Connection connection)
|
public void onOpen(Connection connection)
|
||||||
{
|
{
|
||||||
_connection=connection;
|
_connection=connection;
|
||||||
|
@ -88,6 +97,7 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
_results.add(_connection);
|
_results.add(_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onMessage(String data)
|
public void onMessage(String data)
|
||||||
{
|
{
|
||||||
_results.add("clientWS.onMessage");
|
_results.add("clientWS.onMessage");
|
||||||
|
@ -126,6 +136,7 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private void waitFor(int results)
|
private void waitFor(int results)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -176,6 +187,7 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void newServer() throws Exception
|
protected void newServer() throws Exception
|
||||||
{
|
{
|
||||||
_server=new Server();
|
_server=new Server();
|
||||||
|
@ -186,11 +198,13 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
_server.setConnectors(new Connector[] { _connector });
|
_server.setConnectors(new Connector[] { _connector });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
protected void startServer() throws Exception
|
protected void startServer() throws Exception
|
||||||
{
|
{
|
||||||
newServer();
|
newServer();
|
||||||
_handler= new WebSocketHandler()
|
_handler= new WebSocketHandler()
|
||||||
{
|
{
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
|
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
|
||||||
{
|
{
|
||||||
_websocket = new TestWebSocket();
|
_websocket = new TestWebSocket();
|
||||||
|
@ -203,18 +217,19 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
_port=_connector.getLocalPort();
|
_port=_connector.getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
private void stopServer() throws Exception
|
private void stopServer() throws Exception
|
||||||
{
|
{
|
||||||
_server.stop();
|
_server.stop();
|
||||||
_server.join();
|
_server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
class TestWebSocket implements WebSocket.OnTextMessage
|
class TestWebSocket implements WebSocket.OnTextMessage
|
||||||
{
|
{
|
||||||
Connection _connection;
|
Connection _connection;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onOpen(Connection connection)
|
public void onOpen(Connection connection)
|
||||||
{
|
{
|
||||||
_connection=connection;
|
_connection=connection;
|
||||||
|
@ -223,18 +238,21 @@ public class WebSocketUpgradeTest extends TestCase
|
||||||
_results.add(this);
|
_results.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onMessage(final String data)
|
public void onMessage(final String data)
|
||||||
{
|
{
|
||||||
_results.add("serverWS.onMessage");
|
_results.add("serverWS.onMessage");
|
||||||
_results.add(data);
|
_results.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void onClose(int code, String message)
|
public void onClose(int code, String message)
|
||||||
{
|
{
|
||||||
_results.add("onDisconnect");
|
_results.add("onDisconnect");
|
||||||
_webSockets.remove(this);
|
_webSockets.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
public void sendMessage(String msg) throws IOException
|
public void sendMessage(String msg) throws IOException
|
||||||
{
|
{
|
||||||
_connection.sendMessage(msg);
|
_connection.sendMessage(msg);
|
||||||
|
|
Loading…
Reference in New Issue