jdk/test/java/net/ResponseCache/ResponseCacheTest.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 7668 d4a77089c587
child 28242 0cbef7c46996
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6115
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5165
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @summary Unit test for java.net.ResponseCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4837267
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Yingxian Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Request should get serviced by the cache handler. Response get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * saved through the cache handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class ResponseCacheTest implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    ServerSocket ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static URL url1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static URL url2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static String FNPrefix, OutFNPrefix;
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    45
    static List<Closeable> streams = new ArrayList<>();
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    46
    static List<File> files = new ArrayList<>();
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Our "http" server to return a 404 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public void run() {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    51
        Socket s = null;
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    52
        FileInputStream fis = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        try {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    54
            s = ss.accept();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            InputStream is = s.getInputStream ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            BufferedReader r = new BufferedReader(new InputStreamReader(is));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            String x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            while ((x=r.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                if (x.length() ==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            PrintStream out = new PrintStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                 new BufferedOutputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                    s.getOutputStream() ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            /* send file2.1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            File file2 = new File(FNPrefix+"file2.1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            out.print("HTTP/1.1 200 OK\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            out.print("Content-Type: text/html; charset=iso-8859-1\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            out.print("Content-Length: "+file2.length()+"\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            out.print("Connection: close\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            out.print("\r\n");
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    75
            fis = new FileInputStream(file2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            byte[] buf = new byte[(int)file2.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            while ((len = fis.read(buf)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                out.print(new String(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            s.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            ss.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            e.printStackTrace();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    88
        } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    89
            try { ss.close(); } catch (IOException unused) {}
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    90
            try { s.close(); } catch (IOException unused) {}
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
    91
            try { fis.close(); } catch (IOException unused) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
static class NameVerifier implements HostnameVerifier {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public boolean verify(String hostname, SSLSession session) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    ResponseCacheTest() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /* start the server */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        ss = new ServerSocket(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        (new Thread(this)).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /* establish http connection to server */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        url1 = new URL("http://localhost/file1.cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        HttpURLConnection http = (HttpURLConnection)url1.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        InputStream is = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("request headers: "+http.getRequestProperties());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        System.out.println("responsecode is :"+http.getResponseCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Map<String,List<String>> headers1 = http.getHeaderFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            is = http.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } catch (IOException ioex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            throw new RuntimeException(ioex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        String x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        File fileout = new File(OutFNPrefix+"file1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        PrintStream out = new PrintStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                 new BufferedOutputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                    new FileOutputStream(fileout)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        while ((x=r.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            out.print(x+"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        http.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // testing ResponseCacheHandler.put()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        url2 = new URL("http://localhost:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                       Integer.toString(ss.getLocalPort())+"/file2.1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        http = (HttpURLConnection)url2.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        System.out.println("responsecode2 is :"+http.getResponseCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Map<String,List<String>> headers2 = http.getHeaderFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            is = http.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } catch (IOException ioex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new RuntimeException(ioex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        r = new BufferedReader(new InputStreamReader(is));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        fileout = new File(OutFNPrefix+"file2.2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        out = new PrintStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                 new BufferedOutputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                    new FileOutputStream(fileout)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        while ((x=r.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            out.print(x+"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // assert (headers1 == headers2 && file1 == file2.2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        File file1 = new File(OutFNPrefix+"file1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        File file2 = new File(OutFNPrefix+"file2.2");
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   155
        files.add(file1);
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   156
        files.add(file2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        System.out.println("headers1"+headers1+"\nheaders2="+headers2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (!headers1.equals(headers2) || file1.length() != file2.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new RuntimeException("test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static void main(String args[]) throws Exception {
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   164
        try {
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   165
            ResponseCache.setDefault(new MyResponseCache());
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   166
            FNPrefix = System.getProperty("test.src", ".")+"/";
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   167
            OutFNPrefix = System.getProperty("test.scratch", ".")+"/";
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   168
            new ResponseCacheTest();
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   169
        } finally{
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   170
            ResponseCache.setDefault(null);
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   171
            for (Closeable c: streams) {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   172
                try { c.close(); } catch (IOException unused) {}
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   173
            }
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   174
            for (File f: files) {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   175
                f.delete();
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   176
            }
5165
5693cc1e95c6 6937703: java/net regression test issues with samevm
chegar
parents: 2
diff changeset
   177
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    static class MyResponseCache extends ResponseCache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        public CacheResponse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        get(URI uri, String rqstMethod, Map<String,List<String>> rqstHeaders)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (uri.equals(ParseUtil.toURI(url1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return new MyCacheResponse(FNPrefix+"file1.cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        public CacheRequest put(URI uri, URLConnection conn)  throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // save cache to file2.cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // 1. serialize headers into file2.cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            // 2. write data to file2.cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return new MyCacheRequest(OutFNPrefix+"file2.cache", conn.getHeaderFields());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    static class MyCacheResponse extends CacheResponse {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        FileInputStream fis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        Map<String,List<String>> headers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public MyCacheResponse(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                fis = new FileInputStream(new File(filename));
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   204
                streams.add(fis);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                ObjectInputStream ois = new ObjectInputStream(fis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                headers = (Map<String,List<String>>)ois.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                // throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public InputStream getBody() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return fis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public Map<String,List<String>> getHeaders() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return headers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    static class MyCacheRequest extends CacheRequest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        FileOutputStream fos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        public MyCacheRequest(String filename, Map<String,List<String>> rspHeaders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                File file = new File(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                fos = new FileOutputStream(file);
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   227
                streams.add(fos);
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   228
                files.add(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                ObjectOutputStream oos = new ObjectOutputStream(fos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                oos.writeObject(rspHeaders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        public OutputStream getBody() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return fos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        public void abort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // no op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}