Class VertxHttpResponse

java.lang.Object
dev.resteasy.vertx.server.VertxHttpResponse
All Implemented Interfaces:
Closeable, AutoCloseable, org.jboss.resteasy.spi.HttpResponse

public class VertxHttpResponse extends Object implements org.jboss.resteasy.spi.HttpResponse
Vert.x adapter that bridges HttpServerResponse to RESTEasy's HttpResponse SPI.

This adapter handles:

  • Status code and headers conversion to Vert.x format
  • Response body output stream (via ChunkOutputStream)
  • Chunked encoding and response finalization
  • Exception tracking from Vert.x async handlers

The response is considered committed after headers are sent (either via chunked streaming or when finish() is called).

Author:
Bill Burke, Norman Maurer
  • Constructor Details

    • VertxHttpResponse

      public VertxHttpResponse(io.vertx.core.http.HttpServerResponse response, org.jboss.resteasy.spi.ResteasyProviderFactory providerFactory)
      Creates a new response adapter.
      Parameters:
      response - the Vert.x HTTP server response
      providerFactory - the RESTEasy provider factory for header serialization
    • VertxHttpResponse

      public VertxHttpResponse(io.vertx.core.http.HttpServerResponse response, org.jboss.resteasy.spi.ResteasyProviderFactory providerFactory, io.vertx.core.http.HttpMethod method)
      Creates a new response adapter with optional HTTP method.
      Parameters:
      response - the Vert.x HTTP server response
      providerFactory - the RESTEasy provider factory for header serialization
      method - the HTTP method (if HEAD, no output stream is created)
  • Method Details

    • setOutputStream

      public void setOutputStream(OutputStream os)
      Specified by:
      setOutputStream in interface org.jboss.resteasy.spi.HttpResponse
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface org.jboss.resteasy.spi.HttpResponse
    • setStatus

      public void setStatus(int status)
      Specified by:
      setStatus in interface org.jboss.resteasy.spi.HttpResponse
    • getOutputHeaders

      public jakarta.ws.rs.core.MultivaluedMap<String,Object> getOutputHeaders()
      Specified by:
      getOutputHeaders in interface org.jboss.resteasy.spi.HttpResponse
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Specified by:
      getOutputStream in interface org.jboss.resteasy.spi.HttpResponse
      Throws:
      IOException
    • addNewCookie

      public void addNewCookie(jakarta.ws.rs.core.NewCookie cookie)
      Specified by:
      addNewCookie in interface org.jboss.resteasy.spi.HttpResponse
    • sendError

      public void sendError(int status) throws IOException
      Specified by:
      sendError in interface org.jboss.resteasy.spi.HttpResponse
      Throws:
      IOException
    • sendError

      public void sendError(int status, String message) throws IOException
      Specified by:
      sendError in interface org.jboss.resteasy.spi.HttpResponse
      Throws:
      IOException
    • isCommitted

      public boolean isCommitted()
      Specified by:
      isCommitted in interface org.jboss.resteasy.spi.HttpResponse
    • reset

      public void reset()
      Specified by:
      reset in interface org.jboss.resteasy.spi.HttpResponse
    • prepareOutputStream

      public void prepareOutputStream()
      Prepares the response output stream.

      Sets the status code, enables chunked mode if applicable, and writes all headers. Called when the response output stream is first written to.

    • finish

      public void finish() throws IOException
      Finishes the response by flushing output and ending the Vert.x response.

      This must be called to complete the HTTP response. If not already committed, headers will be written. The response cannot be modified after this call.

      Throws:
      IOException - if the response has already failed or cannot be finished
    • flushBuffer

      public void flushBuffer() throws IOException
      Specified by:
      flushBuffer in interface org.jboss.resteasy.spi.HttpResponse
      Throws:
      IOException