Package io.inversion

Class Response

java.lang.Object
io.inversion.Response
All Implemented Interfaces:
io.inversion.json.JSFind

public class Response extends Object implements io.inversion.json.JSFind
This class serves as holder for the Response returned from a RestClient call AND as the object used to construct your own response to an Engine request.
  • Field Details

    • chain

      protected Chain chain
    • request

      protected Request request
    • statusCode

      protected int statusCode
    • statusMesg

      protected String statusMesg
    • url

      protected String url
    • fileName

      protected String fileName
    • headers

      protected final io.inversion.utils.ListMap<String,String> headers
    • json

      protected io.inversion.json.JSNode json
    • text

      protected String text
    • stream

      protected io.inversion.utils.StreamBuffer stream
    • error

      protected Throwable error
    • debug

      protected final StringBuilder debug
    • changes

      protected final List<Change> changes
    • startAt

      protected long startAt
    • endAt

      protected long endAt
  • Constructor Details

    • Response

      public Response()
    • Response

      public Response(String url)
  • Method Details

    • withJson

      public Response withJson(io.inversion.json.JSNode json)
      Sets the root output json document...you should use withData and withMeta instead unless you REALLY want to change to wrapper document structure.
      Parameters:
      json - the json to set
      Returns:
      this
    • withJson

      public Response withJson(String json)
    • withText

      public Response withText(String text)
    • withBody

      public Response withBody(io.inversion.utils.StreamBuffer stream, String fileName)
    • withBody

      public Response withBody(io.inversion.utils.StreamBuffer stream)
    • getJson

      public io.inversion.json.JSNode getJson()
      Specified by:
      getJson in interface io.inversion.json.JSFind
    • getText

      public String getText()
    • getBody

      public io.inversion.utils.StreamBuffer getBody()
    • getBody

      public io.inversion.utils.StreamBuffer getBody(boolean explain)
    • debug

      public Response debug(String format, Object... args)
    • getDebug

      public String getDebug()
    • dump

      public Response dump()
    • getStartAt

      public long getStartAt()
    • withStartAt

      public Response withStartAt(long startAt)
    • getEndAt

      public long getEndAt()
    • withEndAt

      public Response withEndAt(long endAt)
    • withUrl

      public Response withUrl(String url)
    • withFileName

      public Response withFileName(String fileName)
    • getUrl

      public String getUrl()
    • withRequest

      public Response withRequest(Request request)
    • getRequest

      public Request getRequest()
    • getOp

      public Op getOp()
    • getChain

      public Chain getChain()
    • withChain

      public Response withChain(Chain chain)
    • getEngine

      public Engine getEngine()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • withError

      public Response withError(Throwable ex)
    • getError

      public Throwable getError()
    • withMeta

      public Response withMeta(String key, Object value)
    • getMeta

      public io.inversion.json.JSNode getMeta()
    • withFoundRows

      public Response withFoundRows(int foundRows)
    • getFoundRows

      public int getFoundRows()
    • withLastKey

      public Response withLastKey(String lastKey)
    • getLastKey

      public String getLastKey()
    • withPageSize

      public Response withPageSize(int pageSize)
    • getPageSize

      public int getPageSize()
    • withPageNum

      public Response withPageNum(int pageNum)
    • getPageNum

      public int getPageNum()
    • withPageCount

      public Response withPageCount(int pageCount)
    • getPageCount

      public int getPageCount()
    • updatePageCount

      protected void updatePageCount()
    • withLink

      public Response withLink(String name, String url)
    • getLink

      public String getLink(String name)
    • getSelf

      public String getSelf()
    • withSelf

      public Response withSelf(String url)
    • getNext

      public String getNext()
    • withNext

      public Response withNext(String url)
    • getPrev

      public String getPrev()
    • withPrev

      public Response withPrev(String url)
    • getFirst

      public String getFirst()
    • withFirst

      public Response withFirst(String url)
    • getLast

      public String getLast()
    • withLast

      public Response withLast(String url)
    • data

      public io.inversion.json.JSList data()
    • getFirstRecordAsMap

      public io.inversion.json.JSMap getFirstRecordAsMap()
    • withRecord

      public Response withRecord(Object record)
    • withRecords

      public Response withRecords(List records)
    • isSuccess

      public boolean isSuccess()
    • withStatus

      public Response withStatus(String status)
      Parameters:
      status - - one of the SC constants ex "200 OK"
      Returns:
      this
    • hasStatus

      public boolean hasStatus(int... statusCodes)
    • getStatus

      public String getStatus()
    • withStatusCode

      public Response withStatusCode(int statusCode)
    • getStatusCode

      public int getStatusCode()
      Returns:
      the statusCode
    • getStatusMesg

      public String getStatusMesg()
      Returns:
      the statusMesg
    • withStatusMesg

      public Response withStatusMesg(String statusMesg)
    • getHeaders

      public io.inversion.utils.ListMap<String,String> getHeaders()
      Returns:
      the headers
    • withHeaders

      public void withHeaders(io.inversion.utils.ListMap headers)
    • getHeader

      public String getHeader(String key)
    • withHeader

      public void withHeader(String key, String value)
    • clearHeaders

      public void clearHeaders()
    • getRedirect

      public String getRedirect()
    • withRedirect

      public Response withRedirect(String redirect)
    • withContentType

      public Response withContentType(String contentType)
    • getContentType

      public String getContentType()
    • getContentLength

      public long getContentLength()
      This is the value returned from the server via the "Content-Length" header NOTE: this will not match file length, for partial downloads, consider also using ContentRangeSize
      Returns:
      the value of the Content-Length header if it exists else 0
    • getChanges

      public List<Change> getChanges()
    • withChanges

      public Response withChanges(Collection<Change> changes)
    • withChange

      public Response withChange(String method, String collectionKey, Object resourceKey)
    • withChange

      public Response withChange(String method, String collectionKey, String... resourceKeys)
    • assertOk

      public Response assertOk(String... messages)
    • rethrow

      public void rethrow()
    • rethrow

      public void rethrow(int statusCode)
    • rethrow

      public void rethrow(String... messages)
    • rethrow

      public void rethrow(int statusCode, String... messages)
    • assertStatus

      public Response assertStatus(int... statusCodes)
    • assertStatus

      public Response assertStatus(String message, int... statusCodes)
    • assertDebug

      public Response assertDebug(String lineMatch, String... matches)