01: /*
02: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
03: * California. All rights reserved.
04: *
05: * Permission to use, copy, modify, and distribute this software and its
06: * documentation for any purpose, without fee, and without written agreement is
07: * hereby granted, provided that the above copyright notice and the following
08: * two paragraphs appear in all copies of this software.
09: *
10: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
11: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
13: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14: *
15: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
19: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20: *
21: * Author: Matt Welsh <mdw@cs.berkeley.edu>
22: *
23: */
24:
25: package seda.sandStorm.lib.http;
26:
27: import seda.sandStorm.api.*;
28: import seda.sandStorm.lib.aSocket.*;
29: import seda.sandStorm.core.*;
30:
31: import java.util.*;
32: import java.io.*;
33: import java.net.*;
34:
35: /**
36: * An httpResponse corresponding to a '301 Moved Permanently' response.
37: *
38: * @author Matt Welsh
39: */
40: public class httpRedirectResponse extends httpResponse implements
41: httpConst, QueueElementIF {
42:
43: private static final boolean DEBUG = false;
44: private String oldURL;
45: private String newURL;
46:
47: /**
48: * Create a redirect response corresponding to the given request with
49: * the given new URL.
50: */
51: public httpRedirectResponse(httpRequest request, String newURL) {
52: super (httpResponse.RESPONSE_REDIRECT, "text/html");
53: this .oldURL = request.getURL();
54: this .newURL = newURL;
55:
56: String str = "<html><head><title>301 Moved Permanently</title></head><body bgcolor=white><font face=\"helvetica\"><big><big><b>301 Moved Permanently</b></big></big><p>The URL you requested:<p><blockquote><tt>"
57: + oldURL
58: + "</tt></blockquote><p>has moved permanently to:<p><blockquote><tt><a href=\""
59: + newURL
60: + "\">"
61: + newURL
62: + "</a></tt></blockquote></body></html>\n";
63: BufferElement mypayload = new BufferElement(str.getBytes());
64: setPayload(mypayload);
65: }
66:
67: protected String getEntityHeader() {
68: return "Location: " + newURL + CRLF + "Connection: close"
69: + CRLF;
70: }
71:
72: public String toString() {
73: return "httpRedirectResponse [oldURL=" + oldURL + ", newURL="
74: + newURL + "]";
75: }
76:
77: }
|