List of usage examples for java.lang ClassNotFoundException getMessage
public String getMessage()
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Returns the format type stored for the given resource identifier if * the resource exists; otherwise, throw a ResourceNotFoundException. * // w ww . java 2 s. c om * @param resourceId the resource identifier * @param authToken the authorization token * @return the format type * @throws ClassNotFoundException * @throws SQLException * @throws UnauthorizedException * @throws ResourceNotFoundException * @throws Exception */ public String readResourceFormatType(String resourceId, AuthToken authToken) throws ClassNotFoundException, SQLException, UnauthorizedException, ResourceNotFoundException, Exception { String formatType = null; String user = authToken.getUserId(); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); /* * Check whether user is authorized to read the resource */ Authorizer authorizer = new Authorizer(dataPackageRegistry); boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read); if (!isAuthorized) { String gripe = String.format("User %s does not have permission to read this resource: %s", user, resourceId); throw new UnauthorizedException(gripe); } formatType = dataPackageRegistry.getFormatType(resourceId); if (formatType == null) { String gripe = String.format("A formatType does not exist for this resource: %s", resourceId); throw new ResourceNotFoundException(gripe); } } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } return formatType; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Determines whether the user identified by the authentication token is * authorized to access the given resource identifier with the given * permission./* w w w . j a v a2s. c o m*/ * * @param authToken * The user's authentication token. * @param resourceId * The resource identifier of the requested resource. * @param permission * The requested permission for accessing the resource (e.g., READ). * @return The boolean result of the request. * @throws IllegalArgumentException, UnauthorizedException */ public Boolean isAuthorized(AuthToken authToken, String resourceId, Rule.Permission permission) throws IllegalArgumentException, UnauthorizedException { Boolean isAuthorized = null; DataPackageRegistry dpr = null; String userId = authToken.getUserId(); if (resourceId == null || resourceId.isEmpty()) { String gripe = "ResourceId parameter is null or is empty!"; throw new IllegalArgumentException(gripe); } try { dpr = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); } Authorizer authorizer = new Authorizer(dpr); try { isAuthorized = authorizer.isAuthorized(authToken, resourceId, permission); if (!isAuthorized) { String gripe = "User \"" + userId + "\" is not authorized to " + permission + " this " + resourceId + " resource!"; throw new UnauthorizedException(gripe); } } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); } return isAuthorized; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Returns the entity name for the given entity resource identifier if it * exists; otherwise, throw a ResourceNotFoundException. Authorization for * reading the entity name is based on access rules for the data package * resource, not on the access rules for the data entity resource. * // w w w. j a va2 s. c o m * @param dataPackageResourceId * the data package resource identifier, used for authorization * purposes * @param entityResourceId * the entity resource identifier, used as the key to the entityName * value * @param authToken * the authentication token object * @return the data entity name string for this resource, if it exists * @throws ClassNotFoundException * @throws SQLException * @throws UnauthorizedException * @throws ResourceNotFoundException * @throws Exception */ public String readDataEntityName(String dataPackageResourceId, String entityResourceId, AuthToken authToken) throws ClassNotFoundException, SQLException, UnauthorizedException, ResourceNotFoundException, Exception { String entityName = null; String user = authToken.getUserId(); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); /* * Check whether user is authorized to read the data entity. This is based * on the access rules specified for the data package, not on the access * rules specified for reading the data entity. */ Authorizer authorizer = new Authorizer(dataPackageRegistry); boolean isAuthorized = authorizer.isAuthorized(authToken, dataPackageResourceId, Rule.Permission.read); if (!isAuthorized) { String gripe = "User " + user + " does not have permission to read the entity name for this resource: " + entityResourceId; throw new UnauthorizedException(gripe); } entityName = dataPackageRegistry.getDataEntityName(entityResourceId); if (entityName == null) { String gripe = "An entityName value does not exist for this resource: " + entityResourceId; throw new ResourceNotFoundException(gripe); } } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); } return entityName; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * For the specified data package, returns a newline-separated * list of strings, where each string contains an entity id followed by a * comma followed by the name of that entity. * /*from w w w . java 2 s . c o m*/ * @param scope * the scope value * @param identifier * the identifier value * @param revision * the revision value * @param authToken * the authorization token * @return a newline-separated list of strings, where each string contains an entity id followed by a * comma followed by the entity name. * @throws ClassNotFoundException * @throws SQLException * @throws UnauthorizedException * @throws ResourceNotFoundException * @throws Exception */ public String readDataEntityNames(String scope, Integer identifier, Integer revision, AuthToken authToken) throws ClassNotFoundException, SQLException, UnauthorizedException, ResourceNotFoundException, Exception { String entityNames = null; String packageId = String.format("%s.%d.%d", scope, identifier, revision); StringBuilder stringBuilder = new StringBuilder(""); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); Authorizer authorizer = new Authorizer(dataPackageRegistry); entityNames = dataPackageRegistry.getEntityNames(scope, identifier, revision); if (entityNames == null) { String gripe = "No entity name values found for this data package: " + packageId; throw new ResourceNotFoundException(gripe); } else { String[] lines = entityNames.split("\n"); for (String line : lines) { if ((line != null) && (line.length() > 0)) { String[] keyValuePair = line.split(","); if (keyValuePair.length >= 2) { int firstCommaPosition = line.indexOf(','); String entityId = line.substring(0, firstCommaPosition); String entityName = line.substring(firstCommaPosition + 1); String resourceId = DataPackageManager.composeResourceId(ResourceType.data, scope, identifier, revision, entityId); boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read); if (isAuthorized) { stringBuilder.append(String.format("%s,%s\n", entityId, entityName)); } } } } } } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); } entityNames = stringBuilder.toString(); return entityNames; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * For the specified data package, returns a newline-separated * list of strings, where each string contains an entity id followed by a * comma followed by the size of that entity (in bytes). * Throws a ResourceNotFoundException if the specified data package does * not exist./*www. j a va 2 s .c o m*/ * * @param scope * the scope value * @param identifier * the identifier value * @param revision * the revision value * @param authToken * the authorization token * @return a newline-separated list of strings, where each string contains an entity id followed by a * comma followed by an integer representing the size (in bytes) of that entity. * @throws ClassNotFoundException * @throws SQLException * @throws UnauthorizedException * @throws ResourceNotFoundException * @throws Exception */ public String readEntitySizes(String scope, Integer identifier, Integer revision, AuthToken authToken) throws ClassNotFoundException, SQLException, UnauthorizedException, ResourceNotFoundException, Exception { String entitySizes = null; String packageId = String.format("%s.%d.%d", scope, identifier, revision); StringBuilder stringBuilder = new StringBuilder(""); String user = authToken.getUserId(); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); Authorizer authorizer = new Authorizer(dataPackageRegistry); entitySizes = dataPackageRegistry.getEntitySizes(scope, identifier, revision); if (entitySizes == null) { String gripe = "No entity size values found for this data package: " + packageId; throw new ResourceNotFoundException(gripe); } else { String[] lines = entitySizes.split("\n"); for (String line : lines) { if ((line != null) && (line.length() > 0)) { String[] keyValuePair = line.split(","); if (keyValuePair.length == 2) { String entityId = keyValuePair[0]; String entitySize = keyValuePair[1]; String resourceId = DataPackageManager.composeResourceId(ResourceType.data, scope, identifier, revision, entityId); boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read); if (isAuthorized) { stringBuilder.append(String.format("%s,%s\n", entityId, entitySize)); } } } } } } catch (ClassNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error(e.getMessage()); e.printStackTrace(); throw (e); } entitySizes = stringBuilder.toString(); return entitySizes; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Gets a database connection from the pool. Implementation of this method is * required by the DatabaseConnectionPoolInterface. Note that in this example, * there is no actual pool of connections. A full-fledged application should * manage a pool of connections that can be re-used. * /*from ww w . ja v a 2 s . co m*/ * @return checked out connection * @throws SQLException */ public Connection getConnection() throws SQLException, ConnectionNotAvailableException { Connection connection = null; try { Class.forName(dbDriver); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); throw (new SQLException(e.getMessage())); } try { connection = DriverManager.getConnection(dbURL, dbUser, dbPassword); } catch (SQLException e) { System.err.println("SQLException: " + e.getMessage()); throw (e); } return connection; }
From source file:org.cloudifysource.esc.shell.installer.CloudGridAgentBootstrapper.java
/** * loads the provisioning driver class and sets it up. * /*from w w w . j a v a2 s . com*/ * @param performValidation * true to perform cloud configuration validations before bootstrap, false otherwise * @throws CLIException * Indicates the configured could not be found and instantiated */ private void createProvisioningDriver(final boolean performValidation) throws CLIException { try { final ProvisioningDriverClassBuilder builder = new ProvisioningDriverClassBuilder(); final Object computeProvisioningInstance = builder.build(providerDirectory.getAbsolutePath(), cloud.getConfiguration().getClassName()); provisioning = ComputeDriverProvisioningAdapter.create(computeProvisioningInstance); } catch (final ClassNotFoundException e) { throw new CLIException("Failed to load provisioning class for cloud: " + cloud.getName() + ". Class not found: " + cloud.getConfiguration().getClassName(), e); } catch (final Exception e) { throw new CLIException("Failed to load provisioning class for cloud: " + cloud.getName(), e); } provisioning.setProvisioningDriverClassContext(new DefaultProvisioningDriverClassContext()); provisioning.addListener(new CliProvisioningDriverListener()); final String serviceName = null; final ValidationContext validationContext = new ValidationContextImpl(); try { if (performValidation) { new BootstrapUrlValidator(cloud).validateCloudifyUrls(validationContext); } final ComputeDriverConfiguration configuration = new ComputeDriverConfiguration(); configuration.setAdmin(null); configuration.setCloud(cloud); configuration.setCloudTemplate(cloud.getConfiguration().getManagementMachineTemplate()); configuration.setManagement(true); configuration.setServiceName(serviceName); provisioning.setConfig(configuration); if (performValidation) { validationContext.validationEvent(ValidationMessageType.TOP_LEVEL_VALIDATION_MESSAGE, ShellUtils .getFormattedMessage(CloudifyErrorMessages.EVENT_VALIDATE_CLOUD_CONFIG.getName())); try { provisioning.validateCloudConfiguration(validationContext); } catch (final UnsupportedOperationException e) { // ignore } validationContext.validationEvent(ValidationMessageType.TOP_LEVEL_VALIDATION_MESSAGE, ShellUtils .getFormattedMessage(CloudifyErrorMessages.EVENT_CLOUD_CONFIG_VALIDATED.getName())); } } catch (final CloudProvisioningException e) { throw new CLIException(e.getMessage(), e); } }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Reads a data entity and returns it as a byte array. The specified user must * be authorized to read the data entity resource. * //from w w w . ja v a2 s .c o m * @param scope * The scope of the data package. * @param identifier * The identifier of the data package. * @param revision * The revision of the data package. * @param entityId * The entityId of the data package. * @param user * The user name * @return a File object containing the locally stored entity data */ public File getDataEntityFile(String scope, Integer identifier, String revision, String entityId, AuthToken authToken, String user) throws ClassNotFoundException, SQLException, ClientProtocolException, IOException, Exception { File file = null; boolean hasDataPackage = false; Integer revisionInt = new Integer(revision); String resourceId = composeResourceId(ResourceType.data, scope, identifier, revisionInt, entityId); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); hasDataPackage = dataPackageRegistry.hasDataPackage(scope, identifier, revision); if (!hasDataPackage) { String message = "Attempting to read a data entity that does not exist in PASTA: " + resourceId; throw new ResourceNotFoundException(message); } /* * If we have the data package but it was previously deleted (i.e. * de-activated) * * Note: This logic is no longer valid as of Ticket #912: * https://trac.lternet.edu/trac/NIS/ticket/912 * boolean isDeactivatedDataPackage = dataPackageRegistry .isDeactivatedDataPackage(scope, identifier); if (isDeactivatedDataPackage) { String message = "Attempting to read a data entity that was previously deleted from PASTA: " + resourceId; throw new ResourceDeletedException(message); }*/ /* * Now that we know that the data package is in the registry, check * whether the user is authorized to read the data entity. */ Authorizer authorizer = new Authorizer(dataPackageRegistry); boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read); if (!isAuthorized) { String message = "User " + user + " does not have permission to read this data entity: " + resourceId; throw new UnauthorizedException(message); } DataManagerClient dataManagerClient = new DataManagerClient(); String resourceLocation = dataPackageRegistry.getResourceLocation(resourceId); file = dataManagerClient.getDataEntityFile(resourceLocation, scope, identifier, revision, entityId); } catch (ClassNotFoundException e) { logger.error("Error connecting to Data Package Registry: " + e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error("Error connecting to Data Package Registry: " + e.getMessage()); e.printStackTrace(); throw (e); } return file; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java
/** * Reads metadata from the Metadata Catalog and returns it as a String. The * specified user must be authorized to read the metadata resource. * /* ww w . j ava 2s . co m*/ * @param scope * The scope of the metadata document. * @param identifier * The identifier of the metadata document. * @param revision * The revision of the metadata document. * @param user * The user name value * @param authToken * The AuthToken object * @return The metadata document, an XML string. */ public File getMetadataFile(String scope, Integer identifier, String revision, String user, AuthToken authToken) throws ClassNotFoundException, SQLException, ClientProtocolException, IOException, Exception { String entityId = null; File levelOneEMLFile = null; boolean hasDataPackage = false; Integer revisionInt = new Integer(revision); String metadataId = composeResourceId(ResourceType.metadata, scope, identifier, revisionInt, entityId); try { DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword); hasDataPackage = dataPackageRegistry.hasDataPackage(scope, identifier, revision); if (hasDataPackage) { /* * If we have the data package but it was previously deleted (i.e. * de-activated) * * Note: This logic is no longer valid as of Ticket #912: * https://trac.lternet.edu/trac/NIS/ticket/912 * * boolean isDeactivatedDataPackage = dataPackageRegistry .isDeactivatedDataPackage(scope, identifier); if (isDeactivatedDataPackage) { String message = "Attempting to read a metadata document that was " + "previously deleted from PASTA: " + metadataId; throw new ResourceDeletedException(message); } */ /* * Check whether user is authorized to read the data package metadata */ Authorizer authorizer = new Authorizer(dataPackageRegistry); boolean isAuthorized = authorizer.isAuthorized(authToken, metadataId, Rule.Permission.read); if (!isAuthorized) { String message = "User " + user + " does not have permission to read this metadata document: " + metadataId; throw new UnauthorizedException(message); } EmlPackageIdFormat emlPackageIdFormat = new EmlPackageIdFormat(); EmlPackageId emlPackageId = emlPackageIdFormat.parse(scope, identifier.toString(), revision); DataPackageMetadata dataPackageMetadata = new DataPackageMetadata(emlPackageId); if (dataPackageMetadata != null) { boolean evaluateMode = false; levelOneEMLFile = dataPackageMetadata.getMetadata(evaluateMode); } } } catch (ClassNotFoundException e) { logger.error("Error connecting to Data Package Registry: " + e.getMessage()); e.printStackTrace(); throw (e); } catch (SQLException e) { logger.error("Error connecting to Data Package Registry: " + e.getMessage()); e.printStackTrace(); throw (e); } return levelOneEMLFile; }