Path: blob/master/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpsServer.java
41159 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.net.httpserver;2627import java.io.IOException;28import java.net.BindException;29import java.net.InetSocketAddress;30import com.sun.net.httpserver.spi.HttpServerProvider;3132/**33* This class is an extension of {@link HttpServer} which provides support for34* HTTPS.35*36* <p>A {@code HttpsServer} must have an associated {@link HttpsConfigurator} object37* which is used to establish the SSL configuration for the SSL connections.38*39* <p>All other configuration is the same as for {@code HttpServer}.40*41* @since 1.642*/4344public abstract class HttpsServer extends HttpServer {4546/**47* Constructor for subclasses to call.48*/49protected HttpsServer() {50}5152/**53* Creates a {@code HttpsServer} instance which is initially not bound to any54* local address/port. The {@code HttpsServer} is acquired from the currently55* installed {@link HttpServerProvider}. The server must be bound using56* {@link #bind(InetSocketAddress,int)} before it can be used. The server57* must also have a {@code HttpsConfigurator} established with58* {@link #setHttpsConfigurator(HttpsConfigurator)}.59*60* @return an instance of {@code HttpsServer}61* @throws IOException if an I/O error occurs62*/63public static HttpsServer create() throws IOException {64return create(null, 0);65}6667/**68* Create a {@code HttpsServer} instance which will bind to the specified69* {@link java.net.InetSocketAddress} (IP address and port number).70*71* A maximum backlog can also be specified. This is the maximum number of72* queued incoming connections to allow on the listening socket. Queued TCP73* connections exceeding this limit may be rejected by the TCP implementation.74* The {@code HttpsServer} is acquired from the currently installed75* {@link HttpServerProvider}. The server must have a {@code HttpsConfigurator}76* established with {@link #setHttpsConfigurator(HttpsConfigurator)}.77*78* @param addr the address to listen on, if {@code null} then79* {@link #bind(InetSocketAddress,int)} must be called to set80* the address81* @param backlog the socket backlog. If this value is less than or equal to82* zero, then a system default value is used.83* @return an instance of {@code HttpsServer}84* @throws BindException if the server cannot bind to the requested address,85* or if the server is already bound86* @throws IOException if an I/O error occurs87*/8889public static HttpsServer create(InetSocketAddress addr, int backlog) throws IOException {90HttpServerProvider provider = HttpServerProvider.provider();91return provider.createHttpsServer(addr, backlog);92}9394/**95* Sets this server's {@link HttpsConfigurator} object.96*97* @param config the {@code HttpsConfigurator} to set98* @throws NullPointerException if config is {@code null}99*/100public abstract void setHttpsConfigurator(HttpsConfigurator config);101102/**103* Gets this server's {@link HttpsConfigurator} object, if it has been set.104*105* @return the {@code HttpsConfigurator} for this server, or {@code null} if106* not set107*/108public abstract HttpsConfigurator getHttpsConfigurator();109}110111112