abstract class EnrichedResponse extends ResponseProxy
A wrapper around a com.twitter.finagle.http.Response which is itself a type of com.twitter.finagle.http.Response (by virtue of extending com.twitter.finagle.http.ResponseProxy
This class exposes a builder-like API for creating an com.twitter.finagle.http.Response. Users are NOT expected to interact with this class directly but should instead use the methods in the com.twitter.finatra.http.response.ResponseBuilder which return this specialized com.twitter.finagle.http.Response type.
- Note
Usage is through com.twitter.finatra.http.response.ResponseBuilder
- See also
- Alphabetic
- By Inheritance
- EnrichedResponse
- ResponseProxy
- Proxy
- Response
- Message
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new EnrichedResponse()
Abstract Value Members
- abstract def body(buffer: Buf): EnrichedResponse
Return a response with the given com.twitter.io.Buf set as the response body.
Return a response with the given com.twitter.io.Buf set as the response body.
- buffer
the com.twitter.io.Buf to set as the response body.
- returns
an EnrichedResponse with the given com.twitter.io.Buf set as the response body.
- abstract def body(inputStream: InputStream): EnrichedResponse
Return a response with the given InputStream written as bytes as the response body.
Return a response with the given InputStream written as bytes as the response body.
- inputStream
the InputStream to write as bytes as the response body.
- returns
an EnrichedResponse with the given InputStream written as an Array[Byte] as the response body.
- Note
this fully buffers the InputStream as an Array[Byte] and copies it as the response body. The given input stream is closed after writing the response body.
- abstract def body(bodyStr: String): EnrichedResponse
Return a response with the given String written as the response body.
Return a response with the given String written as the response body.
- bodyStr
the String to write as the response body.
- returns
an EnrichedResponse with the given String written as the response body.
- abstract def body(b: Array[Byte]): EnrichedResponse
Return a response with the given Array[Byte] written as the response body.
Return a response with the given Array[Byte] written as the response body.
- b
bytes to write as the response body.
- returns
an EnrichedResponse with the given Array[Byte] written as the response body.
- Note
this uses com.twitter.io.Buf.ByteArray.Owned to set the response content.
- See also
- abstract def body(request: Request, any: Any): EnrichedResponse
Return a response with a written body potentially based on values contained within the com.twitter.finagle.http.Request.
Return a response with a written body potentially based on values contained within the com.twitter.finagle.http.Request.
- request
the com.twitter.finagle.http.Request associated with this response.
- any
the body, or the information needed to render the body.
- returns
an EnrichedResponse with the given object written as the response body.
- Note
This version is useful when the
any
parameter requires custom message body rendering and values in theRequest
are required for decision making.
- abstract def body(any: Any): EnrichedResponse
Return a response with the given object as the written response body.
Return a response with the given object as the written response body. The object is pattern-matched to set the body and content type appropriately.
- any
the body, or the information needed to render the body.
- returns
an EnrichedResponse with the given object written as the response body.
- abstract def contentType(mediaType: String): EnrichedResponse
Set the "Content-Type" response header field of this EnrichedResponse to the given String.
Set the "Content-Type" response header field of this EnrichedResponse to the given String.
- mediaType
the String to set a the header value.
- returns
an EnrichedResponse with the "Content-Type" response header field set to given media type.
- abstract def contentTypeJson(): EnrichedResponse
Set the "Content-Type" header field for this EnrichedResponse to "application/json".
Set the "Content-Type" header field for this EnrichedResponse to "application/json".
- returns
an EnrichedResponse with a the response header "Content-Type" field set to "application/json".
- abstract def cookie(c: Cookie): EnrichedResponse
Set the given com.twitter.finagle.http.Cookie on the returned Response.
Set the given com.twitter.finagle.http.Cookie on the returned Response.
- c
the com.twitter.finagle.http.Cookie to set.
- returns
an EnrichedResponse with a created Cookie of name with value.
- See also
- abstract def cookie(name: String, value: String): EnrichedResponse
Set a com.twitter.finagle.http.Cookie with the given name and value on the returned Response.
Set a com.twitter.finagle.http.Cookie with the given name and value on the returned Response.
- name
- value
- returns
an EnrichedResponse with a created com.twitter.finagle.http.Cookie of name with value.
- See also
- abstract def failure(request: Request, exception: DetailedNonRetryableSourcedException): EnrichedResponse
Helper method for returning responses that are the result of a "service-level" failure.
Helper method for returning responses that are the result of a "service-level" failure. This is most commonly useful in an com.twitter.finatra.http.exceptions.ExceptionMapper implementation. E.g.,
- request
the com.twitter.finagle.http.Request that triggered the failure
- exception
the DetailedNonRetryableSourcedException exception to classify
- returns
this EnrichedResponse
- abstract def failure(request: Request, source: String, details: Seq[Any], message: String = ""): EnrichedResponse
Helper method for returning responses that are the result of a "service-level" failure.
Helper method for returning responses that are the result of a "service-level" failure. This is most commonly useful in an com.twitter.finatra.http.exceptions.ExceptionMapper implementation. E.g.,
@Singleton class AuthenticationExceptionMapper @Inject()( response: ResponseBuilder) extends ExceptionMapper[AuthenticationException] { override def toResponse( request: Request, exception: AuthenticationException ): Response = { response .status(exception.status) .failureClassifier( is5xxStatus(exception.status), request, exception) .jsonError(s"Your account could not be authenticated. Reason: ${exception.resultCode}") } }
- request
the com.twitter.finagle.http.Request that triggered the failure
- source
The named component responsible for causing this failure.
- details
Details about this exception suitable for stats. Each element will be converted into a string. Note: Each element must have a bounded set of values (e.g. You can stat the type of a tweet as "protected" or "unprotected", but you can't include the actual tweet id "696081566032723968").
- message
Details about this exception to be logged when this exception occurs. Typically logDetails contains the unbounded details of the exception that you are not able to stat such as an actual tweet ID (see above)
- returns
this EnrichedResponse
- abstract def failureClassifier(classifier: => Boolean, request: Request, source: String, details: Seq[Any] = Seq(), message: String = ""): EnrichedResponse
Helper method for returning responses that are the result of a "service-level" failure.
Helper method for returning responses that are the result of a "service-level" failure. This is most commonly useful in an com.twitter.finatra.http.exceptions.ExceptionMapper implementation.
- classifier
if the failure should be "classified", e.g. logged and stat'd accordingly
- request
the com.twitter.finagle.http.Request that triggered the failure
- source
The named component responsible for causing this failure.
- details
Details about this exception suitable for stats. Each element will be converted into a string. Note: Each element must have a bounded set of values (e.g. You can stat the type of a tweet as "protected" or "unprotected", but you can't include the actual tweet id "696081566032723968").
- message
Details about this exception to be logged when this exception occurs. Typically logDetails contains the unbounded details of the exception that you are not able to stat such as an actual tweet ID (see above).
- returns
this EnrichedResponse
- abstract def failureClassifier(classifier: => Boolean, request: Request, exception: DetailedNonRetryableSourcedException): EnrichedResponse
Helper method for returning responses that are the result of a "service-level" failure.
Helper method for returning responses that are the result of a "service-level" failure. This is most commonly useful in an com.twitter.finatra.http.exceptions.ExceptionMapper implementation. E.g.,
- classifier
if the failure should be "classified", e.g. logged and stat'd accordingly
- request
the com.twitter.finagle.http.Request that triggered the failure
- exception
the DetailedNonRetryableSourcedException exception to classify
- returns
this EnrichedResponse
- abstract def file(file: String): EnrichedResponse
Return a response resolving the given file path to a java.io.File using the configured com.twitter.finatra.utils.FileResolver.
Return a response resolving the given file path to a java.io.File using the configured com.twitter.finatra.utils.FileResolver. The resolved java.io.File is set as bytes as the response body. The file contents are fully buffered and copied to an Array[Byte] before being written as the response body.
- file
the file String to resolve as a java.io.File to write as the response body.
- returns
an EnrichedResponse with the given file written as an Array[Byte] as the response body.
- Note
The resolved file is closed after writing the response body.
- See also
- abstract def file(file: File): EnrichedResponse
Return a response with the given java.io.File bytes as the response body.
Return a response with the given java.io.File bytes as the response body. The file contents are fully buffered and copied to an Array[Byte] before being written as the response body.
- file
the java.io.File to write as the response body.
- returns
an EnrichedResponse with the given file written as an Array[Byte] as the response body.
- Note
The given java.io.File is closed after writing the response body.
- abstract def fileOrIndex(filePath: String, indexPath: String): EnrichedResponse
Return the file (only if it's an existing file w/ an extension), otherwise return the index.
Return the file (only if it's an existing file w/ an extension), otherwise return the index. Note: This functionality is useful for "single-page" UI frameworks (e.g. AngularJS) that perform client side routing.
- filePath
the file path to resolve and return
- indexPath
the index path to use when the file at the given filePath does not exist or does not specify an extension.
- returns
an EnrichedResponse with the resolved file or index written as an Array[Byte] as the response body.
- See also
String)
- abstract def header(k: String, v: Any): EnrichedResponse
Return a response with the given response header key/value set.
Return a response with the given response header key/value set.
- k
the response header key to set.
- v
the response header object to set. This method calls
toString
on this parameter to compute the String value.- returns
an EnrichedResponse with the given response header field to the given value.
- abstract def headers(entries: (String, Any)*): EnrichedResponse
Return a response with the given response headers set.
Return a response with the given response headers set.
- entries
the sequence of Tuple2 response header key/values to set.
- returns
an EnrichedResponse with each response header field set to its tupled value.
- abstract def headers(map: Map[String, String]): EnrichedResponse
Return a response with the given response headers set.
Return a response with the given response headers set.
- map
the map of response header key/values to set.
- returns
an EnrichedResponse with each response header field set to its mapped value.
- abstract def html(any: Any): EnrichedResponse
Return a response with the given object written as a HTML response body.
Return a response with the given object written as a HTML response body. Sets the "Content-Type" header field for this EnrichedResponse to "text/html". The object is pattern-matched to set the response body appropriately.
- any
the object to write as an HTML response body.
- returns
an EnrichedResponse with the given object written as an HTML response body.
- Note
the content type can be overridden depending on if there is a registered MessageBodyManager for the given object type that specifies a different content type than "text/html".
- abstract def html(html: String): EnrichedResponse
Return a response with the given String written as a HTML response body.
Return a response with the given String written as a HTML response body. Sets the "Content-Type" header field for this EnrichedResponse to "text/html".
- html
the String to write as an HTML response body.
- returns
an EnrichedResponse with the given String written as an HTML response body.
- abstract def json(obj: Any): EnrichedResponse
Return a JSON-formatted body from the given object.
Return a JSON-formatted body from the given object. Note when either String or Array[Byte] data is passed the data is set as the response body unmodified, i.e., assumes the data is already JSON formatted).
The purpose of this method is to convert an object into a JSON-formatted body via the defined ObjectMapper.
Sets the response "Content-Type" header to "application/json"
- obj
object to convert into a JSON-formatted body.
- returns
an EnrichedResponse with a JSON body.
- abstract def jsonError(message: String): EnrichedResponse
Create a JSON-formatted ErrorsResponse response body based on the given string.
Create a JSON-formatted ErrorsResponse response body based on the given string.
- message
string message over which to create a JSON-formatted ErrorsResponse.
- returns
an EnrichedResponse with a JSON-formatted ErrorsResponse response body.
- See also
- abstract def jsonError: EnrichedResponse
Create a JSON-formatted ErrorsResponse response body based on this response's current com.twitter.finagle.http.Status.
Create a JSON-formatted ErrorsResponse response body based on this response's current com.twitter.finagle.http.Status.
- returns
an EnrichedResponse with a JSON-formatted ErrorsResponse response body.
- abstract def location(uri: String): EnrichedResponse
Return a response with the "Location" response header field set to the given URI value.
Return a response with the "Location" response header field set to the given URI value.
- uri
the String value to set as the header value.
- returns
an EnrichedResponse with a set "Location" response header.
- abstract def location(uri: Any): EnrichedResponse
Return a response with the "Location" response header field set to the given URI value.
Return a response with the "Location" response header field set to the given URI value.
- uri
the value to set as the header value. This method calls
toString
on this parameter to compute the String value.- returns
an EnrichedResponse with a set "Location" response header.
- abstract def plain(any: Any): EnrichedResponse
Return a response with the given object written as a plaintext response body.
Return a response with the given object written as a plaintext response body. Sets the "Content-Type" header field for this EnrichedResponse to "text/plain".
- any
the object to write as a plaintext response body.
- returns
an EnrichedResponse with the given object written as a plaintext response body.
- abstract def response: Response
- Definition Classes
- Proxy
- abstract def toException: HttpResponseException
Returns a HttpResponseException built from the Response wrapped by this EnrichedResponse
Returns a HttpResponseException built from the Response wrapped by this EnrichedResponse
- returns
a new HttpResponseException over the response
- See also
HttpResponseException
- abstract def toFuture: Future[Response]
Returns this EnrichedResponse wrapped in a com.twitter.util.Future
Returns this EnrichedResponse wrapped in a com.twitter.util.Future
- returns
a
Future[Response]]
- abstract def toFutureException[T]: Future[T]
Returns a failed Future of type [T] containing the result of EnrichedResponse#toException.
Returns a failed Future of type [T] containing the result of EnrichedResponse#toException.
- T
the type of the
Future
- returns
a "failed" Future.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addCookie(cookie: Cookie): Unit
- Definition Classes
- Message
- def allow: Option[String]
- Definition Classes
- Message
- def allow_=(values: Iterable[Method]): Unit
- Definition Classes
- Message
- def allow_=(value: String): Unit
- Definition Classes
- Message
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def cacheControl: Option[String]
- Definition Classes
- Message
- def cacheControl_=(maxAge: Duration): Unit
- Definition Classes
- Message
- def cacheControl_=(value: String): Unit
- Definition Classes
- Message
- def charset: Option[String]
- Definition Classes
- Message
- def charset_=(value: String): Unit
- Definition Classes
- Message
- def chunkReader: Reader[Chunk]
- Definition Classes
- Proxy → Message
- def chunkWriter: Writer[Chunk]
- Definition Classes
- Proxy → Message
- final def clearContent(): Unit
- Definition Classes
- Message
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def close(): Future[Unit]
- Definition Classes
- Message
- final def content: Buf
- Definition Classes
- Proxy → Message
- final def content(content: Buf): EnrichedResponse.this.type
- Definition Classes
- Message
- Annotations
- @throws(scala.this.throws.<init>$default$1[IllegalStateException])
- final def contentLength(value: Long): EnrichedResponse.this.type
- Definition Classes
- Message
- def contentLength: Option[Long]
- Definition Classes
- Message
- final def contentLengthOrElse(default: Long): Long
- Definition Classes
- Message
- def contentLength_=(value: Long): Unit
- Definition Classes
- Message
- def contentString: String
- Definition Classes
- Message
- def contentString_=(value: String): Unit
- Definition Classes
- Message
- def contentType: Option[String]
- Definition Classes
- Message
- def contentType_=(value: String): Unit
- Definition Classes
- Message
- final def content_=(content: Buf): Unit
- Definition Classes
- Proxy → Message
- lazy val cookies: CookieMap
- Definition Classes
- Proxy → Message
- def ctx: Record
- Definition Classes
- Proxy → Response
- def date: Option[String]
- Definition Classes
- Message
- def date_=(value: Date): Unit
- Definition Classes
- Message
- def date_=(value: String): Unit
- Definition Classes
- Message
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def expires: Option[String]
- Definition Classes
- Message
- def expires_=(value: Date): Unit
- Definition Classes
- Message
- def expires_=(value: String): Unit
- Definition Classes
- Message
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getContentString(): String
- Definition Classes
- Message
- def getCookies(): Iterator[Cookie]
- Definition Classes
- Message
- final def getInputStream(): InputStream
- Definition Classes
- Message
- final def getLength(): Int
- Definition Classes
- Message
- final def getReader(): Reader
- Definition Classes
- Message
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def headerMap: HeaderMap
- Definition Classes
- Proxy → Message
- final def isChunked: Boolean
- Definition Classes
- Proxy → Message
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def isRequest: Boolean
- Definition Classes
- Response → Message
- def isResponse: Boolean
- Definition Classes
- Message
- def isXmlHttpRequest: Boolean
- Definition Classes
- Message
- final def keepAlive: Boolean
- Definition Classes
- Message
- final def keepAlive(keepAlive: Boolean): EnrichedResponse.this.type
- Definition Classes
- Message
- def lastModified: Option[String]
- Definition Classes
- Message
- def lastModified_=(value: Date): Unit
- Definition Classes
- Message
- def lastModified_=(value: String): Unit
- Definition Classes
- Message
- final def length: Int
- Definition Classes
- Message
- def location: Option[String]
- Definition Classes
- Response
- def location_=(value: String): Unit
- Definition Classes
- Response
- def mediaType: Option[String]
- Definition Classes
- Message
- def mediaType_=(value: String): Unit
- Definition Classes
- Message
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final lazy val reader: Reader[Buf]
- Definition Classes
- Message
- def removeCookie(name: String): Unit
- Definition Classes
- Message
- def retryAfter: Option[String]
- Definition Classes
- Response
- def retryAfter_=(value: Long): Unit
- Definition Classes
- Response
- def retryAfter_=(value: String): Unit
- Definition Classes
- Response
- def server: Option[String]
- Definition Classes
- Response
- def server_=(value: String): Unit
- Definition Classes
- Response
- final def setChunked(chunked: Boolean): Unit
- Definition Classes
- Proxy → Message
- final def setContentString(value: String): Unit
- Definition Classes
- Message
- def setContentType(mediaType: String, charset: String): Unit
- Definition Classes
- Message
- def setContentTypeJson(): Unit
- Definition Classes
- Message
- final def status: Status
- Definition Classes
- Proxy → Response
- final def status(value: Status): EnrichedResponse.this.type
- Definition Classes
- Response
- final def statusCode(value: Int): EnrichedResponse.this.type
- Definition Classes
- Response
- final def statusCode: Int
- Definition Classes
- Response
- final def statusCode_=(value: Int): Unit
- Definition Classes
- Response
- final def status_=(value: Status): Unit
- Definition Classes
- Proxy → Response
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- Response → AnyRef → Any
- def trailers: HeaderMap
- Definition Classes
- Proxy → Message
- final def version: Version
- Definition Classes
- Proxy → Message
- final def version(version: Version): EnrichedResponse.this.type
- Definition Classes
- Message
- final def version_=(version: Version): Unit
- Definition Classes
- Proxy → Message
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withInputStream[T](f: (InputStream) => T): T
- Definition Classes
- Message
- final def withOutputStream[T](f: (OutputStream) => T): T
- Definition Classes
- Message
- Annotations
- @throws(classOf[java.lang.IllegalStateException])
- final def withReader[T](f: (Reader) => T): T
- Definition Classes
- Message
- final def withWriter[T](f: (Writer) => T): T
- Definition Classes
- Message
- Annotations
- @throws(classOf[java.lang.IllegalStateException])
- final def write(bytes: Array[Byte]): Unit
- Definition Classes
- Message
- Annotations
- @throws(classOf[java.lang.IllegalStateException])
- final def write(buf: Buf): Unit
- Definition Classes
- Message
- Annotations
- @throws(classOf[java.lang.IllegalStateException])
- final def write(string: String): Unit
- Definition Classes
- Message
- Annotations
- @throws(classOf[java.lang.IllegalStateException])
- final lazy val writer: Writer[Buf]
- Definition Classes
- Message
- def wwwAuthenticate: Option[String]
- Definition Classes
- Response
- def wwwAuthenticate_=(value: String): Unit
- Definition Classes
- Response