use of javax.ws.rs.core.Request in project com-liferay-apio-architect by liferay.
the class ErrorUtil method getErrorResponse.
/**
* Transforms an exception into a {@code Response}.
*
* @param exception the exception
* @param request the current request
* @param httpHeaders the current HTTP headers
* @return the response
*/
public Response getErrorResponse(Exception exception, Request request, HttpHeaders httpHeaders) {
Optional<APIError> apiErrorOptional = _exceptionConverterManager.convert(exception);
if (!apiErrorOptional.isPresent()) {
Class<? extends Exception> exceptionClass = exception.getClass();
if (_apioLogger != null) {
_apioLogger.warning("No exception converter found for " + exceptionClass);
}
if (exceptionClass.isAssignableFrom(WebApplicationException.class)) {
WebApplicationException webApplicationException = (WebApplicationException) exception;
return webApplicationException.getResponse();
}
return Response.serverError().build();
}
APIError apiError = apiErrorOptional.get();
if (_apioLogger != null) {
_apioLogger.error(apiError);
}
int statusCode = apiError.getStatusCode();
Optional<ErrorMessageMapper> errorMessageMapperOptional = _errorMessageMapperManager.getErrorMessageMapperOptional(request);
return errorMessageMapperOptional.map(errorMessageMapper -> {
String result = ErrorWriter.writeError(errorMessageMapper, apiError, httpHeaders);
return Response.status(statusCode).type(errorMessageMapper.getMediaType()).entity(result).build();
}).orElseGet(() -> Response.status(statusCode).build());
}
use of javax.ws.rs.core.Request in project ovirt-engine by oVirt.
the class UsageFinderTest method testAction.
@Test
public void testAction() {
try {
UriInfo uriInfo = mockUri("vms", "00000001-0001-0001-0001-000000000011", "freezefilesystems");
Request request = mockRequest("POST");
Fault fault = usageFinder.getUsageMessage(uriInfo, request);
assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/vm/methods/freeze_filesystems", fault.getDetail());
} catch (URISyntaxException | ClassNotFoundException | IOException e) {
fail();
}
}
use of javax.ws.rs.core.Request in project ovirt-engine by oVirt.
the class UsageFinderTest method mockRequest.
private Request mockRequest(String httpMethod) {
Request requestMock = mock(Request.class);
when(requestMock.getMethod()).thenReturn(httpMethod);
return requestMock;
}
use of javax.ws.rs.core.Request in project dropwizard by dropwizard.
the class JerseyViolationExceptionTest method testAccessors.
@Test
void testAccessors() {
final Set<? extends ConstraintViolation<?>> violations = Collections.emptySet();
@SuppressWarnings("unchecked") final Inflector<Request, ?> inf = mock(Inflector.class);
final Invocable inv = Invocable.create(inf);
final JerseyViolationException test = new JerseyViolationException(violations, inv);
assertSame(inv, test.getInvocable());
}
use of javax.ws.rs.core.Request in project muikku by otavanopisto.
the class WorkspaceRESTService method getWorkspaceFileContent.
@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (workspaceEntity == null)
return Response.status(Status.BAD_REQUEST).build();
WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
if (imageFile == null)
return Response.status(Status.NOT_FOUND).build();
StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
String contentType = imageFile.getContentType();
String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
Aggregations