Package com.priint.pubserver.webservice
Class ServiceResult
java.lang.Object
com.priint.pubserver.webservice.ServiceResult
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeMarshal(jakarta.xml.bind.Marshaller m) static ServiceResultgetErrorInstance(String exceptionType, int statusCode, String message, Collection<String> causes) Factory method to create a ServiceResult for an error.static ServiceResultgetErrorInstance(Throwable cause) Factory method to create a ServiceResult for an error.Name of Exception class.In case of success this holds the HTTP request method name used to retrieve the data.Status code that the service produced.static ServiceResultgetSuccessInstance(String value) Factory method to create a ServiceResult in case of a success.static ServiceResultgetSuccessInstance(String value, Collection<?> items) Factory method to create a ServiceResult in case of a success.static ServiceResultgetSuccessInstance(String value, Map<String, ?> entries) Factory method to create a ServiceResult in case of a success.getUri()In case of success this holds the URI where the data have been retrieved.getValue()Simple string result.Whether the request was processed successfully.voidsetEntries(Map<String, ?> entries) voidsetExceptionType(String exceptionType) voidvoidvoidsetSuccess(Boolean success) voidvoidtoString()
-
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
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
PubServerExceptionstatus will the error code and entries will be filled with the message stack of the cause.- Parameters:
cause-- Returns:
-
getSuccessInstance
Factory method to create a ServiceResult in case of a success.- Parameters:
value-- Returns:
-
getSuccessInstance
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
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
- Returns:
-
getExceptionType
Name of Exception class.- Returns:
-
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
Status code that the service produced. See the service documentation for interpretation. This does NOT contain the HTTP response codes.- Returns:
-
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
Simple string result. In case of error this is the exception message.- Returns:
-
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
-
setExceptionType
-
setMethod
-
setStatus
-
setSuccess
-
setUri
-
setValue
-
toString
-
beforeMarshal
public void beforeMarshal(jakarta.xml.bind.Marshaller m)
-