001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http.exception;
014
015import static org.apache.juneau.http.exception.NetworkAuthenticationRequired.*;
016
017import java.text.*;
018
019import org.apache.juneau.http.annotation.*;
020
021/**
022 * Exception representing an HTTP 511 (Network Authentication Required).
023 *
024 * <p>
025 * The client needs to authenticate to gain network access.
026 * <br>Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
027 */
028@Response(code=CODE, description=MESSAGE)
029public class NetworkAuthenticationRequired extends HttpException {
030   private static final long serialVersionUID = 1L;
031
032   /** HTTP status code */
033   public static final int CODE = 511;
034
035   /** Default message */
036   public static final String MESSAGE = "Network Authentication Required";
037
038   /**
039    * Constructor.
040    *
041    * @param cause The cause.  Can be <jk>null</jk>.
042    * @param msg The message.  Can be <jk>null</jk>.
043    * @param args Optional {@link MessageFormat}-style arguments in the message.
044    */
045   public NetworkAuthenticationRequired(Throwable cause, String msg, Object...args) {
046      super(cause, CODE, msg, args);
047   }
048
049   /**
050    * Constructor.
051    *
052    * @param msg The message.  Can be <jk>null</jk>.
053    */
054   public NetworkAuthenticationRequired(String msg) {
055      super(msg);
056      setStatus(CODE);
057   }
058
059   /**
060    * Constructor.
061    */
062   public NetworkAuthenticationRequired() {
063      this((Throwable)null, MESSAGE);
064   }
065
066   /**
067    * Constructor.
068    *
069    * @param msg The message.  Can be <jk>null</jk>.
070    * @param args Optional {@link MessageFormat}-style arguments in the message.
071    */
072   public NetworkAuthenticationRequired(String msg, Object...args) {
073      this(null, msg, args);
074   }
075
076   /**
077    * Constructor.
078    *
079    * @param cause The cause.  Can be <jk>null</jk>.
080    */
081   public NetworkAuthenticationRequired(Throwable cause) {
082      this(cause, null);
083   }
084}