use of org.apache.nifi.minifi.c2.api.Configuration in project nifi-minifi by apache.
the class ConfigService method initConfigurationProviderValue.
public ConfigurationProviderValue initConfigurationProviderValue(ConfigurationProviderKey key) {
if (logger.isDebugEnabled()) {
logger.debug("Attempting to load and cache configuration with key " + key);
}
try {
List<MediaType> acceptValues = key.getAcceptValues();
Pair<MediaType, ConfigurationProvider> providerPair = getProvider(acceptValues);
Map<String, List<String>> parameters = key.getParameters();
Integer version = null;
List<String> versionList = parameters.get("version");
if (versionList != null && versionList.size() > 0) {
try {
version = Integer.parseInt(versionList.get(0));
} catch (NumberFormatException e) {
throw new InvalidParameterException("Unable to parse " + version + " as integer.", e);
}
}
return new ConfigurationProviderValue(providerPair.getSecond().getConfiguration(providerPair.getFirst().toString(), version, parameters), providerPair.getFirst(), null);
} catch (ConfigurationProviderException e) {
return new ConfigurationProviderValue(null, null, e);
}
}
use of org.apache.nifi.minifi.c2.api.Configuration in project nifi-minifi by apache.
the class ConfigService method getContentTypes.
@GET
@Path("/contentTypes")
@Produces(MediaType.APPLICATION_JSON)
public Response getContentTypes(@Context HttpServletRequest request, @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();
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
List<String> contentTypes;
try {
contentTypes = configurationProviderInfo.get().getContentTypes();
} catch (ConfigurationProviderException e) {
logger.warn("Unable to initialize content type information.", e);
return Response.status(500).build();
}
try {
objectMapper.writerWithDefaultPrettyPrinter().writeValue(byteArrayOutputStream, contentTypes);
} catch (IOException e) {
logger.warn("Unable to write configuration providers to output stream.", e);
return Response.status(500).build();
}
return Response.ok().type(MediaType.APPLICATION_JSON_TYPE).entity(byteArrayOutputStream.toByteArray()).build();
}
Aggregations