HttpsServer.java revision 10444:f08705540498
1/*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.net.httpserver;
27
28import java.net.*;
29import java.io.*;
30import java.nio.*;
31import java.security.*;
32import java.nio.channels.*;
33import java.util.*;
34import java.util.concurrent.*;
35import javax.net.ssl.*;
36import com.sun.net.httpserver.spi.*;
37
38/**
39 * This class is an extension of {@link HttpServer} which provides
40 * support for HTTPS. <p>
41 * A HttpsServer must have an associated {@link HttpsConfigurator} object
42 * which is used to establish the SSL configuration for the SSL connections.
43 * <p>
44 * All other configuration is the same as for HttpServer.
45 * @since 1.6
46 */
47
48@jdk.Exported
49public abstract class HttpsServer extends HttpServer {
50
51    /**
52     */
53    protected HttpsServer () {
54    }
55
56    /**
57     * creates a HttpsServer instance which is initially not bound to any local address/port.
58     * The HttpsServer is acquired from the currently installed {@link HttpServerProvider}
59     * The server must be bound using {@link #bind(InetSocketAddress,int)} before it can be used.
60     * The server must also have a HttpsConfigurator established with {@link #setHttpsConfigurator(HttpsConfigurator)}
61     * @throws IOException
62     */
63    public static HttpsServer create () throws IOException {
64        return create (null, 0);
65    }
66
67    /**
68     * Create a <code>HttpsServer</code> instance which will bind to the
69     * specified {@link java.net.InetSocketAddress} (IP address and port number)
70     *
71     * A maximum backlog can also be specified. This is the maximum number of
72     * queued incoming connections to allow on the listening socket.
73     * Queued TCP connections exceeding this limit may be rejected by the TCP implementation.
74     * The HttpsServer is acquired from the currently installed {@link HttpServerProvider}
75     * The server must have a HttpsConfigurator established with {@link #setHttpsConfigurator(HttpsConfigurator)}
76     *
77     * @param addr the address to listen on, if <code>null</code> then bind() must be called
78     *  to set the address
79     * @param backlog the socket backlog. If this value is less than or equal to zero,
80     *          then a system default value is used.
81     * @throws BindException if the server cannot bind to the requested address,
82     *          or if the server is already bound.
83     * @throws IOException
84     */
85
86    public static HttpsServer create (
87        InetSocketAddress addr, int backlog
88    ) throws IOException {
89        HttpServerProvider provider = HttpServerProvider.provider();
90        return provider.createHttpsServer (addr, backlog);
91    }
92
93    /**
94     * Sets this server's {@link HttpsConfigurator} object.
95     * @param config the HttpsConfigurator to set
96     * @throws NullPointerException if config is null.
97     */
98    public abstract void setHttpsConfigurator (HttpsConfigurator config) ;
99
100    /**
101     * Gets this server's {@link HttpsConfigurator} object, if it has been set.
102     * @return the HttpsConfigurator for this server, or <code>null</code> if not set.
103     */
104    public abstract HttpsConfigurator getHttpsConfigurator ();
105}
106