< prev index next >

test/jdk/java/net/httpclient/LightWeightHttpServer.java

Print this page

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * library /test/lib /
 26  * build jdk.test.lib.net.SimpleSSLContext ProxyServer
 27  * compile ../../../com/sun/net/httpserver/LogFilter.java
 28  * compile ../../../com/sun/net/httpserver/EchoHandler.java
 29  * compile ../../../com/sun/net/httpserver/FileServerHandler.java
 30  */
 31 import com.sun.net.httpserver.Headers;
 32 import com.sun.net.httpserver.HttpContext;
 33 import com.sun.net.httpserver.HttpExchange;
 34 import com.sun.net.httpserver.HttpHandler;
 35 import com.sun.net.httpserver.HttpServer;
 36 import com.sun.net.httpserver.HttpsConfigurator;
 37 import com.sun.net.httpserver.HttpsServer;
 38 import java.io.IOException;
 39 import java.io.InputStream;
 40 import java.io.OutputStream;
 41 import java.net.InetAddress;
 42 import java.net.InetSocketAddress;
 43 import java.nio.file.Path;
 44 import java.util.HashSet;
 45 import java.util.concurrent.BrokenBarrierException;
 46 import java.util.concurrent.CyclicBarrier;
 47 import java.util.concurrent.ExecutorService;
 48 import java.util.concurrent.Executors;
 49 import java.util.logging.ConsoleHandler;
 50 import java.util.logging.Level;
 51 import java.util.logging.Logger;
 52 import javax.net.ssl.SSLContext;


 53 import jdk.test.lib.net.SimpleSSLContext;
 54 
 55 public class LightWeightHttpServer {
 56 
 57     static SSLContext ctx;
 58     static HttpServer httpServer;
 59     static HttpsServer httpsServer;
 60     static ExecutorService executor;
 61     static int port;
 62     static int httpsport;
 63     static String httproot;
 64     static String httpsroot;
 65     static ProxyServer proxy;
 66     static int proxyPort;
 67     static RedirectErrorHandler redirectErrorHandler, redirectErrorHandlerSecure;
 68     static RedirectHandler redirectHandler, redirectHandlerSecure;
 69     static DelayHandler delayHandler;
 70     static final String midSizedFilename = "/files/notsobigfile.txt";
 71     static final String smallFilename = "/files/smallfile.txt";
 72     static Path midSizedFile;

 94         HttpContext c2 = httpsServer.createContext("/files", h);
 95         HttpContext c3 = httpServer.createContext("/echo", new EchoHandler());
 96         redirectHandler = new RedirectHandler("/redirect");
 97         redirectHandlerSecure = new RedirectHandler("/redirect");
 98         HttpContext c4 = httpServer.createContext("/redirect", redirectHandler);
 99         HttpContext c41 = httpsServer.createContext("/redirect", redirectHandlerSecure);
100         HttpContext c5 = httpsServer.createContext("/echo", new EchoHandler());
101         HttpContext c6 = httpServer.createContext("/keepalive", new KeepAliveHandler());
102         redirectErrorHandler = new RedirectErrorHandler("/redirecterror");
103         redirectErrorHandlerSecure = new RedirectErrorHandler("/redirecterror");
104         HttpContext c7 = httpServer.createContext("/redirecterror", redirectErrorHandler);
105         HttpContext c71 = httpsServer.createContext("/redirecterror", redirectErrorHandlerSecure);
106         delayHandler = new DelayHandler();
107         HttpContext c8 = httpServer.createContext("/delay", delayHandler);
108         HttpContext c81 = httpsServer.createContext("/delay", delayHandler);
109 
110         executor = Executors.newCachedThreadPool();
111         httpServer.setExecutor(executor);
112         httpsServer.setExecutor(executor);
113         ctx = new SimpleSSLContext().get();
114         httpsServer.setHttpsConfigurator(new HttpsConfigurator(ctx));
115         httpServer.start();
116         httpsServer.start();
117 
118         port = httpServer.getAddress().getPort();
119         System.out.println("HTTP server port = " + port);
120         httpsport = httpsServer.getAddress().getPort();
121         System.out.println("HTTPS server port = " + httpsport);
122         httproot = "http://" + makeServerAuthority(httpServer.getAddress()) + "/";
123         httpsroot = "https://" + makeServerAuthority(httpsServer.getAddress()) + "/";
124 
125         proxy = new ProxyServer(0, false);
126         proxyPort = proxy.getPort();
127         System.out.println("Proxy port = " + proxyPort);
128     }
129 
130     private static String makeServerAuthority(final InetSocketAddress addr) {
131         final String hostIP = addr.getAddress().getHostAddress();
132         // escape for ipv6
133         final String h = hostIP.contains(":") ? "[" + hostIP + "]" : hostIP;
134         return h + ":" + addr.getPort();

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * library /test/lib /
 26  * build jdk.test.lib.net.SimpleSSLContext ProxyServer
 27  * compile ../../../com/sun/net/httpserver/LogFilter.java
 28  * compile ../../../com/sun/net/httpserver/EchoHandler.java
 29  * compile ../../../com/sun/net/httpserver/FileServerHandler.java
 30  */
 31 import com.sun.net.httpserver.Headers;
 32 import com.sun.net.httpserver.HttpContext;
 33 import com.sun.net.httpserver.HttpExchange;
 34 import com.sun.net.httpserver.HttpHandler;
 35 import com.sun.net.httpserver.HttpServer;

 36 import com.sun.net.httpserver.HttpsServer;
 37 import java.io.IOException;
 38 import java.io.InputStream;
 39 import java.io.OutputStream;
 40 import java.net.InetAddress;
 41 import java.net.InetSocketAddress;
 42 import java.nio.file.Path;
 43 import java.util.HashSet;
 44 import java.util.concurrent.BrokenBarrierException;
 45 import java.util.concurrent.CyclicBarrier;
 46 import java.util.concurrent.ExecutorService;
 47 import java.util.concurrent.Executors;
 48 import java.util.logging.ConsoleHandler;
 49 import java.util.logging.Level;
 50 import java.util.logging.Logger;
 51 import javax.net.ssl.SSLContext;
 52 
 53 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 54 import jdk.test.lib.net.SimpleSSLContext;
 55 
 56 public class LightWeightHttpServer {
 57 
 58     static SSLContext ctx;
 59     static HttpServer httpServer;
 60     static HttpsServer httpsServer;
 61     static ExecutorService executor;
 62     static int port;
 63     static int httpsport;
 64     static String httproot;
 65     static String httpsroot;
 66     static ProxyServer proxy;
 67     static int proxyPort;
 68     static RedirectErrorHandler redirectErrorHandler, redirectErrorHandlerSecure;
 69     static RedirectHandler redirectHandler, redirectHandlerSecure;
 70     static DelayHandler delayHandler;
 71     static final String midSizedFilename = "/files/notsobigfile.txt";
 72     static final String smallFilename = "/files/smallfile.txt";
 73     static Path midSizedFile;

 95         HttpContext c2 = httpsServer.createContext("/files", h);
 96         HttpContext c3 = httpServer.createContext("/echo", new EchoHandler());
 97         redirectHandler = new RedirectHandler("/redirect");
 98         redirectHandlerSecure = new RedirectHandler("/redirect");
 99         HttpContext c4 = httpServer.createContext("/redirect", redirectHandler);
100         HttpContext c41 = httpsServer.createContext("/redirect", redirectHandlerSecure);
101         HttpContext c5 = httpsServer.createContext("/echo", new EchoHandler());
102         HttpContext c6 = httpServer.createContext("/keepalive", new KeepAliveHandler());
103         redirectErrorHandler = new RedirectErrorHandler("/redirecterror");
104         redirectErrorHandlerSecure = new RedirectErrorHandler("/redirecterror");
105         HttpContext c7 = httpServer.createContext("/redirecterror", redirectErrorHandler);
106         HttpContext c71 = httpsServer.createContext("/redirecterror", redirectErrorHandlerSecure);
107         delayHandler = new DelayHandler();
108         HttpContext c8 = httpServer.createContext("/delay", delayHandler);
109         HttpContext c81 = httpsServer.createContext("/delay", delayHandler);
110 
111         executor = Executors.newCachedThreadPool();
112         httpServer.setExecutor(executor);
113         httpsServer.setExecutor(executor);
114         ctx = new SimpleSSLContext().get();
115         httpsServer.setHttpsConfigurator(new TestServerConfigurator(addr.getAddress(), ctx));
116         httpServer.start();
117         httpsServer.start();
118 
119         port = httpServer.getAddress().getPort();
120         System.out.println("HTTP server port = " + port);
121         httpsport = httpsServer.getAddress().getPort();
122         System.out.println("HTTPS server port = " + httpsport);
123         httproot = "http://" + makeServerAuthority(httpServer.getAddress()) + "/";
124         httpsroot = "https://" + makeServerAuthority(httpsServer.getAddress()) + "/";
125 
126         proxy = new ProxyServer(0, false);
127         proxyPort = proxy.getPort();
128         System.out.println("Proxy port = " + proxyPort);
129     }
130 
131     private static String makeServerAuthority(final InetSocketAddress addr) {
132         final String hostIP = addr.getAddress().getHostAddress();
133         // escape for ipv6
134         final String h = hostIP.contains(":") ? "[" + hostIP + "]" : hostIP;
135         return h + ":" + addr.getPort();
< prev index next >