Package io.inversion

Class Response

  • All Implemented Interfaces:
    io.inversion.json.JSFind

    public class Response
    extends java.lang.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 Detail

      • chain

        protected Chain chain
      • request

        protected Request request
      • statusCode

        protected int statusCode
      • statusMesg

        protected java.lang.String statusMesg
      • url

        protected java.lang.String url
      • fileName

        protected java.lang.String fileName
      • headers

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

        protected io.inversion.json.JSNode json
      • text

        protected java.lang.String text
      • stream

        protected io.inversion.utils.StreamBuffer stream
      • error

        protected java.lang.Throwable error
      • debug

        protected final java.lang.StringBuilder debug
      • changes

        protected final java.util.List<Change> changes
      • startAt

        protected long startAt
      • endAt

        protected long endAt
    • Constructor Detail

      • Response

        public Response()
      • Response

        public Response​(java.lang.String url)
    • Method Detail

      • 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​(java.lang.String json)
      • withText

        public Response withText​(java.lang.String text)
      • withBody

        public Response withBody​(io.inversion.utils.StreamBuffer stream,
                                 java.lang.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 java.lang.String getText()
      • getBody

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

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

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

        public java.lang.String getDebug()
      • getStartAt

        public long getStartAt()
      • withStartAt

        public Response withStartAt​(long startAt)
      • getEndAt

        public long getEndAt()
      • withEndAt

        public Response withEndAt​(long endAt)
      • withUrl

        public Response withUrl​(java.lang.String url)
      • withFileName

        public Response withFileName​(java.lang.String fileName)
      • getUrl

        public java.lang.String getUrl()
      • getRequest

        public Request getRequest()
      • getOp

        public Op getOp()
      • getChain

        public Chain getChain()
      • getEngine

        public Engine getEngine()
      • toString

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

        public Response withError​(java.lang.Throwable ex)
      • getError

        public java.lang.Throwable getError()
      • withMeta

        public Response withMeta​(java.lang.String key,
                                 java.lang.Object value)
      • getMeta

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

        public Response withFoundRows​(int foundRows)
      • getFoundRows

        public int getFoundRows()
      • withLastKey

        public Response withLastKey​(java.lang.String lastKey)
      • getLastKey

        public java.lang.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​(java.lang.String name,
                                 java.lang.String url)
      • getLink

        public java.lang.String getLink​(java.lang.String name)
      • getSelf

        public java.lang.String getSelf()
      • withSelf

        public Response withSelf​(java.lang.String url)
      • getNext

        public java.lang.String getNext()
      • withNext

        public Response withNext​(java.lang.String url)
      • getPrev

        public java.lang.String getPrev()
      • withPrev

        public Response withPrev​(java.lang.String url)
      • getFirst

        public java.lang.String getFirst()
      • withFirst

        public Response withFirst​(java.lang.String url)
      • getLast

        public java.lang.String getLast()
      • withLast

        public Response withLast​(java.lang.String url)
      • data

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

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

        public Response withRecord​(java.lang.Object record)
      • withRecords

        public Response withRecords​(java.util.List records)
      • isSuccess

        public boolean isSuccess()
      • withStatus

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

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

        public java.lang.String getStatus()
      • withStatusCode

        public Response withStatusCode​(int statusCode)
      • getStatusCode

        public int getStatusCode()
        Returns:
        the statusCode
      • getStatusMesg

        public java.lang.String getStatusMesg()
        Returns:
        the statusMesg
      • withStatusMesg

        public Response withStatusMesg​(java.lang.String statusMesg)
      • getHeaders

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

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

        public java.lang.String getHeader​(java.lang.String key)
      • withHeader

        public void withHeader​(java.lang.String key,
                               java.lang.String value)
      • clearHeaders

        public void clearHeaders()
      • getRedirect

        public java.lang.String getRedirect()
      • withRedirect

        public Response withRedirect​(java.lang.String redirect)
      • withContentType

        public Response withContentType​(java.lang.String contentType)
      • getContentType

        public java.lang.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 java.util.List<Change> getChanges()
      • withChanges

        public Response withChanges​(java.util.Collection<Change> changes)
      • withChange

        public Response withChange​(java.lang.String method,
                                   java.lang.String collectionKey,
                                   java.lang.Object resourceKey)
      • withChange

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

        public Response assertOk​(java.lang.String... messages)
      • rethrow

        public void rethrow()
      • rethrow

        public void rethrow​(int statusCode)
      • rethrow

        public void rethrow​(java.lang.String... messages)
      • rethrow

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

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

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

        public Response assertDebug​(java.lang.String lineMatch,
                                    java.lang.String... matches)