001: /*
002: * $Id: RedirectResponse.java,v 1.8 2005/03/07 06:28:19 np145014 Exp $
003: * $Source: /m/portal/ps/srap/src/com/sun/portal/rproxy/connectionhandler/RedirectResponse.java,v $
004: * $Log: RedirectResponse.java,v $
005: * Revision 1.8 2005/03/07 06:28:19 np145014
006: * CR 6223492 Updated P2 portalserver/erproxy SRA should use the monitoring framework and provide monitoring metadata.
007: *
008: * Revision 1.7 2005/03/01 10:33:12 np145014
009: * CR 6224556
010: *
011: * Revision 1.6 2005/03/01 10:17:24 np145014
012: * CR 6224556
013: *
014: * Revision 1.5 2005/02/24 07:36:45 ss150821
015: * RFE 6223490 - SRA Should use JDK based logging
016: *
017: * Revision 1.4 2005/02/23 09:15:07 ss150821
018: * RFE 6223490 - SRA Should use JDK based logging
019: *
020: * Revision 1.3 2002/09/18 19:56:13 mm132998
021: * CRT #1986
022: *
023: * Revision 1.2.2.1 2002/09/18 19:40:33 mm132998
024: * CRT #1986
025: *
026: * Revision 1.2 2002/08/16 12:19:55 bv131302
027: * Hana CRT#1884 - RProxy perf issues
028: *
029: * Revision 1.1 2002/06/14 09:53:53 rt130506
030: * SRAP rebranding
031: *
032: * Revision 1.4 2002/06/11 16:02:04 bv131302
033: * new branded
034: *
035: * Revision 1.3 2002/06/02 09:52:47 ss133690
036: * CRT 1281 Bug 4618920 Option to make Gateway PDC work with other authentication mechanism (Authentication chain)
037: *
038: * Revision 1.2 2002/03/20 04:35:24 mm132998
039: * Bug ID # 4655269 CRT : # 602 Desc : Support for HTTP persistent connection at gateway
040: *
041: *
042: */
043: /*
044: * RedirectResponse.java
045: *
046: * $Author: np145014 $
047: *
048: * $Date: 2005/03/07 06:28:19 $ $Revision: 1.8 $
049: *
050: * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
051: *
052: * Developed by SunPS and SunIR
053: */
054:
055: package com.sun.portal.rproxy.connectionhandler;
056:
057: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
058: import com.sun.portal.rproxy.monitoring.util.RProxyEvent;
059:
060: import java.io.ByteArrayOutputStream;
061: import java.io.DataOutputStream;
062: import java.io.IOException;
063: import java.util.Date;
064:
065: /**
066: * This represents a single redirect response.
067: *
068: * @author Gabriel Lawrence
069: */
070: public class RedirectResponse extends HeaderResponse {
071: private static final String REDIRECTMESSAGE = "RedirectMessage";
072:
073: private static final String STATUS_CODE = "302";
074:
075: private static final String STATUS_TEXT = "Moved Temporarily";
076:
077: private static final String space = " ";
078:
079: private String _location;
080:
081: private boolean _needTranslation = true;
082:
083: {
084: MonitoringSubsystem.handleEvent(RProxyEvent.LOGIN_REDIRECT);
085: }
086:
087: public RedirectResponse(String location) {
088: super (REDIRECTMESSAGE, "", STATUS_CODE, STATUS_TEXT, null);
089: _location = location;
090: substituteContent(_location);
091: }
092:
093: public RedirectResponse(String location, boolean nt) {
094: super (REDIRECTMESSAGE, "", STATUS_CODE, STATUS_TEXT, null);
095: _location = location;
096: _needTranslation = nt;
097: substituteContent(_location);
098: }
099:
100: public boolean needTranslation() {
101: return _needTranslation;
102: }
103:
104: public String getResponseHeader(String s) {
105: if (s.regionMatches(true, 0, "location:", 0, 9)) {
106: return _location;
107: }
108: return null;
109: }
110:
111: /*
112: * public void setContentLength(int i) { }
113: */
114:
115: public void setLocation(String location) {
116: _location = location;
117: }
118:
119: public String getLocation() {
120: return _location;
121: }
122:
123: public byte[] getHeaderBytes() {
124: ByteArrayOutputStream outBAOS = new ByteArrayOutputStream();
125: try {
126: DataOutputStream out = new DataOutputStream(outBAOS);
127: StringBuffer strBuffer = new StringBuffer();
128: strBuffer.append(getHTTPVersion());
129: strBuffer.append(space);
130: strBuffer.append(getStatusCode());
131: strBuffer.append(space);
132: strBuffer.append(getStatusText());
133: strBuffer.append(crlf);
134: strBuffer.append("Date: ");
135: strBuffer.append(df.format(new Date()));
136: strBuffer.append(crlf);
137: strBuffer.append("Server: Redirector");
138: strBuffer.append(crlf);
139: strBuffer.append("Location: ");
140: strBuffer.append(getLocation());
141: strBuffer.append(crlf);
142: strBuffer.append("Content-Length: ");
143: strBuffer.append(getContentLength());
144: strBuffer.append(crlf);
145: strBuffer.append("Content-Type: ");
146: strBuffer.append(getContentType());
147: strBuffer.append("/");
148: strBuffer.append(getContentEncoding());
149: strBuffer.append(crlf);
150: out.writeBytes(strBuffer.toString());
151: /*
152: * out.writeBytes(getHTTPVersion() + " " + getStatusCode() + " " +
153: * getStatusText() + crlf + "Date: " + df.format(new Date()) + crlf +
154: * "Server: Redirector" + crlf + "Location: " + getLocation() + crlf +
155: * "Content-Length: " + getContentLength() + crlf + // Lihue
156: * KeepAlive //"Content-Type: " + getContentType() + "/" +
157: * getContentEncoding() + crlf + "Content-Type: " + getContentType() +
158: * "/" + getContentEncoding() + crlf ); //crlf);
159: */
160: if (keepAliveToken != null) {
161: out.writeBytes(keepAliveToken);
162: }
163: /*
164: * PRD 3.7 (4338513) Authentication chaining will work with
165: * Certificate authentication.
166: */
167: if (_cookie != null) {
168: out.writeBytes(_cookie + crlf);
169: }
170: // End of code change for PRD 3.7
171:
172: out.writeBytes(crlf);
173: // End of Code : Lihue KeepAlive
174: } catch (IOException ex) {
175: }
176: return outBAOS.toByteArray();
177: }
178: }
|