jdk/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpServer.java
author clanger
Fri, 23 Dec 2016 07:54:05 +0100
changeset 42944 641db7ce5057
parent 34894 3248b89d1921
child 45132 db2f2d72cd4f
permissions -rw-r--r--
8171906: Changes for 8148023 break AIX build Reviewed-by: goetz, bpb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20742
diff changeset
     2
 * Copyright (c) 2005, 2013, 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.net.httpserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.net.httpserver.spi.HttpServerProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class implements a simple HTTP server. A HttpServer is bound to an IP address
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * and port number and listens for incoming TCP connections from clients on this address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The sub-class {@link HttpsServer} implements a server which handles HTTPS requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * One or more {@link HttpHandler} objects must be associated with a server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in order to process requests. Each such HttpHandler is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * with a root URI path which represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * location of the application or service on this server. The mapping of a handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to a HttpServer is encapsulated by a {@link HttpContext} object. HttpContexts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * are created by calling {@link #createContext(String,HttpHandler)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Any request for which no handler can be found is rejected with a 404 response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Management of threads can be done external to this object by providing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * {@link java.util.concurrent.Executor} object. If none is provided a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * implementation is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <a name="mapping_description"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <b>Mapping request URIs to HttpContext paths</b><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * When a HTTP request is received,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the appropriate HttpContext (and handler) is located by finding the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * whose path is the longest matching prefix of the request URI's path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Paths are matched literally, which means that the strings are compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * case sensitively, and with no conversion to or from any encoded forms.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 25859
diff changeset
    61
 * For example. Given a HttpServer with the following HttpContexts configured.
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 25859
diff changeset
    62
 * <table>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <tr><td><i>Context</i></td><td><i>Context path</i></td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <tr><td>ctx1</td><td>"/"</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <tr><td>ctx2</td><td>"/apps/"</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <tr><td>ctx3</td><td>"/apps/foo/"</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the following table shows some request URIs and which, if any context they would
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 25859
diff changeset
    70
 * match with.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <tr><td><i>Request URI</i></td><td><i>Matches context</i></td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <tr><td>"http://foo.com/apps/foo/bar"</td><td>ctx3</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <tr><td>"http://foo.com/apps/Foo/bar"</td><td>no match, wrong case</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <tr><td>"http://foo.com/apps/app1"</td><td>ctx2</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <tr><td>"http://foo.com/foo"</td><td>ctx1</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <b>Note about socket backlogs</b><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * When binding to an address and port number, the application can also specify an integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <i>backlog</i> parameter. This represents the maximum number of incoming TCP connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * which the system will queue internally. Connections are queued while they are waiting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * be accepted by the HttpServer. When the limit is reached, further connections may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * rejected (or possibly ignored) by the underlying TCP implementation. Setting the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * backlog value is a compromise between efficient resource usage in the TCP layer (not setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * it too high) and allowing adequate throughput of incoming requests (not setting it too low).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public abstract class HttpServer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected HttpServer () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * creates a HttpServer instance which is initially not bound to any local address/port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * The HttpServer is acquired from the currently installed {@link HttpServerProvider}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The server must be bound using {@link #bind(InetSocketAddress,int)} before it can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static HttpServer create () throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return create (null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Create a <code>HttpServer</code> instance which will bind to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * specified {@link java.net.InetSocketAddress} (IP address and port number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * A maximum backlog can also be specified. This is the maximum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * queued incoming connections to allow on the listening socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Queued TCP connections exceeding this limit may be rejected by the TCP implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The HttpServer is acquired from the currently installed {@link HttpServerProvider}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param addr the address to listen on, if <code>null</code> then bind() must be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *  to set the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param backlog the socket backlog. If this value is less than or equal to zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *          then a system default value is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws BindException if the server cannot bind to the requested address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *          or if the server is already bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static HttpServer create (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        InetSocketAddress addr, int backlog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    ) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        HttpServerProvider provider = HttpServerProvider.provider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return provider.createHttpServer (addr, backlog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Binds a currently unbound HttpServer to the given address and port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * A maximum backlog can also be specified. This is the maximum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * queued incoming connections to allow on the listening socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Queued TCP connections exceeding this limit may be rejected by the TCP implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param addr the address to listen on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param backlog the socket backlog. If this value is less than or equal to zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *          then a system default value is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @throws BindException if the server cannot bind to the requested address or if the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *          is already bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @throws NullPointerException if addr is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public abstract void bind (InetSocketAddress addr, int backlog) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Starts this server in a new background thread. The background thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * inherits the priority, thread group and context class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * of the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public abstract void start () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * sets this server's {@link java.util.concurrent.Executor} object. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Executor must be established before {@link #start()} is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * All HTTP requests are handled in tasks given to the executor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * If this method is not called (before start()) or if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * called with a <code>null</code> Executor, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * a default implementation is used, which uses the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * which was created by the {@link #start()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param executor the Executor to set, or <code>null</code> for  default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *          implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws IllegalStateException if the server is already started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public abstract void setExecutor (Executor executor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * returns this server's Executor object if one was specified with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * {@link #setExecutor(Executor)}, or <code>null</code> if none was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the Executor established for this server or <code>null</code> if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public abstract Executor getExecutor () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * stops this server by closing the listening socket and disallowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * any new exchanges from being processed. The method will then block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * until all current exchange handlers have completed or else when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * approximately <i>delay</i> seconds have elapsed (whichever happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * sooner). Then, all open TCP connections are closed, the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * thread created by start() exits, and the method returns.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 25859
diff changeset
   183
     * Once stopped, a HttpServer cannot be re-used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param delay the maximum time in seconds to wait until exchanges have finished.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @throws IllegalArgumentException if delay is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public abstract void stop (int delay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Creates a HttpContext. A HttpContext represents a mapping from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * URI path to a exchange handler on this HttpServer. Once created, all requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * received by the server for the path will be handled by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * the given handler object. The context is identified by the path, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * can later be removed from the server using this with the {@link #removeContext(String)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The path specifies the root URI path for this context. The first character of path must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * '/'. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * The class overview describes how incoming request URIs are <a href="#mapping_description">mapped</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * to HttpContext instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param path the root URI path to associate the context with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param handler the handler to invoke for incoming requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @throws IllegalArgumentException if path is invalid, or if a context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          already exists for this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @throws NullPointerException if either path, or handler are <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public abstract HttpContext createContext (String path, HttpHandler handler) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Creates a HttpContext without initially specifying a handler. The handler must later be specified using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * {@link HttpContext#setHandler(HttpHandler)}.  A HttpContext represents a mapping from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * URI path to an exchange handler on this HttpServer. Once created, and when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the handler has been set, all requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * received by the server for the path will be handled by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the handler object. The context is identified by the path, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * can later be removed from the server using this with the {@link #removeContext(String)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * The path specifies the root URI path for this context. The first character of path must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * '/'. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * The class overview describes how incoming request URIs are <a href="#mapping_description">mapped</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * to HttpContext instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param path the root URI path to associate the context with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @throws IllegalArgumentException if path is invalid, or if a context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *          already exists for this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @throws NullPointerException if path is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public abstract HttpContext createContext (String path) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Removes the context identified by the given path from the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Removing a context does not affect exchanges currently being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * but prevents new ones from being accepted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param path the path of the handler to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws IllegalArgumentException if no handler corresponding to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *          path exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @throws NullPointerException if path is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public abstract void removeContext (String path) throws IllegalArgumentException ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Removes the given context from the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Removing a context does not affect exchanges currently being processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * but prevents new ones from being accepted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param context the context to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws NullPointerException if context is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public abstract void removeContext (HttpContext context) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * returns the address this server is listening on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return the address/port number the server is listening on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public abstract InetSocketAddress getAddress() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}