Class HttpResponseImpl

java.lang.Object
org.apache.openejb.server.httpd.HttpResponseImpl
All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse, Serializable, HttpResponse

public class HttpResponseImpl extends Object implements HttpResponse
This class takes care of HTTP Responses. It sends data back to the browser.
See Also:
  • Field Details

  • Constructor Details

    • HttpResponseImpl

      protected HttpResponseImpl()
      creates a new instance of HttpResponseImpl with default values
    • HttpResponseImpl

      protected HttpResponseImpl(int code, String responseString, String contentType)
      Creates a new HttpResponseImpl with user provided parameters
      Parameters:
      code - the HTTP Response code, see http://www.ietf.org/rfc/rfc2616.txt for these codes
      responseString - the response string to be sent back
      contentType - the content type to be sent back
  • Method Details

    • setRequest

      protected void setRequest(HttpRequestImpl request)
    • setHeader

      public void setHeader(String name, String value)
      sets a header to be sent back to the browser
      Specified by:
      setHeader in interface jakarta.servlet.http.HttpServletResponse
      Parameters:
      name - the name of the header
      value - the value of the header
    • setIntHeader

      public void setIntHeader(String s, int i)
      Specified by:
      setIntHeader in interface jakarta.servlet.http.HttpServletResponse
    • setStatus

      public void setStatus(int i)
      Specified by:
      setStatus in interface jakarta.servlet.http.HttpServletResponse
    • addCookie

      public void addCookie(jakarta.servlet.http.Cookie cookie)
      Specified by:
      addCookie in interface jakarta.servlet.http.HttpServletResponse
    • addDateHeader

      public void addDateHeader(String s, long l)
      Specified by:
      addDateHeader in interface jakarta.servlet.http.HttpServletResponse
    • addHeader

      public void addHeader(String s, String s1)
      Specified by:
      addHeader in interface jakarta.servlet.http.HttpServletResponse
    • addIntHeader

      public void addIntHeader(String s, int i)
      Specified by:
      addIntHeader in interface jakarta.servlet.http.HttpServletResponse
    • containsHeader

      public boolean containsHeader(String s)
      Specified by:
      containsHeader in interface jakarta.servlet.http.HttpServletResponse
    • encodeURL

      public String encodeURL(String s)
      Specified by:
      encodeURL in interface jakarta.servlet.http.HttpServletResponse
    • encodeRedirectURL

      public String encodeRedirectURL(String s)
      Specified by:
      encodeRedirectURL in interface jakarta.servlet.http.HttpServletResponse
    • getHeader

      public String getHeader(String name)
      Gets a header based on the name passed in
      Specified by:
      getHeader in interface jakarta.servlet.http.HttpServletResponse
      Parameters:
      name - The name of the header
      Returns:
      the value of the header
    • getHeaderNames

      public Collection<String> getHeaderNames()
      Specified by:
      getHeaderNames in interface jakarta.servlet.http.HttpServletResponse
    • getHeaders

      public Collection<String> getHeaders(String s)
      Specified by:
      getHeaders in interface jakarta.servlet.http.HttpServletResponse
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface jakarta.servlet.http.HttpServletResponse
    • sendError

      public void sendError(int i) throws IOException
      Specified by:
      sendError in interface jakarta.servlet.http.HttpServletResponse
      Throws:
      IOException
    • sendError

      public void sendError(int i, String s) throws IOException
      Specified by:
      sendError in interface jakarta.servlet.http.HttpServletResponse
      Throws:
      IOException
    • sendRedirect

      public void sendRedirect(String path) throws IOException
      Specified by:
      sendRedirect in interface jakarta.servlet.http.HttpServletResponse
      Throws:
      IOException
    • setDateHeader

      public void setDateHeader(String s, long l)
      Specified by:
      setDateHeader in interface jakarta.servlet.http.HttpServletResponse
    • getOutputStream

      public jakarta.servlet.ServletOutputStream getOutputStream()
      gets the OutputStream to send data to the browser
      Specified by:
      getOutputStream in interface jakarta.servlet.ServletResponse
      Returns:
      the OutputStream to send data to the browser
    • getWriter

      public PrintWriter getWriter() throws IOException
      Specified by:
      getWriter in interface jakarta.servlet.ServletResponse
      Throws:
      IOException
    • isCommitted

      public boolean isCommitted()
      Specified by:
      isCommitted in interface jakarta.servlet.ServletResponse
    • flushBuffer

      public void flushBuffer() throws IOException
      Description copied from interface: HttpResponse
      Flushes the output buffer to the client.
      Specified by:
      flushBuffer in interface HttpResponse
      Specified by:
      flushBuffer in interface jakarta.servlet.ServletResponse
      Throws:
      IOException
    • getBufferSize

      public int getBufferSize()
      Specified by:
      getBufferSize in interface jakarta.servlet.ServletResponse
    • getCharacterEncoding

      public String getCharacterEncoding()
      Specified by:
      getCharacterEncoding in interface jakarta.servlet.ServletResponse
    • setCode

      public void setCode(int code)
      sets the HTTP response code to be sent to the browser. These codes are: OPTIONS = 0 GET = 1 HEAD = 2 POST = 3 PUT = 4 DELETE = 5 TRACE = 6 CONNECT = 7 UNSUPPORTED = 8
      Parameters:
      code - the code to be sent to the browser
    • getCode

      public int getCode()
      gets the HTTP response code
      Returns:
      the HTTP response code
    • setContentType

      public void setContentType(String type)
      sets the content type to be sent back to the browser
      Specified by:
      setContentType in interface HttpResponse
      Specified by:
      setContentType in interface jakarta.servlet.ServletResponse
      Parameters:
      type - the type to be sent to the browser (i.e. "text/html")
    • setLocale

      public void setLocale(Locale loc)
      Specified by:
      setLocale in interface jakarta.servlet.ServletResponse
    • getContentType

      public String getContentType()
      gets the content type that will be sent to the browser
      Specified by:
      getContentType in interface HttpResponse
      Specified by:
      getContentType in interface jakarta.servlet.ServletResponse
      Returns:
      the content type (i.e. "text/html")
    • getLocale

      public Locale getLocale()
      Specified by:
      getLocale in interface jakarta.servlet.ServletResponse
    • setResponseString

      public void setResponseString(String responseString)
      Sets the response string to be sent to the browser
      Parameters:
      responseString - the response string
    • reset

      public void reset()
      resets the data to be sent to the browser
      Specified by:
      reset in interface jakarta.servlet.ServletResponse
    • resetBuffer

      public void resetBuffer()
      Specified by:
      resetBuffer in interface jakarta.servlet.ServletResponse
    • setBufferSize

      public void setBufferSize(int i)
      Specified by:
      setBufferSize in interface jakarta.servlet.ServletResponse
    • setCharacterEncoding

      public void setCharacterEncoding(String s)
      Specified by:
      setCharacterEncoding in interface jakarta.servlet.ServletResponse
    • setContentLength

      public void setContentLength(int i)
      Specified by:
      setContentLength in interface jakarta.servlet.ServletResponse
    • setContentLengthLong

      public void setContentLengthLong(long length)
      Specified by:
      setContentLengthLong in interface jakarta.servlet.ServletResponse
    • reset

      public void reset(int code, String responseString)
      resets the data to be sent to the browser with the response code and response string
      Parameters:
      code - the code to be sent to the browser
      responseString - the response string to be sent to the browser
    • writeMessage

      protected void writeMessage(OutputStream output, boolean indent) throws IOException
      Takes care of sending the response line, headers and body HTTP/1.1 200 OK Server: Netscape-Enterprise/3.6 SP3 Date: Thu, 07 Jun 2001 17:30:42 GMT Content-Type: text/html Connection: close
      Parameters:
      output - the output to send the response to
      Throws:
      IOException - if an exception is thrown
    • toString

      public String toString()
      Creates a string version of the response similar to: HTTP/1.1 200 OK
      Overrides:
      toString in class Object
      Returns:
      the string value of this HttpResponseImpl
    • getServerName

      public String getServerName()
      gets the name of the server being used
      Returns:
      the name of the server
    • createError

      protected static HttpResponseImpl createError(String message)
      This could be improved at some day in the future to also include a stack trace of the exceptions
      Parameters:
      message - the error message to be sent
      Returns:
      the HttpResponseImpl that this error belongs to
    • createError

      protected static HttpResponseImpl createError(String message, Throwable t)
      creates an error with user defined variables
      Parameters:
      message - the message of the error
      t - a Throwable to print a stack trace to
      Returns:
      the HttpResponseImpl that this error belongs to
    • createForbidden

      protected static HttpResponseImpl createForbidden(String ip)
      Creates a forbidden response to be sent to the browser using IP authentication
      Parameters:
      ip - the ip that is forbidden
      Returns:
      the HttpResponseImpl that this error belongs to
    • setContent

      public void setContent(URLConnection content)
      Parameters:
      content - The content to set.
    • setStatusMessage

      public void setStatusMessage(String responseString)
      Description copied from interface: HttpResponse
      Sets the response string to be sent to the browser
      Specified by:
      setStatusMessage in interface HttpResponse
      Parameters:
      responseString - the response string