summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorThomas Becker2011-09-26 11:48:52 (EDT)
committer Jesse McConnell2011-09-26 18:50:27 (EDT)
commite14cc536ee9021a622a163cd5fbb17b6e48d292f (patch)
tree9b3d0fbd591d0b0d8997180001e6b7e7fa30af3e
parent5e6a9ea78e5030d7dc29de2a1122065f02cb731c (diff)
downloadorg.eclipse.jetty.project-e14cc536ee9021a622a163cd5fbb17b6e48d292f.zip
org.eclipse.jetty.project-e14cc536ee9021a622a163cd5fbb17b6e48d292f.tar.gz
org.eclipse.jetty.project-e14cc536ee9021a622a163cd5fbb17b6e48d292f.tar.bz2
JETTY-1415: Start/Stop Server and Client only once in test, code format
-rw-r--r--jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ProxyRule.java14
-rw-r--r--jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ProxyRuleTest.java39
2 files changed, 28 insertions, 25 deletions
diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ProxyRule.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ProxyRule.java
index a913ca6..65efebc 100644
--- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ProxyRule.java
+++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ProxyRule.java
@@ -18,12 +18,11 @@ import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EofException;
-import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
-public class ProxyRule extends PatternRule implements Rule.ApplyURI
+public class ProxyRule extends PatternRule
{
private static final Logger _log = Log.getLogger(ProxyRule.class);
@@ -44,6 +43,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
_DontProxyHeaders.add("upgrade");
}
+ /* ------------------------------------------------------------ */
public ProxyRule()
{
_handling = true;
@@ -51,6 +51,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
}
+ /* ------------------------------------------------------------ */
private void initializeClient() throws Exception
{
_client = new HttpClient();
@@ -65,11 +66,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
return new HttpURI(_proxyTo + uri);
}
- public void applyURI(Request request, String oldTarget, String newTarget) throws IOException
- {
- System.out.println("applyURI called");
- }
-
+ /* ------------------------------------------------------------ */
@Override
protected String apply(String target, HttpServletRequest request, final HttpServletResponse response) throws IOException
{
@@ -229,6 +226,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
return target;
}
+ /* ------------------------------------------------------------ */
private HttpURI createUrl(HttpServletRequest request, final int debug) throws MalformedURLException
{
String uri = request.getRequestURI();
@@ -244,6 +242,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
return url;
}
+ /* ------------------------------------------------------------ */
private boolean createHeaders(final HttpServletRequest request, final int debug, HttpExchange exchange)
{
// check connection header
@@ -315,6 +314,7 @@ public class ProxyRule extends PatternRule implements Rule.ApplyURI
return hasContent;
}
+ /* ------------------------------------------------------------ */
public void setProxyTo(String proxyTo)
{
this._proxyTo = proxyTo;
diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ProxyRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ProxyRuleTest.java
index 65a0b4d..d4c90be 100644
--- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ProxyRuleTest.java
+++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ProxyRuleTest.java
@@ -30,22 +30,22 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
public class ProxyRuleTest
{
- private ProxyRule _rule;
- private RewriteHandler _handler;
- private Server _proxyServer = new Server();
- private Connector _proxyServerConnector = new SelectChannelConnector();
- private Server _targetServer = new Server();
- private Connector _targetServerConnector = new SelectChannelConnector();
- private HttpClient httpClient = new HttpClient();
-
- @Before
- public void init() throws Exception
+ private static ProxyRule _rule;
+ private static RewriteHandler _handler;
+ private static Server _proxyServer = new Server();
+ private static Connector _proxyServerConnector = new SelectChannelConnector();
+ private static Server _targetServer = new Server();
+ private static Connector _targetServerConnector = new SelectChannelConnector();
+ private static HttpClient _httpClient = new HttpClient();
+
+ @BeforeClass
+ public static void setupOnce() throws Exception
{
_targetServer.addConnector(_targetServerConnector);
_targetServer.setHandler(new AbstractHandler()
@@ -73,12 +73,15 @@ public class ProxyRuleTest
_proxyServer.setHandler(_handler);
_proxyServer.start();
- httpClient.start();
+ _httpClient.start();
}
- @After
- public void destroy()
+ @AfterClass
+ public static void destroy() throws Exception
{
+ _httpClient.stop();
+ _proxyServer.stop();
+ _targetServer.stop();
_rule = null;
}
@@ -92,7 +95,7 @@ public class ProxyRuleTest
String url = "http://localhost:" + _proxyServerConnector.getLocalPort() + "/foo?body=" + URLEncoder.encode(body,"UTF-8");
exchange.setURL(url);
- httpClient.send(exchange);
+ _httpClient.send(exchange);
assertEquals(HttpExchange.STATUS_COMPLETED,exchange.waitForDone());
assertEquals("uri: / some content",exchange.getResponseContent());
assertEquals(201,exchange.getResponseStatus());
@@ -108,7 +111,7 @@ public class ProxyRuleTest
String url = "http://localhost:" + _proxyServerConnector.getLocalPort() + "/foo/bar/foobar?body=" + URLEncoder.encode(body,"UTF-8");
exchange.setURL(url);
- httpClient.send(exchange);
+ _httpClient.send(exchange);
assertEquals(HttpExchange.STATUS_COMPLETED,exchange.waitForDone());
assertEquals("uri: /bar/foobar some content",exchange.getResponseContent());
assertEquals(201,exchange.getResponseStatus());
@@ -123,7 +126,7 @@ public class ProxyRuleTest
String url = "http://localhost:" + _proxyServerConnector.getLocalPort() + "/foobar?body=" + URLEncoder.encode(body,"UTF-8");
exchange.setURL(url);
- httpClient.send(exchange);
+ _httpClient.send(exchange);
assertEquals(HttpExchange.STATUS_COMPLETED,exchange.waitForDone());
assertEquals(404,exchange.getResponseStatus());
}