Path: blob/master/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpContext.java
41159 views
/*1* Copyright (c) 2005, 2020, 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;26import java.util.List;27import java.util.Map;2829/**30* {@code HttpContext} represents a mapping between the root {@link java.net.URI}31* path of an application to a {@link HttpHandler} which is invoked to handle32* requests destined for that path on the associated {@link HttpServer} or33* {@link HttpsServer}.34*35* <p> {@code HttpContext} instances are created by the create methods in36* {@code HttpServer} and {@code HttpsServer}.37*38* <p> A chain of {@link Filter} objects can be added to a {@code HttpContext}.39* All exchanges processed by the context can be pre- and post-processed by each40* {@code Filter} in the chain.41*42* @since 1.643*/44public abstract class HttpContext {4546/**47* Constructor for subclasses to call.48*/49protected HttpContext() {50}5152/**53* Returns the handler for this context.54*55* @return the {@code HttpHandler} for this context56*/57public abstract HttpHandler getHandler();5859/**60* Sets the handler for this context, if not already set.61*62* @param handler the handler to set for this context63* @throws IllegalArgumentException if the context for this handler is already set.64* @throws NullPointerException if handler is {@code null}65*/66public abstract void setHandler(HttpHandler handler);6768/**69* Returns the path this context was created with.70*71* @return the context of this path72*/73public abstract String getPath();7475/**76* Returns the server this context was created with.77*78* @return the context of this server79*/80public abstract HttpServer getServer();8182/**83* Returns a mutable {@link Map}, which can be used to pass configuration84* and other data to {@link Filter} modules and to the context's exchange85* handler.86*87* <p> Every attribute stored in this {@code Map} will be visible to every88* {@code HttpExchange} processed by this context.89*90* @return a {@code Map} containing the attributes of this context91*/92public abstract Map<String,Object> getAttributes() ;9394/**95* Returns this context's {@link List} of {@linkplain Filter filters}. This96* is the actual list used by the server when dispatching requests so97* modifications to this list immediately affect the the handling of exchanges.98*99* @return a {@link List} containing the filters of this context100*/101public abstract List<Filter> getFilters();102103/**104* Sets the {@link Authenticator} for this {@code HttpContext}. Once an authenticator105* is establised on a context, all client requests must be authenticated,106* and the given object will be invoked to validate each request. Each call107* to this method replaces any previous value set.108*109* @param auth the {@code Authenticator} to set. If {@code null} then any previously110* set {@code Authenticator} is removed, and client authentication111* will no longer be required.112* @return the previous {@code Authenticator}, if any set, or {@code null} otherwise.113*/114public abstract Authenticator setAuthenticator(Authenticator auth);115116/**117* Returns the currently set {@link Authenticator} for this context118* if one exists.119*120* @return this {@linkplain HttpContext HttpContext's} {@code Authenticator},121* or {@code null} if none is set122*/123public abstract Authenticator getAuthenticator();124}125126127