test/jdk/java/net/httpclient/http2/server/Http2EchoHandler.java
branchhttp-client-branch
changeset 56300 13a2ec671e62
parent 56093 22d94c4a3641
child 56451 9585061fdb04
equal deleted inserted replaced
56299:903ff8ec239d 56300:13a2ec671e62
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.*;
    24 import java.io.*;
       
    25 import java.nio.file.Files;
       
    26 import java.nio.file.Path;
       
    27 import java.nio.file.Paths;
       
    28 
    25 import jdk.internal.net.http.common.HttpHeadersImpl;
    29 import jdk.internal.net.http.common.HttpHeadersImpl;
    26 
    30 
    27 public class Http2EchoHandler implements Http2Handler {
    31 public class Http2EchoHandler implements Http2Handler {
       
    32     static final Path CWD = Paths.get(".");
       
    33 
    28     public Http2EchoHandler() {}
    34     public Http2EchoHandler() {}
    29 
    35 
    30     @Override
    36     @Override
    31     public void handle(Http2TestExchange t)
    37     public void handle(Http2TestExchange t)
    32             throws IOException {
    38             throws IOException {
    37             HttpHeadersImpl map = t.getRequestHeaders();
    43             HttpHeadersImpl map = t.getRequestHeaders();
    38             HttpHeadersImpl map1 = t.getResponseHeaders();
    44             HttpHeadersImpl map1 = t.getResponseHeaders();
    39             map1.addHeader("X-Hello", "world");
    45             map1.addHeader("X-Hello", "world");
    40             map1.addHeader("X-Bye", "universe");
    46             map1.addHeader("X-Bye", "universe");
    41             String fixedrequest = map.firstValue("XFixed").orElse(null);
    47             String fixedrequest = map.firstValue("XFixed").orElse(null);
    42             File outfile = File.createTempFile("foo", "bar");
    48             File outfile = Files.createTempFile(CWD, "foo", "bar").toFile();
    43             //System.err.println ("QQQ = " + outfile.toString());
    49             //System.err.println ("QQQ = " + outfile.toString());
    44             FileOutputStream fos = new FileOutputStream(outfile);
    50             FileOutputStream fos = new FileOutputStream(outfile);
    45             int count = (int) is.transferTo(fos);
    51             int count = (int) is.transferTo(fos);
    46             System.err.printf("EchoHandler read %d bytes\n", count);
    52             System.err.printf("EchoHandler read %d bytes\n", count);
    47             is.close();
    53             is.close();