Package com.sodius.oslc.server
Class OslcResponses
- java.lang.Object
-
- com.sodius.oslc.server.OslcResponses
-
public class OslcResponses extends Object
Constructs responses containing aOSLC-Core-Version
header and possibly an OSLC Error entity.- Since:
- 1.3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OslcResponses.OslcResponseBuilder
A class used to build Response instances
-
Method Summary
-
-
-
Method Detail
-
from
public static OslcResponses.OslcResponseBuilder from(ResourceResponse<?> response)
Create a new ResponseBuilder with the status and entity provided by the specified response.Below is the list of headers automatically copied, if present, from the specified response into the builder:
ETag
Last-Modified
- Parameters:
response
- the response to copy into the created builder.- Returns:
- a new ResponseBuilder.
-
from
public static OslcResponses.OslcResponseBuilder from(ClientResponse response) throws IOException
Create a new ResponseBuilder with the status and entity provided by the specified response.The specified client response is expected to contain a input stream as entity. In such case, this method copies the input stream into a byte array. This byte array is then set as entity in the created builder instance.
Below is the list of headers automatically copied, if present, from the specified response into the builder:
Cache-Control
Content-Type
Content-Length
ETag
Expires
Last-Modified
- Parameters:
response
- the response to copy into the created builder.- Returns:
- a new ResponseBuilder.
- Throws:
IOException
- if the entity stream cannot be retrieved.
-
ok
public static OslcResponses.OslcResponseBuilder ok()
Create a new ResponseBuilder with an OK status.- Returns:
- a new ResponseBuilder.
-
ok
public static OslcResponses.OslcResponseBuilder ok(Object entity)
Create a new ResponseBuilder with an OK status and a representation.- Parameters:
entity
- the representation entity data.- Returns:
- a new ResponseBuilder.
-
noContent
public static OslcResponses.OslcResponseBuilder noContent()
Create a new ResponseBuilder for an empty response.- Returns:
- a new ResponseBuilder.
-
created
public static OslcResponses.OslcResponseBuilder created(URI location)
Create a new ResponseBuilder for a created resource, set the location header using the supplied value.- Parameters:
location
- the content location.- Returns:
- a new ResponseBuilder.
-
created
public static OslcResponses.OslcResponseBuilder created(URI location, Object entity)
Create a new ResponseBuilder for a created resource, set the location header using the supplied value.- Parameters:
location
- the content location.entity
- the representation entity data.- Returns:
- a new ResponseBuilder.
-
accepted
public static OslcResponses.OslcResponseBuilder accepted()
Create a new ResponseBuilder with an Accepted status.- Returns:
- a new ResponseBuilder.
-
accepted
public static OslcResponses.OslcResponseBuilder accepted(Object entity)
Create a new ResponseBuilder with an Accepted status and a representation.- Parameters:
entity
- the representation entity data.- Returns:
- a new ResponseBuilder.
-
notFound
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder notFound()
Deprecated.UseOslcErrors.notFound(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for a non found resource. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
notFound
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder notFound(String message)
Deprecated.UseOslcErrors.notFound(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a non found resource with an error message. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
badRequest
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder badRequest()
Deprecated.UseOslcErrors.badRequest(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for a bad request The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
badRequest
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder badRequest(String message)
Deprecated.UseOslcErrors.badRequest(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a bad request. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
serviceUnavailable
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder serviceUnavailable()
Deprecated.UseOslcErrors.serviceUnavailable(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for a service being non available. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
serviceUnavailable
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder serviceUnavailable(String message)
Deprecated.UseOslcErrors.serviceUnavailable(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a service being non available. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
unauthorized
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder unauthorized()
Deprecated.UseOslcErrors.unauthorized(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for an unauthorized access. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
unauthorized
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder unauthorized(String message)
Deprecated.UseOslcErrors.unauthorized(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for an unauthorized access. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
forbidden
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder forbidden()
Deprecated.UseOslcErrors.forbidden(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for a forbidden access. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
forbidden
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder forbidden(String message)
Deprecated.UseOslcErrors.forbidden(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a forbidden access. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
serverError
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder serverError()
Deprecated.UseOslcErrors.serverError(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder with a server error status. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
serverError
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder serverError(String message)
Deprecated.UseOslcErrors.serverError(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a server error status. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
preconditionFailed
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder preconditionFailed()
Deprecated.UseOslcErrors.preconditionFailed(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting with an error message.Create a new ResponseBuilder for a precondition that was not verified. The response will contain an OSLC Error entity with the specified HTTP status.- Returns:
- a new ResponseBuilder.
-
preconditionFailed
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder preconditionFailed(String message)
Deprecated.UseOslcErrors.preconditionFailed(ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for a precondition that was not verified. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
error
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder error(Response.Status status)
Deprecated.UseOslcErrors.status(Response.Status, ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for the provided error status. The response will contain an OSLC Error entity with the specified HTTP status.- Parameters:
status
- the error status.- Returns:
- a new ResponseBuilder.
-
error
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder error(Response.Status status, String message)
Deprecated.UseOslcErrors.status(Response.Status, ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for the provided error status and message. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
status
- the error status.message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
error
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder error(int status)
Deprecated.UseOslcErrors.status(Response.Status, ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for the provided error status. The response will contain an OSLC Error entity with the specified HTTP status.- Parameters:
status
- the error status.- Returns:
- a new ResponseBuilder.
-
error
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder error(int status, String message)
Deprecated.UseOslcErrors.status(Response.Status, ErrorId, String)
andof(OslcError, Logger)
for enhanced error reporting.Create a new ResponseBuilder for the provided error status and message. The response will contain an OSLC Error entity with the specified HTTP status and error message.- Parameters:
status
- the error status.message
- the associated error message.- Returns:
- a new ResponseBuilder.
-
of
@Deprecated(since="1.13.0", forRemoval=false) public static OslcResponses.OslcResponseBuilder of(OslcError error)
Deprecated.Won't be removed, but rather useof(OslcError, Logger)
insteadCreate a new ResponseBuilder for the provided OSLC error entity. Client should useOslcErrors
to build such entity.Client is recommended to rather use
of(OslcError, Logger)
, unless the logging strategy of that method is not appropriate for a specific case.- Parameters:
error
- the OSLC Error entity.- Returns:
- a new ResponseBuilder.
- Since:
- 1.13.0
- See Also:
OslcErrors
,of(OslcError, Logger)
-
of
public static OslcResponses.OslcResponseBuilder of(OslcError error, org.slf4j.Logger logger)
Create a new ResponseBuilder for the provided OSLC error entity and log the entity. Client should useOslcErrors
to build such entity.This method logs the Error entity with following log level:
DEBUG
- if HTTP status is below 500.ERROR
- if HTTP status is 500 or upper.
- Parameters:
error
- the OSLC Error entity.logger
- the Logger instance where to log the given error.- Returns:
- a new ResponseBuilder.
- Since:
- 1.13.0
- See Also:
OslcErrors
-
-