Class NettyWebResponse

java.lang.Object
services.moleculer.web.netty.NettyWebResponse
All Implemented Interfaces:
HttpConstants, WebResponse

public class NettyWebResponse extends Object implements WebResponse, HttpConstants
  • Field Details

    • ctx

      protected final io.netty.channel.ChannelHandlerContext ctx
    • req

      protected final NettyWebRequest req
    • channel

      protected final io.netty.channel.Channel channel
    • properties

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

      protected int code
    • headers

      protected HashMap<String,String> headers
    • first

      protected AtomicBoolean first
  • Constructor Details

    • NettyWebResponse

      public NettyWebResponse(io.netty.channel.ChannelHandlerContext ctx, NettyWebRequest req)
  • 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 asynchronous operation that was started on the request.
      Specified by:
      end in interface WebResponse
      Returns:
      return true, if all resources are released
    • sendHeaders

      protected void sendHeaders()
    • 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 (Netty ChannelHandlerContext)