test/jdk/java/net/httpclient/HttpEchoHandler.java
changeset 49765 ee6f7a61f3a5
parent 47216 71c04702a3d5
child 52121 934969c63223
child 56451 9585061fdb04
equal deleted inserted replaced
49707:f7fd051519ac 49765:ee6f7a61f3a5
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import com.sun.net.httpserver.*;
    24 import com.sun.net.httpserver.*;
    25 import java.net.*;
    25 import java.net.*;
    26 import jdk.incubator.http.*;
    26 import java.net.http.*;
    27 import java.io.*;
    27 import java.io.*;
    28 import java.util.concurrent.*;
    28 import java.util.concurrent.*;
    29 import javax.net.ssl.*;
    29 import javax.net.ssl.*;
    30 import java.nio.file.*;
    30 import java.nio.file.*;
    31 import java.util.HashSet;
    31 import java.util.HashSet;
    32 import java.util.LinkedList;
    32 import java.util.LinkedList;
    33 import java.util.List;
    33 import java.util.List;
    34 import java.util.Random;
    34 import java.util.Random;
    35 import jdk.testlibrary.SimpleSSLContext;
    35 import jdk.testlibrary.SimpleSSLContext;
    36 import static jdk.incubator.http.HttpRequest.*;
    36 import static java.net.http.HttpRequest.*;
    37 import static jdk.incubator.http.HttpResponse.*;
    37 import static java.net.http.HttpResponse.*;
    38 import java.util.logging.ConsoleHandler;
    38 import java.util.logging.ConsoleHandler;
    39 import java.util.logging.Level;
    39 import java.util.logging.Level;
    40 import java.util.logging.Logger;
    40 import java.util.logging.Logger;
    41 
    41 
    42 public class HttpEchoHandler implements HttpHandler {
    42 public class HttpEchoHandler implements HttpHandler {
       
    43     static final Path CWD = Paths.get(".");
       
    44 
    43     public HttpEchoHandler() {}
    45     public HttpEchoHandler() {}
    44 
    46 
    45     @Override
    47     @Override
    46     public void handle(HttpExchange t)
    48     public void handle(HttpExchange t)
    47             throws IOException {
    49             throws IOException {
    51             Headers map = t.getRequestHeaders();
    53             Headers map = t.getRequestHeaders();
    52             Headers map1 = t.getResponseHeaders();
    54             Headers map1 = t.getResponseHeaders();
    53             map1.add("X-Hello", "world");
    55             map1.add("X-Hello", "world");
    54             map1.add("X-Bye", "universe");
    56             map1.add("X-Bye", "universe");
    55             String fixedrequest = map.getFirst("XFixed");
    57             String fixedrequest = map.getFirst("XFixed");
    56             File outfile = File.createTempFile("foo", "bar");
    58             File outfile = Files.createTempFile(CWD, "foo", "bar").toFile();
    57             FileOutputStream fos = new FileOutputStream(outfile);
    59             FileOutputStream fos = new FileOutputStream(outfile);
    58             int count = (int) is.transferTo(fos);
    60             int count = (int) is.transferTo(fos);
    59             is.close();
    61             is.close();
    60             fos.close();
    62             fos.close();
    61             InputStream is1 = new FileInputStream(outfile);
    63             InputStream is1 = new FileInputStream(outfile);