use of javax.ws.rs.ServiceUnavailableException in project Hystrix by Netflix.
the class HystricsMetricsControllerTest method testConcurrency.
@Test
public void testConcurrency() throws Exception {
// Execute a Hystrix command so that metrics are initialized.
executeHystrixCommand();
List<EventInput> streamList = new ArrayList<EventInput>();
// Fire 5 requests, validate their responses and hold these connections.
for (int i = 0; i < 5; i++) {
EventInput stream = getStream();
System.out.println("Received Response for Request#" + (i + 1));
streamList.add(stream);
validateStream(stream, 1000);
System.out.println("Validated Response#" + (i + 1));
}
// Sixth request should fail since max configured connection is 5.
try {
streamList.add(getStreamFailFast());
Assert.fail("Expected 'ServiceUnavailableException' but, request went through.");
} catch (ServiceUnavailableException e) {
System.out.println("Got ServiceUnavailableException as expected.");
}
// Close one of the connections
streamList.get(0).close();
// Try again after closing one of the connections. This request should go through.
EventInput eventInput = getStream();
streamList.add(eventInput);
validateStream(eventInput, 1000);
}
use of javax.ws.rs.ServiceUnavailableException in project jersey by jersey.
the class JerseyInvocation method convertToException.
private ProcessingException convertToException(final Response response) {
try {
// Buffer and close entity input stream (if any) to prevent
// leaking connections (see JERSEY-2157).
response.bufferEntity();
final WebApplicationException webAppException;
final int statusCode = response.getStatus();
final Response.Status status = Response.Status.fromStatusCode(statusCode);
if (status == null) {
final Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
webAppException = createExceptionForFamily(response, statusFamily);
} else {
switch(status) {
case BAD_REQUEST:
webAppException = new BadRequestException(response);
break;
case UNAUTHORIZED:
webAppException = new NotAuthorizedException(response);
break;
case FORBIDDEN:
webAppException = new ForbiddenException(response);
break;
case NOT_FOUND:
webAppException = new NotFoundException(response);
break;
case METHOD_NOT_ALLOWED:
webAppException = new NotAllowedException(response);
break;
case NOT_ACCEPTABLE:
webAppException = new NotAcceptableException(response);
break;
case UNSUPPORTED_MEDIA_TYPE:
webAppException = new NotSupportedException(response);
break;
case INTERNAL_SERVER_ERROR:
webAppException = new InternalServerErrorException(response);
break;
case SERVICE_UNAVAILABLE:
webAppException = new ServiceUnavailableException(response);
break;
default:
final Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
webAppException = createExceptionForFamily(response, statusFamily);
}
}
return new ResponseProcessingException(response, webAppException);
} catch (final Throwable t) {
return new ResponseProcessingException(response, LocalizationMessages.RESPONSE_TO_EXCEPTION_CONVERSION_FAILED(), t);
}
}
use of javax.ws.rs.ServiceUnavailableException in project atlasdb by palantir.
the class RsErrorDecoder method decode.
@Override
public RuntimeException decode(String methodKey, feign.Response feignResponse) {
try {
Response response = convertResponseToRs(feignResponse);
int statusCode = response.getStatus();
Response.Status status = Response.Status.fromStatusCode(statusCode);
if (status == null) {
Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
return createExceptionForFamily(response, statusFamily);
} else {
switch(status) {
case BAD_REQUEST:
return new BadRequestException(response);
case UNAUTHORIZED:
return new NotAuthorizedException(response);
case FORBIDDEN:
return new ForbiddenException(response);
case NOT_FOUND:
return new NotFoundException(response);
case METHOD_NOT_ALLOWED:
return new NotAllowedException(response);
case NOT_ACCEPTABLE:
return new NotAcceptableException(response);
case UNSUPPORTED_MEDIA_TYPE:
return new NotSupportedException(response);
case INTERNAL_SERVER_ERROR:
return new InternalServerErrorException(response);
case SERVICE_UNAVAILABLE:
return new ServiceUnavailableException(response);
default:
Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
return createExceptionForFamily(response, statusFamily);
}
}
} catch (Throwable t) {
return new RuntimeException("Failed to convert response to exception", t);
}
}
use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.
the class Meta method datafile.
@Path("datafile/{fileId}")
@GET
@Produces({ "text/xml" })
public String datafile(@PathParam("fileId") Long fileId, @QueryParam("exclude") String exclude, @QueryParam("include") String include, @Context HttpHeaders header, @Context HttpServletResponse response) throws NotFoundException, ServiceUnavailableException /*, PermissionDeniedException, AuthorizationRequiredException*/
{
String retValue = "";
DataFile dataFile = null;
// httpHeaders.add("Content-disposition", "attachment; filename=\"dataverse_files.zip\"");
// httpHeaders.add("Content-Type", "application/zip; name=\"dataverse_files.zip\"");
response.setHeader("Content-disposition", "attachment; filename=\"dataverse_files.zip\"");
dataFile = datafileService.find(fileId);
if (dataFile == null) {
throw new NotFoundException();
}
String fileName = dataFile.getFileMetadata().getLabel().replaceAll("\\.tab$", "-ddi.xml");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
response.setHeader("Content-Type", "application/xml; name=\"" + fileName + "\"");
ByteArrayOutputStream outStream = null;
outStream = new ByteArrayOutputStream();
try {
ddiExportService.exportDataFile(fileId, outStream, exclude, include);
retValue = outStream.toString();
} catch (Exception e) {
// We return Service Unavailable.
throw new ServiceUnavailableException();
}
response.setHeader("Access-Control-Allow-Origin", "*");
return retValue;
}
use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.
the class Access method dvCardImage.
@Path("dvCardImage/{dataverseId}")
@GET
@Produces({ "image/png" })
public InputStream dvCardImage(@PathParam("dataverseId") Long dataverseId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
logger.fine("entering dvCardImage");
Dataverse dataverse = dataverseService.find(dataverseId);
if (dataverse == null) {
logger.warning("Preview: Version service could not locate a DatasetVersion object for id " + dataverseId + "!");
return null;
}
String imageThumbFileName = null;
if (dataverse.getDataverseTheme() != null && dataverse.getDataverseTheme().getLogo() != null && !dataverse.getDataverseTheme().getLogo().equals("")) {
File dataverseLogoFile = getLogo(dataverse);
if (dataverseLogoFile != null) {
logger.fine("dvCardImage: logo file found");
String logoThumbNailPath = null;
InputStream in = null;
try {
if (dataverseLogoFile.exists()) {
logoThumbNailPath = ImageThumbConverter.generateImageThumbnailFromFile(dataverseLogoFile.getAbsolutePath(), 48);
if (logoThumbNailPath != null) {
in = new FileInputStream(logoThumbNailPath);
}
}
} catch (Exception ex) {
in = null;
}
if (in != null) {
logger.fine("dvCardImage: successfully obtained thumbnail for dataverse logo.");
return in;
}
}
}
/*
StorageIO thumbnailDataAccess = null;
if (!dataverse.isHarvested()) {
for (Dataset dataset : datasetService.findPublishedByOwnerId(dataverseId)) {
logger.info("dvCardImage: checking dataset "+dataset.getGlobalId());
if (dataset != null) {
DatasetVersion releasedVersion = dataset.getReleasedVersion();
logger.info("dvCardImage: obtained released version "+releasedVersion.getTitle());
thumbnailDataAccess = getThumbnailForDatasetVersion(releasedVersion);
if (thumbnailDataAccess != null) {
logger.info("dvCardImage: obtained thumbnail for the version.");
break;
}
}
}
}
if (thumbnailDataAccess != null && thumbnailDataAccess.getInputStream() != null) {
return thumbnailDataAccess.getInputStream();
}
*/
return null;
}
Aggregations