Class AbstractWebResponse

java.lang.Object
services.moleculer.web.servlet.response.AbstractWebResponse
All Implemented Interfaces:
WebResponse
Direct Known Subclasses:
BlockingWebResponse, NonBlockingWebResponse

public abstract class AbstractWebResponse extends Object implements WebResponse
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final AtomicBoolean
     
    protected final jakarta.servlet.ServletOutputStream
     
    protected HashMap<String,Object>
    Custom properties (for inter-middleware communication).
    protected final jakarta.servlet.http.HttpServletResponse
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractWebResponse(jakarta.servlet.http.HttpServletResponse rsp)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    end()
    Completes the synchronous operation that was started on the request.
    Returns the value of the specified response header as a String.
    Returns the internal object of this WebResponse.
    Returns the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name".
    int
    Gets the current status code of this response.
    void
    send(byte[] bytes)
    Writes b.length bytes of body from the specified byte array to the output stream.
    void
    setHeader(String name, String value)
    Sets a response header with the given name and value.
    void
    setProperty(String name, Object value)
    Associates the specified value with the specified "name" in this WebResponse.
    void
    setStatus(int code)
    Sets the status code for this response.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • rsp

      protected final jakarta.servlet.http.HttpServletResponse rsp
    • out

      protected final jakarta.servlet.ServletOutputStream out
    • closed

      protected final AtomicBoolean closed
    • properties

      protected HashMap<String,Object> properties
      Custom properties (for inter-middleware communication).
  • Constructor Details

    • AbstractWebResponse

      protected AbstractWebResponse(jakarta.servlet.http.HttpServletResponse rsp) throws IOException
      Throws:
      IOException
  • Method Details

    • setStatus

      public void setStatus(int code)
      Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the 200 or 404 status codes). This method preserves any cookies and other response headers. Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.
      Specified by:
      setStatus in interface WebResponse
      Parameters:
      code - the status code
    • getStatus

      public int getStatus()
      Gets the current status code of this response.
      Specified by:
      getStatus in interface WebResponse
      Returns:
      the status code
    • setHeader

      public void setHeader(String name, String value)
      Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.
      Specified by:
      setHeader in interface WebResponse
      Parameters:
      name - the name of the header
      value - the header value If it contains octet string, it should be encoded according to RFC 2047
    • getHeader

      public String getHeader(String name)
      Returns the value of the specified response header as a String. If the response did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first head in the response.
      Specified by:
      getHeader in interface WebResponse
      Parameters:
      name - name a String specifying the header name
      Returns:
      a String containing the value of the response header, or null if the response does not have a header of that name
    • send

      public void send(byte[] bytes) throws IOException
      Writes b.length bytes of body from the specified byte array to the output stream.
      Specified by:
      send in interface WebResponse
      Parameters:
      bytes - the data
      Throws:
      IOException - if an I/O error occurs
    • end

      public boolean end()
      Completes the synchronous operation that was started on the request.
      Specified by:
      end in interface WebResponse
      Returns:
      return true, if any resources are released
    • setProperty

      public void setProperty(String name, Object value)
      Associates the specified value with the specified "name" in this WebResponse. If the WebResponse previously contained a mapping for the "name", the old value is replaced.
      Specified by:
      setProperty in interface WebResponse
      Parameters:
      name - a "name" with which the specified value is to be associated
      value - value to be associated with the specified "name"
    • getProperty

      public Object getProperty(String name)
      Returns the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name".
      Specified by:
      getProperty in interface WebResponse
      Parameters:
      name - the "name" whose associated value is to be returned
      Returns:
      the value to which the specified "name" is mapped, or null if this WebResponse contains no mapping for the "name"
    • getInternalObject

      public Object getInternalObject()
      Returns the internal object of this WebResponse.
      Specified by:
      getInternalObject in interface WebResponse
      Returns:
      internal object (HttpServletResponse)