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