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.PermanentRedirect.*; 016 017import java.net.*; 018 019import org.apache.juneau.annotation.BeanIgnore; 020import org.apache.juneau.http.annotation.*; 021 022/** 023 * Represents an <c>HTTP 308 Permanent Redirect</c> response. 024 * 025 * <p> 026 * The request and all future requests should be repeated using another URI. 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. 027 * So, for example, submitting a form to a permanently redirected resource may continue smoothly. 028 */ 029@Response(code=CODE, description=MESSAGE) 030@BeanIgnore 031public class PermanentRedirect extends HttpResponse { 032 033 /** HTTP status code */ 034 public static final int CODE = 308; 035 036 /** Default message */ 037 public static final String MESSAGE = "Permanent Redirect"; 038 039 /** Reusable instance. */ 040 public static final PermanentRedirect INSTANCE = new PermanentRedirect(); 041 042 private final URI location; 043 044 /** 045 * Constructor using HTTP-standard message. 046 */ 047 public PermanentRedirect() { 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 PermanentRedirect(String message) { 059 super(message); 060 this.location = null; 061 } 062 063 /** 064 * Constructor using custom message. 065 * @param message Message to send as the response. 066 * @param location <c>Location</c> header value. 067 */ 068 public PermanentRedirect(String message, URI location) { 069 super(message); 070 this.location = location; 071 } 072 073 /** 074 * Constructor. 075 * @param location <c>Location</c> header value. 076 */ 077 public PermanentRedirect(URI location) { 078 this(MESSAGE, location); 079 } 080 081 /** 082 * @return <c>Location</c> header value. 083 */ 084 @ResponseHeader(name="Location", description="New location of resource.") 085 public URI getLocation() { 086 return location; 087 } 088}