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.response;
014
015import static org.apache.juneau.http.response.SeeOther.*;
016
017import java.net.*;
018
019import org.apache.juneau.annotation.BeanIgnore;
020import org.apache.juneau.http.annotation.*;
021
022/**
023 * Represents an <c>HTTP 303 See Other</c> response.
024 *
025 * <p>
026 * The response to the request can be found under another URI using the GET method.
027 * When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
028 */
029@Response(code=CODE, description=MESSAGE)
030@BeanIgnore
031public class SeeOther extends HttpResponse {
032
033   /** HTTP status code */
034   public static final int CODE = 303;
035
036   /** Default message */
037   public static final String MESSAGE = "See Other";
038
039   /** Reusable instance. */
040   public static final SeeOther INSTANCE = new SeeOther();
041
042   private final URI location;
043
044   /**
045    * Constructor using HTTP-standard message.
046    */
047   public SeeOther() {
048      this(MESSAGE, null);
049   }
050
051   /**
052    * Constructor with no redirect.
053    * <p>
054    * Used for end-to-end interfaces.
055    *
056    * @param message Message to send as the response.
057    */
058   public SeeOther(String message) {
059      super(message);
060      this.location = null;
061   }
062
063   /**
064    * Constructor using custom message.
065    *
066    * @param message Message to send as the response.
067    * @param location <c>Location</c> header value.
068    */
069   public SeeOther(String message, URI location) {
070      super(message);
071      this.location = location;
072   }
073
074   /**
075    * Constructor.
076    *
077    * @param location <c>Location</c> header value.
078    */
079   public SeeOther(URI location) {
080      this(MESSAGE, location);
081   }
082
083   /**
084    * @return <c>Location</c> header value.
085    */
086   @ResponseHeader(name="Location", description="Other location.")
087   public URI getLocation() {
088      return location;
089   }
090
091   //------------------------------------------------------------------------------------------------------------------
092   // Fluent setters.
093   //------------------------------------------------------------------------------------------------------------------
094
095   // <FluentSetters>
096
097   @Override /* GENERATED - HttpResponse */
098   public SeeOther header(String name, Object val) {
099      super.header(name, val);
100      return this;
101   }
102
103   // </FluentSetters>
104}