0N/A/*
3261N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6270015
2612N/A * @run main/othervm Test8a
0N/A * @summary Light weight HTTP server
0N/A */
0N/A
0N/Aimport com.sun.net.httpserver.*;
0N/A
0N/Aimport java.util.concurrent.*;
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport javax.net.ssl.*;
0N/A
0N/A/**
0N/A * Test POST large file via fixed len encoding
0N/A */
0N/A
0N/Apublic class Test8a extends Test {
0N/A
0N/A public static void main (String[] args) throws Exception {
0N/A //Logger log = Logger.getLogger ("com.sun.net.httpserver");
0N/A //ConsoleHandler h = new ConsoleHandler();
0N/A //h.setLevel (Level.INFO);
0N/A //log.addHandler (h);
0N/A //log.setLevel (Level.INFO);
2612N/A HttpsServer server = null;
2612N/A ExecutorService executor = null;
2612N/A try {
2612N/A Handler handler = new Handler();
2612N/A InetSocketAddress addr = new InetSocketAddress (0);
2612N/A server = HttpsServer.create (addr, 0);
2612N/A HttpContext ctx = server.createContext ("/test", handler);
2612N/A executor = Executors.newCachedThreadPool();
2612N/A SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
2612N/A server.setHttpsConfigurator(new HttpsConfigurator (ssl));
2612N/A server.setExecutor (executor);
2612N/A server.start ();
0N/A
2612N/A URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
2612N/A System.out.print ("Test8a: " );
2612N/A HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
2612N/A urlc.setDoOutput (true);
2612N/A urlc.setRequestMethod ("POST");
2612N/A urlc.setHostnameVerifier (new DummyVerifier());
2612N/A urlc.setSSLSocketFactory (ssl.getSocketFactory());
2612N/A OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
2612N/A for (int i=0; i<SIZE; i++) {
2612N/A os.write (i % 250);
2612N/A }
2612N/A os.close();
2612N/A int resp = urlc.getResponseCode();
2612N/A if (resp != 200) {
2612N/A throw new RuntimeException ("test failed response code");
2612N/A }
2612N/A InputStream is = urlc.getInputStream ();
2612N/A for (int i=0; i<SIZE; i++) {
2612N/A int f = is.read();
2612N/A if (f != (i % 250)) {
2612N/A System.out.println ("Setting error(" +f +")("+i+")" );
2612N/A error = true;
2612N/A break;
2612N/A }
2612N/A }
2612N/A is.close();
2612N/A } finally {
2612N/A delay();
2612N/A if (server != null) server.stop(2);
2612N/A if (executor != null) executor.shutdown();
0N/A }
0N/A if (error) {
0N/A throw new RuntimeException ("test failed error");
0N/A }
0N/A System.out.println ("OK");
0N/A
0N/A }
0N/A
0N/A public static boolean error = false;
0N/A //final static int SIZE = 999999;
0N/A final static int SIZE = 9999;
0N/A
0N/A static class Handler implements HttpHandler {
0N/A int invocation = 1;
0N/A public void handle (HttpExchange t)
0N/A throws IOException
0N/A {
0N/A System.out.println ("Handler.handle");
0N/A InputStream is = t.getRequestBody();
0N/A Headers map = t.getRequestHeaders();
0N/A Headers rmap = t.getResponseHeaders();
0N/A int c, count=0;
0N/A while ((c=is.read ()) != -1) {
0N/A if (c != (count % 250)) {
0N/A System.out.println ("Setting error 1");
0N/A error = true;
0N/A break;
0N/A }
0N/A count ++;
0N/A }
0N/A if (count != SIZE) {
0N/A System.out.println ("Setting error 2");
0N/A error = true;
0N/A }
0N/A is.close();
0N/A t.sendResponseHeaders (200, SIZE);
0N/A System.out.println ("Sending 200 OK");
0N/A OutputStream os = new BufferedOutputStream(t.getResponseBody(), 8000);
0N/A for (int i=0; i<SIZE; i++) {
0N/A os.write (i % 250);
0N/A }
0N/A os.close();
0N/A System.out.println ("Finished");
0N/A }
0N/A }
0N/A}