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
48public abstract class HttpsServer extends HttpServer {
49
50    /**
51     */
52    protected HttpsServer () {
53    }
54
55    /**
56     * creates a HttpsServer instance which is initially not bound to any local address/port.
57     * The HttpsServer is acquired from the currently installed {@link HttpServerProvider}
58     * The server must be bound using {@link #bind(InetSocketAddress,int)} before it can be used.
59     * The server must also have a HttpsConfigurator established with {@link #setHttpsConfigurator(HttpsConfigurator)}
60     * @throws IOException
61     */
62    public static HttpsServer create () throws IOException {
63        return create (null, 0);
64    }
65
66    /**
67     * Create a <code>HttpsServer</code> instance which will bind to the
68     * specified {@link java.net.InetSocketAddress} (IP address and port number)
69     *
70     * A maximum backlog can also be specified. This is the maximum number of
71     * queued incoming connections to allow on the listening socket.
72     * Queued TCP connections exceeding this limit may be rejected by the TCP implementation.
73     * The HttpsServer is acquired from the currently installed {@link HttpServerProvider}
74     * The server must have a HttpsConfigurator established with {@link #setHttpsConfigurator(HttpsConfigurator)}
75     *
76     * @param addr the address to listen on, if <code>null</code> then bind() must be called
77     *  to set the address
78     * @param backlog the socket backlog. If this value is less than or equal to zero,
79     *          then a system default value is used.
80     * @throws BindException if the server cannot bind to the requested address,
81     *          or if the server is already bound.
82     * @throws IOException
83     */
84
85    public static HttpsServer create (
86        InetSocketAddress addr, int backlog
87    ) throws IOException {
88        HttpServerProvider provider = HttpServerProvider.provider();
89        return provider.createHttpsServer (addr, backlog);
90    }
91
92    /**
93     * Sets this server's {@link HttpsConfigurator} object.
94     * @param config the HttpsConfigurator to set
95     * @throws NullPointerException if config is null.
96     */
97    public abstract void setHttpsConfigurator (HttpsConfigurator config) ;
98
99    /**
100     * Gets this server's {@link HttpsConfigurator} object, if it has been set.
101     * @return the HttpsConfigurator for this server, or <code>null</code> if not set.
102     */
103    public abstract HttpsConfigurator getHttpsConfigurator ();
104}
105