test/jdk/java/net/URLConnection/HandleContentTypeWithAttrs.java
author aefimov
Thu, 08 Aug 2019 21:58:11 +0100
changeset 57686 70f5cbb711a9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225430: Replace wildcard address with loopback or local host in tests - part 14 Reviewed-by: dfuchs, chegar, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2019, 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: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4160200
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    27
 * @summary Make sure URLConnection.getContentHandler
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *     can handle MIME types with attributes
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    29
 * @library /test/lib
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 7668
diff changeset
    30
 * @modules java.base/sun.net.www java.base/sun.net.www.content.text
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.net.www.content.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.net.www.MessageHeader;
38780
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 30820
diff changeset
    36
import static java.net.Proxy.NO_PROXY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    38
import jdk.test.lib.net.URIBuilder;
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    39
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class HandleContentTypeWithAttrs {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public HandleContentTypeWithAttrs (int port) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        // Request echo.html from myHttpServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        // In the header of the response, we make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // the content type have some attributes.
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    49
        url = URIBuilder.newBuilder()
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    50
                .scheme("http")
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    51
                .loopback()
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    52
                .port(port)
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    53
                .path("/echo.html")
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
    54
                .toURL();
38780
fa8bf2d62d36 8158525: Update a few java/net tests to use the loopback address instead of the host address
chegar
parents: 30820
diff changeset
    55
        URLConnection urlConn = url.openConnection(NO_PROXY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // the method getContent() calls the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // getContentHandler(). With the fix, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // getContentHandler() gets the correct content
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // handler for our response -  it should be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        // PlainText conten handler; without the fix,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // it gets the UnknownContent handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        // So based on what the getContent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // returns, we know whether getContentHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // can handle content type with attributes or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        Object obj = urlConn.getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (!(obj instanceof PlainTextInputStream))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            throw new Exception("Cannot get the correct content handler.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static void main(String [] argv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // Start myHttpServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        myHttpServer testServer = new myHttpServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        testServer.startServer(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        int serverPort = testServer.getServerLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        new HandleContentTypeWithAttrs(serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
// myHttpServer is pretty much like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
// sun.net.www.httpd.BasicHttpServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
// But we only need it to handle one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
// simple request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
class myHttpServer implements Runnable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** Socket for communicating with client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public Socket clientSocket = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private Thread serverInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private ServerSocket serverSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /** Stream for printing to the client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public PrintStream clientOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /** Buffered stream for reading replies from client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public InputStream clientInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    static URL defaultContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /** Close an open connection to the client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        clientSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        clientSocket = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        clientInput = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        clientOutput = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    final public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (serverSocket != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                // wait for incoming request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                Socket ns = serverSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                myHttpServer n = (myHttpServer)clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                n.serverSocket = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                n.clientSocket = ns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                new Thread(n).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                System.out.print("Server failure\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                e.printStackTrace();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   122
            } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   123
                try { serverSocket.close(); } catch(IOException unused) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                clientOutput = new PrintStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    new BufferedOutputStream(clientSocket.getOutputStream()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                             false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                clientInput = new BufferedInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                             clientSocket.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                serviceRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                // System.out.print("Service handler failure\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                // e.printStackTrace();
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   137
            } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   138
                try { close(); }  catch(IOException unused) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /** Start a server on port <i>port</i>.  It will call serviceRequest()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        for each new connection. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    final public void startServer(int port) throws IOException {
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   146
        serverSocket = new ServerSocket(port, 50,
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   147
                InetAddress.getLoopbackAddress());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        serverInstance = new Thread(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        serverInstance.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    final public int getServerLocalPort() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (serverSocket != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return serverSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        throw new Exception("serverSocket is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    MessageHeader mh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    final public void serviceRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        //totalConnections++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            mh = new MessageHeader(clientInput);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            String cmd = mh.findValue(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // if (cmd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            //  error("Missing command " + mh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            //  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            int fsp = cmd.indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            // if (fsp < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            //  error("Syntax error in command: " + cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            //  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            //  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            String k = cmd.substring(0, fsp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            int nsp = cmd.indexOf(' ', fsp + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            String p1, p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (nsp > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                p1 = cmd.substring(fsp + 1, nsp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                p2 = cmd.substring(nsp + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                p1 = cmd.substring(fsp + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                p2 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // expectsMime = p2 != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (k.equalsIgnoreCase("get"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                getRequest(new URL(defaultContext, p1), p2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                //      error("Unknown command: " + k + " (" + cmd + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } catch(IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            // totally ignore IOException.  They're usually client crashes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            //  error("Exception: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /** Satisfy one get request.  It is invoked with the clientInput and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        clientOutput streams initialized.  This method handles one client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        connection. When it is done, it can simply exit. The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        server just echoes it's input. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected void getRequest(URL u, String param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (u.getFile().equals("/echo.html")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
               startHtml("Echo reply");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
               clientOutput.print("<p>URL was " + u.toExternalForm() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
               clientOutput.print("<p>Socket was " + clientSocket + "\n<p><pre>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
               mh.print(clientOutput);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            System.out.print("Failed on "+u.getFile()+"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      * Clone this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            // this shouldn't happen, since we are Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public myHttpServer () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        try {
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   231
            defaultContext = URIBuilder.newBuilder()
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   232
                    .scheme("http")
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   233
                    .loopback()
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   234
                    .path("/")
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   235
                    .toURL();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch(Exception e) {
57686
70f5cbb711a9 8225430: Replace wildcard address with loopback or local host in tests - part 14
aefimov
parents: 47216
diff changeset
   237
            System.out.println("Failed to construct default URL context: "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                               + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    // Make the content type have some attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void startHtml(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        clientOutput.print("HTTP/1.0 200 Document follows\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                           "Server: Java/" + getClass().getName() + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                           "Content-type: text/plain; charset=Shift_JIS \n\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}