001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: HttpPresentationResponse.java,v 1.3 2006-09-08 08:33:07 sinisa Exp $
022: */
023:
024: package com.lutris.appserver.server.httpPresentation;
025:
026: import java.util.Map;
027:
028: import javax.servlet.http.Cookie;
029: import javax.servlet.http.HttpServletResponse;
030:
031: import org.enhydra.xml.io.OutputOptions;
032: import org.enhydra.xml.xmlc.XMLObject;
033: import org.w3c.dom.Node;
034: import org.w3c.dom.html.HTMLDocument;
035:
036: import com.lutris.appserver.server.ResponsePostProcessingManager;
037: import com.lutris.appserver.server.session.SessionManager;
038:
039: /**
040: * Object passed to presentation objects that is used to generate HTTP
041: * responses.
042: *
043: * @author Mark Diekhans
044: * @version $Revision: 1.3 $
045: */
046: public interface HttpPresentationResponse {
047: /**
048: * Returns the original HttpServletResponse.
049: */
050: public HttpServletResponse getHttpServletResponse();
051:
052: /**
053: * Sets the content length for this response.
054: *
055: * @param len the content length
056: */
057: public void setContentLength(int len)
058: throws HttpPresentationException;
059:
060: /**
061: * Sets the content type for this response.
062: *
063: * @param type the content's MIME type
064: */
065: public void setContentType(String type)
066: throws HttpPresentationException;
067:
068: /**
069: * Create an OutputOptions object for a document. Options are default for
070: * the specified document. The object maybe then modified as needed to
071: * override the default values.
072: * <P>
073: * The following attributes are set in the object:
074: * <UL>
075: * <LI> encoding
076: * <LI> MIME type - Defaults for document.
077: * <LI> URLRewriter - Set if URL encoding of sessions is enabled.
078: * </UL>
079: */
080: public OutputOptions createOutputOptions(XMLObject document)
081: throws HttpPresentationException;
082:
083: /**
084: * Returns an output stream for writing response data.
085: */
086: public HttpPresentationOutputStream getOutputStream()
087: throws HttpPresentationException;
088:
089: /**
090: * Adds the specified cookie to the response. It can be called multiple
091: * times to set more than one cookie.
092: *
093: * @param cookie - The Cookie to return to the client.
094: */
095: public void addCookie(Cookie cookie)
096: throws HttpPresentationException;
097:
098: /**
099: * Returns true if the response message header has a field with
100: * the specified name.
101: *
102: * @param name the header field name
103: */
104: public boolean containsHeader(String name)
105: throws HttpPresentationException;
106:
107: /**
108: * Sets the status code and message for this response.
109: *
110: * @param sc the status code
111: * @param sm the status message
112: */
113: public void setStatus(int sc, String sm)
114: throws HttpPresentationException;
115:
116: /**
117: * Sets the status code and a default message for this response.
118: *
119: * @param sc the status code
120: */
121: public void setStatus(int sc) throws HttpPresentationException;
122:
123: /**
124: * Adds a field to the response header with a given name and
125: * value. If the field had already been set, the new value
126: * overwrites the previous one. The containsHeader method can be
127: * used to test for the presence of a header before setting its
128: * value.
129: *
130: * @param name the header field name
131: * @param value the header field value
132: */
133: public void setHeader(String name, String value)
134: throws HttpPresentationException;
135:
136: /**
137: * Adds a field to the response header with a given name and
138: * integer value. If the field had already been set, the new
139: * value overwrites the previous one. The containsHeader method
140: * can be used to test for the presence of a header before setting
141: * its value.
142: *
143: * @param name the header field name
144: * @param value the header field integer value
145: */
146: public void setIntHeader(String name, int value)
147: throws HttpPresentationException;
148:
149: /**
150: *
151: * Adds a field to the response header with a given name and
152: * date-valued field. The date is specified in terms of
153: * milliseconds since the epoch. If the date field had already
154: * been set, the new value overwrites the previous one. The
155: * containsHeader method can be used to test for the presence of a
156: * header before setting its value.
157: *
158: * @param name the header field name
159: * @param value the header field date value
160: */
161: public void setDateHeader(String name, long date)
162: throws HttpPresentationException;
163:
164: /**
165: * Sends an error response to the client using the specified status
166: * code and descriptive message.
167: *
168: * @param sc the status code
169: * @param msg the detail message
170: */
171: public void sendError(int sc, String msg)
172: throws HttpPresentationException;
173:
174: /**
175: * Sends an error response to the client using the specified
176: * status code and a default message.
177: *
178: * @param sc the status code
179: */
180: public void sendError(int sc) throws HttpPresentationException;
181:
182: //Omitted: sendRedirect(String location)
183:
184: //Omitted: public abstract String encodeUrl(String url)
185:
186: //Omitted: public abstract String encodeRedirectUrl(String url)
187:
188: /**
189: * Called at the end of processing a response to force any cached headers to
190: * be written and buffers flushed. This maybe a no-op if no buffering is
191: * implemented. This is normally not called by a client.
192: */
193: public void flush() throws HttpPresentationException;
194:
195: /**
196: * Output an an XML document object (DOM). The document is formatted
197: * according to it's type. The MIME type of the response is automatically
198: * set.
199: *
200: * @param outputFormat Object use to specify options controling formatting
201: * of the document.
202: * @param doc The DOM object to be returned as response.
203: */
204: public void writeDOM(OutputOptions outputOptions, Node document)
205: throws HttpPresentationException;
206:
207: /**
208: * Output an an XML document object (DOM). The document is formatted
209: * according to it's type. The MIME type of the response is automatically
210: * set.
211: *
212: * @param doc The DOM object to be returned as response.
213: */
214: public void writeDOM(Node document)
215: throws HttpPresentationException;
216:
217: /**
218: * Utility method to output an HTML page. The appropriate headers are
219: * set for MIME type and to disable caching of the HTML by the broswer.
220: */
221: public void writeHTML(String html) throws HttpPresentationException;
222:
223: /**
224: * Utility method to output an HTML page from a DOM object. The
225: * appropriate headers are set for MIME type and to disable caching
226: * of the HTML by the broswer.
227: *
228: * @param doc The DOM object to be returned as response
229: * @deprecated use writeDOM
230: * @see #writeDOM
231: */
232: public void writeHTML(HTMLDocument doc)
233: throws HttpPresentationException;
234:
235: /**
236: * Set the output character encoding.
237: *
238: * @param enc character encoding
239: */
240: public void setEncoding(String enc);
241:
242: /**
243: * Get the output character encoding.
244: *
245: * @return the current encoding
246: */
247: public String getEncoding();
248:
249: /**
250: * Sets the current session key for this response
251: *
252: * @param sessionKey
253: * The current sessionKey
254: **/
255: public void setSessionKey(String sessionKey);
256:
257: /**
258: * Sets the current application name for this response
259: *
260: * @param appName
261: * The current application name
262: **/
263: public void setSessionManager(SessionManager sessionManager);
264:
265: /**
266: * Indicates whether client response requires a sessionId cookie
267: * @return true if client response requires a sessionId cookie
268: * false otherwise
269: */
270: public boolean isSessionIdCookieRequired()
271: throws HttpPresentationException;
272:
273: /*
274: * set boolean flag for sessionId response cookie. Indicates whether
275: * client response requires a sessionId cookie
276: * @param isFromCookie boolean flag
277: */
278: public void setSessionIdCookieRequired(boolean sessionIdCookie)
279: throws HttpPresentationException;
280:
281: /**
282: * Indicates whether client response requires url encoding for
283: * sessionId
284: * @return true if client response requires url encoding for
285: * sessionId; false otherwise
286: */
287: public boolean isSessionIdEncodeUrlRequired()
288: throws HttpPresentationException;
289:
290: /*
291: * set boolean flag url encoding for sessionId. Indicates whether
292: * client response requires url encoding for sessionId
293: * @param sessionIdUrl boolean flag
294: */
295: public void setSessionIdEncodeUrlRequired(boolean sessionIdUrl)
296: throws HttpPresentationException;
297:
298: /*
299: * SERVER status codes; see RFC 1945.
300: */
301:
302: /**
303: * Status code (200) indicating the request succeeded normally.
304: */
305: public static final int SC_OK = 200;
306:
307: /**
308: * Status code (201) indicating the request succeeded and created
309: * a new resource on the server.
310: */
311: public static final int SC_CREATED = 201;
312:
313: /**
314: * Status code (202) indicating that a request was accepted for
315: * processing, but was not completed.
316: */
317: public static final int SC_ACCEPTED = 202;
318:
319: /**
320: * Status code (204) indicating that the request succeeded but that
321: * there was no new information to return.
322: */
323: public static final int SC_NO_CONTENT = 204;
324:
325: /**
326: * Status code (301) indicating that the resource has permanently
327: * moved to a new location, and that future references should use a
328: * new URI with their requests.
329: */
330: public static final int SC_MOVED_PERMANENTLY = 301;
331:
332: /**
333: * Status code (302) indicating that the resource has temporarily
334: * moved to another location, but that future references should
335: * still use the original URI to access the resource.
336: */
337: public static final int SC_MOVED_TEMPORARILY = 302;
338:
339: /**
340: * Status code (304) indicating that a conditional GET operation
341: * found that the resource was available and not modified.
342: */
343: public static final int SC_NOT_MODIFIED = 304;
344:
345: /**
346: * Status code (400) indicating the request sent by the client was
347: * syntactically incorrect.
348: */
349: public static final int SC_BAD_REQUEST = 400;
350:
351: /**
352: * Status code (401) indicating that the request requires HTTP
353: * authentication.
354: */
355: public static final int SC_UNAUTHORIZED = 401;
356:
357: /**
358: * Status code (403) indicating the server understood the request
359: * but refused to fulfill it.
360: */
361: public static final int SC_FORBIDDEN = 403;
362:
363: /**
364: * Status code (404) indicating that the requested resource is not
365: * available.
366: */
367: public static final int SC_NOT_FOUND = 404;
368:
369: /**
370: * Status code (500) indicating an error inside the HTTP service
371: * which prevented it from fulfilling the request.
372: */
373: public static final int SC_INTERNAL_SERVER_ERROR = 500;
374:
375: /**
376: * Status code (501) indicating the HTTP service does not support
377: * the functionality needed to fulfill the request.
378: */
379: public static final int SC_NOT_IMPLEMENTED = 501;
380:
381: /**
382: * Status code (502) indicating that the HTTP server received an
383: * invalid response from a server it consulted when acting as a
384: * proxy or gateway.
385: */
386: public static final int SC_BAD_GATEWAY = 502;
387:
388: /**
389: * Status code (503) indicating that the HTTP service is
390: * temporarily overloaded, and unable to handle the request.
391: */
392: public static final int SC_SERVICE_UNAVAILABLE = 503;
393:
394: /**
395: * Sets the response post processing manager.
396: *
397: * @param processingManager
398: */
399: public void setPostProcessingManager(
400: ResponsePostProcessingManager processingManager);
401:
402: /**
403: * Returns the response post processing manager.
404: */
405: public ResponsePostProcessingManager getPostProcessingManager();
406: }
|