Class ServiceResult

  • All Implemented Interfaces:
    java.io.Serializable

    public class ServiceResult
    extends java.lang.Object
    implements java.io.Serializable
    Default result class for all RESTful service methods including exceptional results.

    Contains success field for easy switching between default processing or error handling.

    In case of error the object will contain exception information in

    • statusCode (see exception classes for list of relevant codes),
    • exceptionType (name of exception class),
    • value (exception message),
    • items (some stack trace messages).

    In case of success the object may contain a string value or a hash map of arbitrary entries depending on the generating service.

    Since:
    4.0.5
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ServiceResult()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beforeMarshal​(javax.xml.bind.Marshaller m)  
      java.util.Map<java.lang.String,​?> getEntries()  
      static ServiceResult getErrorInstance​(java.lang.String exceptionType, int statusCode, java.lang.String message, java.util.Collection<java.lang.String> causes)
      Factory method to create a ServiceResult for an error.
      static ServiceResult getErrorInstance​(java.lang.Throwable cause)
      Factory method to create a ServiceResult for an error.
      java.lang.String getExceptionType()
      Name of Exception class.
      java.lang.String getMethod()
      In case of success this holds the HTTP request method name used to retrieve the data.
      java.lang.Integer getStatus()
      Status code that the service produced.
      static ServiceResult getSuccessInstance​(java.lang.String value)
      Factory method to create a ServiceResult in case of a success.
      static ServiceResult getSuccessInstance​(java.lang.String value, java.util.Collection<?> items)
      Factory method to create a ServiceResult in case of a success.
      static ServiceResult getSuccessInstance​(java.lang.String value, java.util.Map<java.lang.String,​?> entries)
      Factory method to create a ServiceResult in case of a success.
      java.lang.String getUri()
      In case of success this holds the URI where the data have been retrieved.
      java.lang.String getValue()
      Simple string result.
      java.lang.Boolean isSuccess()
      Whether the request was processed successfully.
      void setEntries​(java.util.Map<java.lang.String,​?> entries)  
      void setExceptionType​(java.lang.String exceptionType)  
      void setMethod​(java.lang.String method)  
      void setStatus​(java.lang.Integer status)  
      void setSuccess​(java.lang.Boolean success)  
      void setUri​(java.lang.String uri)  
      void setValue​(java.lang.String value)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ServiceResult

        public ServiceResult()
    • Method Detail

      • getErrorInstance

        public static ServiceResult getErrorInstance​(java.lang.String exceptionType,
                                                     int statusCode,
                                                     java.lang.String message,
                                                     java.util.Collection<java.lang.String> causes)
        Factory method to create a ServiceResult for an error.
        Parameters:
        exceptionType -
        statusCode -
        message -
        causes -
        Returns:
      • getErrorInstance

        public static ServiceResult getErrorInstance​(java.lang.Throwable cause)
        Factory method to create a ServiceResult for an error.

        Type will be filled with the class name of the cause and value will be filled with the message.

        If the cause is an instance of PubServerException status will the error code and entries will be filled with the message stack of the cause.

        Parameters:
        cause -
        Returns:
      • getSuccessInstance

        public static ServiceResult getSuccessInstance​(java.lang.String value)
        Factory method to create a ServiceResult in case of a success.
        Parameters:
        value -
        Returns:
      • getSuccessInstance

        public static ServiceResult getSuccessInstance​(java.lang.String value,
                                                       java.util.Collection<?> items)
        Factory method to create a ServiceResult in case of a success.

        Items can be of any of the registered serializable PubServer types. Items will be represented in a hash map with its numerical index as key.

        Parameters:
        value -
        items -
        Returns:
      • getSuccessInstance

        public static ServiceResult getSuccessInstance​(java.lang.String value,
                                                       java.util.Map<java.lang.String,​?> entries)
        Factory method to create a ServiceResult in case of a success.

        Items can be of any of the registered serializable PubServer types.

        Parameters:
        value -
        entries -
        Returns:
      • getEntries

        public java.util.Map<java.lang.String,​?> getEntries()
        Returns:
      • getExceptionType

        public java.lang.String getExceptionType()
        Name of Exception class.
        Returns:
      • getMethod

        public java.lang.String getMethod()
        In case of success this holds the HTTP request method name used to retrieve the data. Together with the uri field this makes the request.
        Returns:
      • getStatus

        public java.lang.Integer getStatus()
        Status code that the service produced. See the service documentation for interpretation. This does NOT contain the HTTP response codes.
        Returns:
      • getUri

        public java.lang.String getUri()
        In case of success this holds the URI where the data have been retrieved. Together with the method field this makes the request.
        Returns:
      • getValue

        public java.lang.String getValue()
        Simple string result. In case of error this is the exception message.
        Returns:
      • isSuccess

        public java.lang.Boolean isSuccess()
        Whether the request was processed successfully. Typically true if server send HTTP code 200 and response payload could be parsed into Data or a ServiceResult object. False in all other cases.
        Returns:
      • setEntries

        public void setEntries​(java.util.Map<java.lang.String,​?> entries)
      • setExceptionType

        public void setExceptionType​(java.lang.String exceptionType)
      • setMethod

        public void setMethod​(java.lang.String method)
      • setStatus

        public void setStatus​(java.lang.Integer status)
      • setSuccess

        public void setSuccess​(java.lang.Boolean success)
      • setUri

        public void setUri​(java.lang.String uri)
      • setValue

        public void setValue​(java.lang.String value)
      • toString

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

        public void beforeMarshal​(javax.xml.bind.Marshaller m)