Class DefaultServletHttpResponse<B>

java.lang.Object
io.micronaut.servlet.engine.DefaultServletHttpResponse<B>
Type Parameters:
B - The body type
All Implemented Interfaces:
io.micronaut.core.attr.AttributeHolder, io.micronaut.core.attr.MutableAttributeHolder, io.micronaut.http.HttpMessage<B>, io.micronaut.http.HttpResponse<B>, io.micronaut.http.MutableHttpMessage<B>, io.micronaut.http.MutableHttpResponse<B>, ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>

@Internal public class DefaultServletHttpResponse<B> extends Object implements ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
Implementation of ServletHttpResponse for the Servlet API.
Since:
1.0.0
Author:
graemerocher
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    DefaultServletHttpResponse(io.micronaut.core.convert.ConversionService conversionService, DefaultServletHttpRequest<B> request, jakarta.servlet.http.HttpServletResponse delegate)
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> io.micronaut.http.MutableHttpResponse<T>
    body(T body)
     
    int
     
    io.micronaut.http.MutableHttpResponse<B>
    contentLength(long length)
     
    io.micronaut.http.MutableHttpResponse<B>
    contentType(io.micronaut.http.MediaType mediaType)
     
    io.micronaut.http.MutableHttpResponse<B>
     
    io.micronaut.http.MutableHttpResponse<B>
    cookie(io.micronaut.http.cookie.Cookie cookie)
     
    @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object>
     
    @NonNull Optional<B>
     
    @NonNull Optional<io.micronaut.http.MediaType>
     
    @NonNull io.micronaut.http.MutableHttpHeaders
     
    jakarta.servlet.http.HttpServletResponse
     
    Returns an OutputStream that can be used to write the body of the response.
    Returns a BufferedWriter that can be used to write the text body of the response.
    io.micronaut.http.MutableHttpResponse<B>
     
    io.micronaut.http.MutableHttpResponse<B>
    locale(Locale locale)
     
     
    io.micronaut.http.MutableHttpResponse<B>
    status(int status)
     
    io.micronaut.http.MutableHttpResponse<B>
    status(int status, CharSequence message)
     
    io.micronaut.http.MutableHttpResponse<B>
    status(io.micronaut.http.HttpStatus status)
     
    org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>>
    stream(org.reactivestreams.Publisher<?> dataPublisher)
    Streams data using the given data publisher.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.core.attr.AttributeHolder

    getAttribute, getAttribute

    Methods inherited from interface io.micronaut.http.HttpMessage

    getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getLocale

    Methods inherited from interface io.micronaut.http.HttpResponse

    body, getCookie, getCookies, getStatus, header, setAttribute, status

    Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder

    removeAttribute

    Methods inherited from interface io.micronaut.http.MutableHttpMessage

    basicAuth, bearerAuth, bodyWriter

    Methods inherited from interface io.micronaut.http.MutableHttpResponse

    attribute, characterEncoding, characterEncoding, contentEncoding, cookies, headers, headers, status, toMutableResponse
  • Constructor Details

    • DefaultServletHttpResponse

      protected DefaultServletHttpResponse(io.micronaut.core.convert.ConversionService conversionService, DefaultServletHttpRequest<B> request, jakarta.servlet.http.HttpServletResponse delegate)
      Default constructor.
      Parameters:
      conversionService - The conversion service
      request - The servlet request
      delegate - The servlet response
  • Method Details

    • stream

      public org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>> stream(org.reactivestreams.Publisher<?> dataPublisher)
      Description copied from interface: ServletHttpResponse
      Streams data using the given data publisher.
      Specified by:
      stream in interface ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
      Parameters:
      dataPublisher - The data publisher
      Returns:
      Emits the response once the stream has completed
    • getContentType

      @NonNull public @NonNull Optional<io.micronaut.http.MediaType> getContentType()
      Specified by:
      getContentType in interface io.micronaut.http.HttpMessage<B>
    • contentType

      public io.micronaut.http.MutableHttpResponse<B> contentType(CharSequence contentType)
      Specified by:
      contentType in interface io.micronaut.http.MutableHttpMessage<B>
      Specified by:
      contentType in interface io.micronaut.http.MutableHttpResponse<B>
    • contentType

      public io.micronaut.http.MutableHttpResponse<B> contentType(io.micronaut.http.MediaType mediaType)
      Specified by:
      contentType in interface io.micronaut.http.MutableHttpMessage<B>
      Specified by:
      contentType in interface io.micronaut.http.MutableHttpResponse<B>
    • contentLength

      public io.micronaut.http.MutableHttpResponse<B> contentLength(long length)
      Specified by:
      contentLength in interface io.micronaut.http.MutableHttpMessage<B>
      Specified by:
      contentLength in interface io.micronaut.http.MutableHttpResponse<B>
    • locale

      public io.micronaut.http.MutableHttpResponse<B> locale(Locale locale)
      Specified by:
      locale in interface io.micronaut.http.MutableHttpResponse<B>
    • header

      public io.micronaut.http.MutableHttpResponse<B> header(CharSequence name, CharSequence value)
      Specified by:
      header in interface io.micronaut.http.MutableHttpMessage<B>
      Specified by:
      header in interface io.micronaut.http.MutableHttpResponse<B>
    • status

      public io.micronaut.http.MutableHttpResponse<B> status(int status)
      Specified by:
      status in interface io.micronaut.http.MutableHttpResponse<B>
    • status

      public io.micronaut.http.MutableHttpResponse<B> status(io.micronaut.http.HttpStatus status)
      Specified by:
      status in interface io.micronaut.http.MutableHttpResponse<B>
    • getNativeResponse

      public jakarta.servlet.http.HttpServletResponse getNativeResponse()
      Specified by:
      getNativeResponse in interface ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
      Returns:
      The native response type.
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Description copied from interface: ServletHttpResponse
      Returns an OutputStream that can be used to write the body of the response. This method is typically used to write binary data. If the body is text, the ServletHttpResponse.getWriter() method is more appropriate.
      Specified by:
      getOutputStream in interface ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
      Returns:
      The output stream
      Throws:
      IOException - if a valid OutputStream cannot be returned for some reason.
    • getWriter

      public BufferedWriter getWriter() throws IOException
      Description copied from interface: ServletHttpResponse
      Returns a BufferedWriter that can be used to write the text body of the response. If the written text will not be US-ASCII, you should specify a character encoding by calling MutableHttpResponse.contentEncoding(CharSequence) before calling this method.
      Specified by:
      getWriter in interface ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
      Returns:
      The writer
      Throws:
      IOException - if a valid BufferedWriter cannot be returned for some reason.
    • cookie

      public io.micronaut.http.MutableHttpResponse<B> cookie(io.micronaut.http.cookie.Cookie cookie)
      Specified by:
      cookie in interface io.micronaut.http.MutableHttpResponse<B>
    • getHeaders

      @NonNull public @NonNull io.micronaut.http.MutableHttpHeaders getHeaders()
      Specified by:
      getHeaders in interface io.micronaut.http.HttpMessage<B>
      Specified by:
      getHeaders in interface io.micronaut.http.MutableHttpMessage<B>
    • getAttributes

      @NonNull public @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object> getAttributes()
      Specified by:
      getAttributes in interface io.micronaut.core.attr.AttributeHolder
      Specified by:
      getAttributes in interface io.micronaut.http.HttpMessage<B>
      Specified by:
      getAttributes in interface io.micronaut.core.attr.MutableAttributeHolder
    • getBody

      @NonNull public @NonNull Optional<B> getBody()
      Specified by:
      getBody in interface io.micronaut.http.HttpMessage<B>
    • body

      public <T> io.micronaut.http.MutableHttpResponse<T> body(@Nullable T body)
      Specified by:
      body in interface io.micronaut.http.MutableHttpMessage<B>
      Specified by:
      body in interface io.micronaut.http.MutableHttpResponse<B>
    • status

      public io.micronaut.http.MutableHttpResponse<B> status(int status, CharSequence message)
      Specified by:
      status in interface io.micronaut.http.MutableHttpResponse<B>
    • code

      public int code()
      Specified by:
      code in interface io.micronaut.http.HttpResponse<B>
    • reason

      public String reason()
      Specified by:
      reason in interface io.micronaut.http.HttpResponse<B>