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.*;
016import static org.apache.juneau.internal.StringUtils.*;
017
018import java.net.*;
019import java.text.*;
020
021import org.apache.juneau.annotation.BeanIgnore;
022import org.apache.juneau.http.annotation.*;
023
024/**
025 * Represents an <c>HTTP 303 See Other</c> response.
026 *
027 * <p>
028 * The response to the request can be found under another URI using the GET method.
029 * 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.
030 */
031@Response(code=CODE, description=MESSAGE)
032@BeanIgnore
033public class SeeOther extends HttpResponse {
034
035   /** HTTP status code */
036   public static final int CODE = 303;
037
038   /** Default message */
039   public static final String MESSAGE = "See Other";
040
041   /** Reusable instance. */
042   public static final SeeOther INSTANCE = new SeeOther();
043
044   private final URI location;
045
046   /**
047    * Constructor using HTTP-standard message.
048    */
049   public SeeOther() {
050      this(MESSAGE, null);
051   }
052
053   /**
054    * Constructor with no redirect.
055    * <p>
056    * Used for end-to-end interfaces.
057    *
058    * @param message Message to send as the response.
059    */
060   public SeeOther(String message) {
061      super(message);
062      this.location = null;
063   }
064
065   /**
066    * Constructor using custom message.
067    *
068    * @param message Message to send as the response.
069    * @param location <c>Location</c> header value.
070    */
071   public SeeOther(String message, URI location) {
072      super(message);
073      this.location = location;
074   }
075
076   /**
077    * Constructor.
078    *
079    * @param message Message to send as the response.
080    * @param uri URI containing {@link MessageFormat}-style arguments.
081    * @param uriArgs {@link MessageFormat}-style arguments.
082    */
083   public SeeOther(String message, String uri, Object uriArgs) {
084      this(message, toURI(format(uri.toString(), uriArgs)));
085   }
086
087   /**
088    * Constructor.
089    *
090    * @param location <c>Location</c> header value.
091    */
092   public SeeOther(URI location) {
093      this(MESSAGE, location);
094   }
095
096   /**
097    * Constructor.
098    *
099    * @param uri URI containing {@link MessageFormat}-style arguments.
100    * @param uriArgs {@link MessageFormat}-style arguments.
101    */
102   public SeeOther(String uri, Object uriArgs) {
103      this(toURI(format(uri.toString(), uriArgs)));
104   }
105
106   /**
107    * @return <c>Location</c> header value.
108    */
109   @ResponseHeader(name="Location", description="Other location.")
110   public URI getLocation() {
111      return location;
112   }
113}