You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VaadinResponse.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.IOException;
  18. import java.io.OutputStream;
  19. import java.io.PrintWriter;
  20. import java.io.Serializable;
  21. import javax.portlet.MimeResponse;
  22. import javax.portlet.PortletResponse;
  23. import javax.portlet.ResourceResponse;
  24. import javax.servlet.ServletResponse;
  25. import javax.servlet.http.Cookie;
  26. import javax.servlet.http.HttpServletResponse;
  27. /**
  28. * A generic response from the server, wrapping a more specific response type,
  29. * e.g. HttpServletResponse or PortletResponse.
  30. *
  31. * @since 7.0
  32. */
  33. public interface VaadinResponse extends Serializable {
  34. /**
  35. * Sets the (http) status code for the response. If you want to include an
  36. * error message along the status code, use {@link #sendError(int, String)}
  37. * instead.
  38. *
  39. * @param statusCode
  40. * the status code to set
  41. * @see HttpServletResponse#setStatus(int)
  42. *
  43. * @see ResourceResponse#HTTP_STATUS_CODE
  44. */
  45. public void setStatus(int statusCode);
  46. /**
  47. * Sets the content type of this response. If the content type including a
  48. * charset is set before {@link #getWriter()} is invoked, the returned
  49. * PrintWriter will automatically use the defined charset.
  50. *
  51. * @param contentType
  52. * a string specifying the MIME type of the content
  53. *
  54. * @see ServletResponse#setContentType(String)
  55. * @see MimeResponse#setContentType(String)
  56. */
  57. public void setContentType(String contentType);
  58. /**
  59. * Sets the value of a generic response header. If the header had already
  60. * been set, the new value overwrites the previous one.
  61. *
  62. * @param name
  63. * the name of the header
  64. * @param value
  65. * the header value.
  66. *
  67. * @see HttpServletResponse#setHeader(String, String)
  68. * @see PortletResponse#setProperty(String, String)
  69. */
  70. public void setHeader(String name, String value);
  71. /**
  72. * Properly formats a timestamp as a date header. If the header had already
  73. * been set, the new value overwrites the previous one.
  74. *
  75. * @param name
  76. * the name of the header
  77. * @param timestamp
  78. * the number of milliseconds since epoch
  79. *
  80. * @see HttpServletResponse#setDateHeader(String, long)
  81. */
  82. public void setDateHeader(String name, long timestamp);
  83. /**
  84. * Returns a <code>OutputStream</code> for writing binary data in the
  85. * response.
  86. * <p>
  87. * Either this method or getWriter() may be called to write the response,
  88. * not both.
  89. *
  90. * @return a <code>OutputStream</code> for writing binary data
  91. * @throws IOException
  92. * if an input or output exception occurred
  93. *
  94. * @see #getWriter()
  95. * @see ServletResponse#getOutputStream()
  96. * @see MimeResponse#getPortletOutputStream()
  97. */
  98. public OutputStream getOutputStream() throws IOException;
  99. /**
  100. * Returns a <code>PrintWriter</code> object that can send character text to
  101. * the client. The PrintWriter uses the character encoding defined using
  102. * setContentType.
  103. * <p>
  104. * Either this method or getOutputStream() may be called to write the
  105. * response, not both.
  106. *
  107. * @return a <code>PrintWriter</code> for writing character text
  108. * @throws IOException
  109. * if an input or output exception occurred
  110. *
  111. * @see #getOutputStream()
  112. * @see ServletResponse#getWriter()
  113. * @see MimeResponse#getWriter()
  114. */
  115. public PrintWriter getWriter() throws IOException;
  116. /**
  117. * Sets cache time in milliseconds, -1 means no cache at all. All required
  118. * headers related to caching in the response are set based on the time.
  119. *
  120. * @param milliseconds
  121. * Cache time in milliseconds
  122. */
  123. public void setCacheTime(long milliseconds);
  124. /**
  125. * Sends an error response to the client using the specified status code and
  126. * clears the buffer. In some configurations, this can cause a predefined
  127. * error page to be displayed.
  128. *
  129. * @param errorCode
  130. * the HTTP status code
  131. * @param message
  132. * a message to accompany the error
  133. * @throws IOException
  134. * if an input or output exception occurs
  135. *
  136. * @see HttpServletResponse#sendError(int, String)
  137. */
  138. public void sendError(int errorCode, String message) throws IOException;
  139. /**
  140. * Gets the vaadin service for the context of this response.
  141. *
  142. * @return the vaadin service
  143. *
  144. * @see VaadinService
  145. */
  146. public VaadinService getService();
  147. /**
  148. * Adds the specified cookie to the response. This method can be called
  149. * multiple times to set more than one cookie.
  150. *
  151. * @param cookie
  152. * the Cookie to return to the client
  153. *
  154. * @see HttpServletResponse#addCookie(Cookie)
  155. * @see PortletResponse#addProperty(Cookie)
  156. */
  157. public void addCookie(Cookie cookie);
  158. /**
  159. * Sets the length of the content body in the response In HTTP servlets,
  160. * this method sets the HTTP Content-Length header. For some portlet
  161. * responses, this method sets the content-length header, for others this
  162. * method does nothing.
  163. *
  164. * @param len
  165. * an integer specifying the length of the content being returned
  166. * to the client
  167. * @since 7.3.8
  168. */
  169. public void setContentLength(int len);
  170. }