diff options
author | Jan Bartel | 2012-12-17 07:40:50 +0000 |
---|---|---|
committer | Jan Bartel | 2012-12-17 07:40:50 +0000 |
commit | 43c9bba86d076cae33f4fa21a3effd127c03ae67 (patch) | |
tree | 98ed90cabebbdf63b98ca8c89d0582426ecd6b1b /jetty-servlets | |
parent | f9e76b162057e9548f3ea807c31b047e05d2a095 (diff) | |
download | org.eclipse.jetty.project-43c9bba86d076cae33f4fa21a3effd127c03ae67.tar.gz org.eclipse.jetty.project-43c9bba86d076cae33f4fa21a3effd127c03ae67.tar.xz org.eclipse.jetty.project-43c9bba86d076cae33f4fa21a3effd127c03ae67.zip |
393158 java.lang.IllegalStateException when sending an empty InputStream
Diffstat (limited to 'jetty-servlets')
-rw-r--r-- | jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java new file mode 100644 index 0000000000..5e19f1460a --- /dev/null +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java @@ -0,0 +1,140 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 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 static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * TransparentProxyTest + * + * + */ +public class TransparentProxyTest +{ + + + protected Server server; + protected Server proxyServer; + + public static class ServletA extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/plain"); + resp.getWriter().println("ok"); + } + } + + @Before + public void setUp () throws Exception + { + //set up the target server + server = new Server(); + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setPort(8080); + server.addConnector(connector); + ServletContextHandler handler = new ServletContextHandler(server, "/"); + handler.addServlet(ServletA.class, "/a"); + server.setHandler(handler); + server.start(); + + + //set up the server that proxies to the target server + proxyServer = new Server(); + SelectChannelConnector proxyConnector = new SelectChannelConnector(); + proxyConnector.setPort(8081); + proxyServer.addConnector(proxyConnector); + ServletContextHandler proxyHandler = new ServletContextHandler(proxyServer, "/"); + proxyHandler.addServlet(new ServletHolder(new ProxyServlet.Transparent("/", "http", "127.0.0.1", 8080, "/")), "/"); + proxyServer.setHandler(proxyHandler); + proxyServer.start(); + + } + + + @After + public void tearDown() throws Exception + { + server.stop(); + proxyServer.stop(); + } + + + @Test + public void testDirectNoContentType() throws Exception + { + // Direct request without Content-Type set works + URL url = new URL("http://localhost:8080/a"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + assertEquals(200, con.getResponseCode()); + } + + + @Test + public void testDirectWithContentType() throws Exception + { + // Direct request with Content-Type works + URL url = new URL("http://localhost:8080/a"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + assertEquals(200, con.getResponseCode()); + } + + @Test + public void testProxiedWithoutContentType() throws Exception + { + // Proxied request without Content-Type set works + URL url = new URL("http://localhost:8081/a"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + assertEquals(200, con.getResponseCode()); + System.err.println (con.getContentType()); + } + + @Test + public void testProxiedWithContentType() throws Exception + { + // Proxied request with Content-Type set fails + + URL url = new URL("http://localhost:8081/a"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + assertEquals(200, con.getResponseCode()); + System.err.println(con.getContentType()); + + } +} |