1 /*
   2  * Copyright (c) 2004, 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 
  26 package java.net;
  27 
  28 import java.io.IOException;
  29 
  30 /**
  31  * Thrown to indicate that a HTTP request needs to be retried
  32  * but cannot be retried automatically, due to streaming mode
  33  * being enabled.
  34  *
  35  * @author  Michael McMahon
  36  * @since   1.5
  37  */
  38 public
  39 class HttpRetryException extends IOException {
  40     @java.io.Serial
  41     private static final long serialVersionUID = -9186022286469111381L;
  42 
  43     private int responseCode;
  44     private String location;
  45 
  46     /**
  47      * Constructs a new {@code HttpRetryException} from the
  48      * specified response code and exception detail message
  49      *
  50      * @param   detail   the detail message.
  51      * @param   code   the HTTP response code from server.
  52      */
  53     public HttpRetryException(String detail, int code) {
  54         super(detail);
  55         responseCode = code;
  56     }
  57 
  58     /**
  59      * Constructs a new {@code HttpRetryException} with detail message
  60      * responseCode and the contents of the Location response header field.
  61      *
  62      * @param   detail   the detail message.
  63      * @param   code   the HTTP response code from server.
  64      * @param   location   the URL to be redirected to
  65      */
  66     public HttpRetryException(String detail, int code, String location) {
  67         super (detail);
  68         responseCode = code;
  69         this.location = location;
  70     }
  71 
  72     /**
  73      * Returns the http response code
  74      *
  75      * @return  The http response code.
  76      */
  77     public int responseCode() {
  78         return responseCode;
  79     }
  80 
  81     /**
  82      * Returns a string explaining why the http request could
  83      * not be retried.
  84      *
  85      * @return  The reason string
  86      */
  87     public String getReason() {
  88         return super.getMessage();
  89     }
  90 
  91     /**
  92      * Returns the value of the Location header field if the
  93      * error resulted from redirection.
  94      *
  95      * @return The location string
  96      */
  97     public String getLocation() {
  98         return location;
  99     }
 100 }