Class ServiceResult

java.lang.Object
com.priint.pubserver.webservice.ServiceResult
All Implemented Interfaces:
Serializable

public class ServiceResult extends Object implements 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:
  • Constructor Details

    • ServiceResult

      public ServiceResult()
  • Method Details

    • getErrorInstance

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

      public static ServiceResult getErrorInstance(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(String value)
      Factory method to create a ServiceResult in case of a success.
      Parameters:
      value -
      Returns:
    • getSuccessInstance

      public static ServiceResult getSuccessInstance(String value, 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(String value, Map<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 Map<String,?> getEntries()
      Returns:
    • getExceptionType

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

      public 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 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 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 String getValue()
      Simple string result. In case of error this is the exception message.
      Returns:
    • isSuccess

      public 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(Map<String,?> entries)
    • setExceptionType

      public void setExceptionType(String exceptionType)
    • setMethod

      public void setMethod(String method)
    • setStatus

      public void setStatus(Integer status)
    • setSuccess

      public void setSuccess(Boolean success)
    • setUri

      public void setUri(String uri)
    • setValue

      public void setValue(String value)
    • toString

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

      public void beforeMarshal(jakarta.xml.bind.Marshaller m)