use of com.google.common.util.concurrent.UncheckedExecutionException in project nifi-minifi by apache.
the class ConfigService method getConfig.
@GET
public Response getConfig(@Context HttpServletRequest request, @Context HttpHeaders httpHeaders, @Context UriInfo uriInfo) {
try {
authorizer.authorize(SecurityContextHolder.getContext().getAuthentication(), uriInfo);
} catch (AuthorizationException e) {
logger.warn(HttpRequestUtil.getClientString(request) + " not authorized to access " + uriInfo, e);
return Response.status(403).build();
}
Map<String, List<String>> parameters = new HashMap<>();
for (Map.Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
parameters.put(entry.getKey(), entry.getValue());
}
List<MediaType> acceptValues = httpHeaders.getAcceptableMediaTypes();
boolean defaultAccept = false;
if (acceptValues.size() == 0) {
acceptValues = Arrays.asList(MediaType.WILDCARD_TYPE);
defaultAccept = true;
}
if (logger.isDebugEnabled()) {
StringBuilder builder = new StringBuilder("Handling request from ").append(HttpRequestUtil.getClientString(request)).append(" with parameters ").append(parameters).append(" and Accept");
if (defaultAccept) {
builder = builder.append(" default value");
}
builder = builder.append(": ").append(acceptValues.stream().map(Object::toString).collect(Collectors.joining(", ")));
logger.debug(builder.toString());
}
try {
ConfigurationProviderValue configurationProviderValue = configurationCache.get(new ConfigurationProviderKey(acceptValues, parameters));
Configuration configuration = configurationProviderValue.getConfiguration();
Response.ResponseBuilder ok = Response.ok();
ok = ok.header("X-Content-Version", configuration.getVersion());
ok = ok.type(configurationProviderValue.getMediaType());
byte[] buffer = new byte[1024];
int read;
try (InputStream inputStream = configuration.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
MessageDigest md5 = MessageDigest.getInstance("MD5");
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
while ((read = inputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, read);
md5.update(buffer, 0, read);
sha256.update(buffer, 0, read);
}
ok = ok.header("Content-MD5", bytesToHex(md5.digest()));
ok = ok.header("X-Content-SHA-256", bytesToHex(sha256.digest()));
ok = ok.entity(outputStream.toByteArray());
} catch (ConfigurationProviderException | IOException | NoSuchAlgorithmException e) {
logger.error("Error reading or checksumming configuration file", e);
throw new WebApplicationException(500);
}
return ok.build();
} catch (AuthorizationException e) {
logger.warn(HttpRequestUtil.getClientString(request) + " not authorized to access " + uriInfo, e);
return Response.status(403).build();
} catch (InvalidParameterException e) {
logger.info(HttpRequestUtil.getClientString(request) + " made invalid request with " + HttpRequestUtil.getQueryString(request), e);
return Response.status(400).entity("Invalid request.").build();
} catch (ConfigurationProviderException e) {
logger.warn("Unable to get configuration.", e);
return Response.status(500).build();
} catch (ExecutionException | UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof WebApplicationException) {
throw (WebApplicationException) cause;
}
logger.error(HttpRequestUtil.getClientString(request) + " made request with " + HttpRequestUtil.getQueryString(request) + " that caused error.", cause);
return Response.status(500).entity("Internal error").build();
}
}
use of com.google.common.util.concurrent.UncheckedExecutionException in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method resolvePath.
static MCRFilesystemNode resolvePath(MCRPath path) throws IOException {
try {
String ifsid = nodeCache.getUnchecked(path);
MCRFilesystemNode node = MCRFilesystemNode.getNode(ifsid);
if (node != null) {
return node;
}
nodeCache.invalidate(path);
return resolvePath(path);
} catch (UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoSuchFileException) {
throw (NoSuchFileException) cause;
}
if (cause instanceof NotDirectoryException) {
throw (NotDirectoryException) cause;
}
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw e;
}
}
use of com.google.common.util.concurrent.UncheckedExecutionException in project java-driver by datastax.
the class CodecRegistry method lookupCodec.
@SuppressWarnings("unchecked")
private <T> TypeCodec<T> lookupCodec(DataType cqlType, TypeToken<T> javaType) {
checkNotNull(cqlType, "Parameter cqlType cannot be null");
TypeCodec<?> codec = BUILT_IN_CODECS_MAP.get(cqlType.getName());
if (codec != null && (javaType == null || codec.accepts(javaType))) {
logger.trace("Returning built-in codec {}", codec);
return (TypeCodec<T>) codec;
}
if (logger.isTraceEnabled())
logger.trace("Querying cache for codec [{} <-> {}]", toString(cqlType), toString(javaType));
try {
CacheKey cacheKey = new CacheKey(cqlType, javaType);
codec = cache.get(cacheKey);
} catch (UncheckedExecutionException e) {
if (e.getCause() instanceof CodecNotFoundException) {
throw (CodecNotFoundException) e.getCause();
}
throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
} catch (RuntimeException e) {
throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
} catch (ExecutionException e) {
throw new CodecNotFoundException(e.getCause(), cqlType, javaType);
}
logger.trace("Returning cached codec {}", codec);
return (TypeCodec<T>) codec;
}
use of com.google.common.util.concurrent.UncheckedExecutionException in project presto by prestodb.
the class BuiltInTypeAndFunctionNamespaceManager method getWindowFunctionImplementation.
public WindowFunctionSupplier getWindowFunctionImplementation(FunctionHandle functionHandle) {
checkArgument(functionHandle instanceof BuiltInFunctionHandle, "Expect BuiltInFunctionHandle");
Signature signature = ((BuiltInFunctionHandle) functionHandle).getSignature();
checkArgument(signature.getKind() == WINDOW || signature.getKind() == AGGREGATE, "%s is not a window function", signature);
checkArgument(signature.getTypeVariableConstraints().isEmpty(), "%s has unbound type parameters", signature);
try {
return specializedWindowCache.getUnchecked(getSpecializedFunctionKey(signature));
} catch (UncheckedExecutionException e) {
throwIfInstanceOf(e.getCause(), PrestoException.class);
throw e;
}
}
use of com.google.common.util.concurrent.UncheckedExecutionException in project cassandra by apache.
the class CodecRegistry method lookupCodec.
@SuppressWarnings("unchecked")
private <T> TypeCodec<T> lookupCodec(DataType cqlType, TypeToken<T> javaType) {
checkNotNull(cqlType, "Parameter cqlType cannot be null");
TypeCodec<?> codec = BUILT_IN_CODECS_MAP.get(cqlType.getName());
if (codec != null && (javaType == null || codec.accepts(javaType))) {
logger.trace("Returning built-in codec {}", codec);
return (TypeCodec<T>) codec;
}
if (logger.isTraceEnabled())
logger.trace("Querying cache for codec [{} <-> {}]", toString(cqlType), toString(javaType));
try {
CacheKey cacheKey = new CacheKey(cqlType, javaType);
codec = cache.get(cacheKey);
} catch (UncheckedExecutionException e) {
if (e.getCause() instanceof CodecNotFoundException) {
throw (CodecNotFoundException) e.getCause();
}
throw new CodecNotFoundException(e.getCause());
} catch (RuntimeException | ExecutionException e) {
throw new CodecNotFoundException(e.getCause());
}
logger.trace("Returning cached codec {}", codec);
return (TypeCodec<T>) codec;
}
Aggregations