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 <code>HTTP 303 See Other</code> 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 using custom message. 055 * 056 * @param message Message to send as the response. 057 * @param location <code>Location</code> header value. 058 */ 059 public SeeOther(String message, URI location) { 060 super(message); 061 this.location = location; 062 } 063 064 /** 065 * Constructor. 066 * 067 * @param message Message to send as the response. 068 * @param uri URI containing {@link MessageFormat}-style arguments. 069 * @param uriArgs {@link MessageFormat}-style arguments. 070 */ 071 public SeeOther(String message, String uri, Object uriArgs) { 072 this(message, toURI(format(uri.toString(), uriArgs))); 073 } 074 075 /** 076 * Constructor. 077 * 078 * @param location <code>Location</code> header value. 079 */ 080 public SeeOther(URI location) { 081 this(MESSAGE, location); 082 } 083 084 /** 085 * Constructor. 086 * 087 * @param uri URI containing {@link MessageFormat}-style arguments. 088 * @param uriArgs {@link MessageFormat}-style arguments. 089 */ 090 public SeeOther(String uri, Object uriArgs) { 091 this(toURI(format(uri.toString(), uriArgs))); 092 } 093 094 /** 095 * @return <code>Location</code> header value. 096 */ 097 @ResponseHeader(name="Location", description="Other location.") 098 public URI getLocation() { 099 return location; 100 } 101}