List of usage examples for com.amazonaws.services.s3.model AmazonS3Exception getMessage
@Override
public String getMessage()
From source file:com.gst.infrastructure.documentmanagement.contentrepository.S3ContentRepository.java
License:Apache License
@Override public ImageData fetchImage(final ImageData imageData) { try {/*from w w w . j a va2 s. c om*/ final S3Object s3object = this.s3Client .getObject(new GetObjectRequest(this.s3BucketName, imageData.location())); imageData.updateContent(s3object.getObjectContent()); } catch (AmazonS3Exception e) { logger.error(e.getMessage()); } return imageData; }
From source file:com.ibm.stocator.fs.cos.COSAPIClient.java
License:Apache License
@Override public FileStatus getFileStatus(String hostName, Path path, String msg) throws IOException, FileNotFoundException { FileStatus res = null;/*from w w w . j a v a2s .co m*/ FileStatus cached = memoryCache.getFileStatus(path.toString()); if (cached != null) { return cached; } LOG.trace("getFileStatus(start) for {}, hostname: {}", path, hostName); /* * The requested path is equal to hostName. HostName is equal to * hostNameScheme, thus the container. Therefore we have no object to look * for and we return the FileStatus as a directory. Containers have to * lastModified. */ if (path.toString().equals(hostName) || (path.toString().length() + 1 == hostName.length())) { LOG.trace("getFileStatus(completed) {}", path); res = new FileStatus(0L, true, 1, mBlockSize, 0L, path); memoryCache.putFileStatus(path.toString(), res); return res; } if (path.toString().contains(HADOOP_TEMPORARY)) { LOG.debug("getFileStatus on temp object {}. Return not found", path.toString()); throw new FileNotFoundException("Not found " + path.toString()); } String key = pathToKey(hostName, path); LOG.debug("getFileStatus: on original key {}", key); try { FileStatus fileStatus = null; try { fileStatus = getFileStatusKeyBased(key, path); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) { throw new IOException(e); } } if (fileStatus != null) { LOG.trace("getFileStatus(completed) {}", path); memoryCache.putFileStatus(path.toString(), fileStatus); return fileStatus; } // means key returned not found. Trying to call get file status on key/ // probably not needed this call if (!key.endsWith("/")) { String newKey = key + "/"; try { LOG.debug("getFileStatus: original key not found. Alternative key {}", key); fileStatus = getFileStatusKeyBased(newKey, path); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) { throw new IOException(e); } } if (fileStatus != null) { LOG.trace("getFileStatus(completed) {}", path); memoryCache.putFileStatus(path.toString(), fileStatus); return fileStatus; } else { // if here: both key and key/ returned not found. // trying to see if pseudo directory of the form // a/b/key/d/e (a/b/key/ doesn't exists by itself) // perform listing on the key LOG.debug("getFileStatus: Modifined key {} not found. Trying to lisr", key); key = maybeAddTrailingSlash(key); ListObjectsRequest request = new ListObjectsRequest(); request.setBucketName(mBucket); request.setPrefix(key); request.setDelimiter("/"); request.setMaxKeys(1); ObjectListing objects = mClient.listObjects(request); if (!objects.getCommonPrefixes().isEmpty() || !objects.getObjectSummaries().isEmpty()) { LOG.trace("getFileStatus(completed) {}", path); res = new FileStatus(0, true, 1, 0, 0, path); memoryCache.putFileStatus(path.toString(), res); return res; } else if (key.isEmpty()) { LOG.debug("Found root directory"); LOG.trace("getFileStatus(completed) {}", path); res = new FileStatus(0, true, 1, 0, 0, path); memoryCache.putFileStatus(path.toString(), res); return res; } } } } catch (AmazonS3Exception e) { if (e.getStatusCode() == 403) { throw new IOException(e); } } catch (Exception e) { LOG.debug("Not found {}", path.toString()); LOG.warn(e.getMessage()); throw new FileNotFoundException("Not found " + path.toString()); } throw new FileNotFoundException("Not found " + path.toString()); }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.AwsInfiniteFile.java
License:Open Source License
@Override public void rename(String newPathName) throws IOException { try {/*from w w w .jav a2 s .c om*/ String oldBucket = _awsBucketName; String oldName = _awsObjectName; getBucketAndObjectName(newPathName, true); // (renames self) _awsObjectName = new URI("").resolve(_awsObjectName).getPath(); // (resolve relative paths) // Check parent directory exists: int index = _awsObjectName.lastIndexOf('/'); if (index > 0) { String oldParentDir = _awsObjectName.substring(0, 1 + index); // (don't include the "/" so will try to create) GetObjectMetadataRequest objMetaRequest = new GetObjectMetadataRequest(_awsBucketName, oldParentDir); ((AmazonS3Client) _awsClient).getObjectMetadata(objMetaRequest); } // Create actual file: ((AmazonS3Client) _awsClient).copyObject(oldBucket, oldName, _awsBucketName, _awsObjectName); _awsBucketName = oldBucket; _awsObjectName = oldName; // (copy back again before deleting) delete(); // (original, only gets this far if the copyObject succeeds, else it exceptions out) } catch (AmazonS3Exception e) { throw new IOException(e.getMessage()); } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } }
From source file:com.scoyo.tools.s3cacheenhancer.S3HeaderEnhancer.java
License:Apache License
private void setHeaders(ObjectListing listing, final String maxAgeHeader, ExecutorService executorService) { for (final S3ObjectSummary summary : listing.getObjectSummaries()) { executorService.submit(new Runnable() { @Override//from w ww . jav a2 s . c o m public void run() { String bucket = summary.getBucketName(); String key = summary.getKey(); ObjectMetadata metadata = null; try { metadata = s3.getObjectMetadata(bucket, key); } catch (AmazonS3Exception exception) { System.out.println("Could not update " + key + " [" + exception.getMessage() + "]"); return; } if ("application/x-directory".equals(metadata.getContentType())) { System.out.println("Skipping because content-type " + key); return; } if (!maxAgeHeader.equals(metadata.getCacheControl())) { metadata.setCacheControl(maxAgeHeader); } else { System.out.println("Skipping because header is already correct " + key); return; } AccessControlList acl = s3.getObjectAcl(summary.getBucketName(), summary.getKey()); CopyObjectRequest copyReq = new CopyObjectRequest(bucket, key, bucket, key) .withAccessControlList(acl).withNewObjectMetadata(metadata); CopyObjectResult result = s3.copyObject(copyReq); if (result != null) { System.out.println("Updated " + key); } else { System.out.println("Could not update " + key); } } }); } }
From source file:com.wowza.wms.plugin.s3upload.ModuleS3Upload.java
License:Open Source License
public void onAppStart(IApplicationInstance appInstance) { logger = WMSLoggerFactory.getLoggerObj(appInstance); this.appInstance = appInstance; try {//from w ww . j a va 2s . co m WMSProperties props = appInstance.getProperties(); accessKey = props.getPropertyStr("s3UploadAccessKey", accessKey); secretKey = props.getPropertyStr("s3UploadSecretKey", secretKey); bucketName = props.getPropertyStr("s3UploadBucketName", bucketName); endpoint = props.getPropertyStr("s3UploadEndpoint", endpoint); resumeUploads = props.getPropertyBoolean("s3UploadResumeUploads", resumeUploads); deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeletOriginalFiles", deleteOriginalFiles); // fix typo in property name deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeleteOriginalFiles", deleteOriginalFiles); // This value should be the URI representation of the "Group Grantee" found here http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html under "Amazon S3 Predefined Groups" aclGroupGranteeUri = props.getPropertyStr("s3UploadACLGroupGranteeUri", aclGroupGranteeUri); // This should be a string that represents the level of permissions we want to grant to the "Group Grantee" access to the file to be uploaded aclPermissionRule = props.getPropertyStr("s3UploadACLPermissionRule", aclPermissionRule); // With the passed property, check if it maps to a specified GroupGrantee GroupGrantee grantee = GroupGrantee.parseGroupGrantee(aclGroupGranteeUri); // In order for the parsing to work correctly, we will go ahead and force uppercase on the string passed Permission permission = Permission.parsePermission(aclPermissionRule.toUpperCase()); // If we have properties for specifying permisions on the file upload, create the AccessControlList object and set the Grantee and Permissions if (grantee != null && permission != null) { acl = new AccessControlList(); acl.grantPermission(grantee, permission); } if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(secretKey)) { logger.warn( MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr() + "] missing S3 credentials", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); return; } AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); if (!StringUtils.isEmpty(endpoint)) s3Client.setEndpoint(endpoint); if (!StringUtils.isEmpty(bucketName)) { boolean hasBucket = false; List<Bucket> buckets = s3Client.listBuckets(); for (Bucket bucket : buckets) { if (bucket.getName().equals(bucketName)) { hasBucket = true; break; } } if (!hasBucket) { logger.warn(MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr() + "] missing S3 bucket: " + bucketName, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); return; } } logger.info(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] S3 Bucket Name: " + bucketName + ", Resume Uploads: " + resumeUploads + ", Delete Original Files: " + deleteOriginalFiles, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); transferManager = new TransferManager(s3Client); resumeUploads(); appInstance.addMediaWriterListener(new WriteListener()); } catch (AmazonS3Exception ase) { logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] AmazonS3Exception: " + ase.getMessage()); } catch (Exception e) { logger.error( MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] exception: " + e.getMessage(), e); } catch (Throwable t) { logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] throwable exception: " + t.getMessage(), t); } }
From source file:io.dockstore.webservice.resources.ToolTesterResource.java
License:Apache License
@GET @Timed// ww w .j a v a 2 s . c o m @Path("logs") @Operation(summary = "Get ToolTester log file") @Produces(MediaType.TEXT_PLAIN) public String getToolTesterLog( @QueryParam("tool_id") @Parameter(description = "TRS Tool Id", example = "#workflow/github.com/dockstore/hello_world", required = true) String toolId, @QueryParam("tool_version_name") @Parameter(example = "v1.0.0", required = true) String toolVersionName, @QueryParam("test_filename") @Parameter(example = "hello_world.cwl.json", required = true) String testFilename, @QueryParam("runner") @Parameter(example = "cwltool", required = true) String runner, @QueryParam("log_type") @Parameter(required = true) ToolTesterLogType logType, @QueryParam("filename") @Parameter(example = "1554477737092.log", required = true) String filename) { if (this.bucketName == null) { throw new CustomWebApplicationException("Dockstore Logging integration is currently not set up", HttpStatus.SC_SERVICE_UNAVAILABLE); } ToolTesterS3Client toolTesterS3Client = new ToolTesterS3Client(this.bucketName); try { return toolTesterS3Client.getToolTesterLog(toolId, toolVersionName, testFilename, runner, filename); } catch (AmazonS3Exception e) { LOG.error(e.getMessage(), e); throw new CustomWebApplicationException("Dockstore Logging integration is currently not set up", HttpStatus.SC_SERVICE_UNAVAILABLE); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new CustomWebApplicationException("Could not fetch log file contents", HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:io.dockstore.webservice.resources.ToolTesterResource.java
License:Apache License
@GET @Timed/*from w ww . j av a 2 s . c om*/ @Path("logs/search") @Operation(summary = "Search for ToolTester log files") public List<ToolTesterLog> search( @QueryParam("tool_id") @Parameter(description = "TRS Tool Id", example = "#workflow/github.com/dockstore/hello_world", required = true) String toolId, @QueryParam("tool_version_name") @Parameter(example = "v1.0.0", required = true) String toolVersionName) { if (this.bucketName == null) { throw new CustomWebApplicationException("Dockstore Logging integration is currently not set up", HttpStatus.SC_SERVICE_UNAVAILABLE); } try { ToolTesterS3Client toolTesterS3Client = new ToolTesterS3Client(this.bucketName); return toolTesterS3Client.getToolTesterLogs(toolId, toolVersionName); } catch (AmazonS3Exception e) { LOG.error(e.getMessage(), e); throw new CustomWebApplicationException("Dockstore Logging integration is currently not set up", HttpStatus.SC_SERVICE_UNAVAILABLE); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); throw new CustomWebApplicationException("Could not find log file location", HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:org.geowebcache.s3.S3Ops.java
License:Open Source License
@Nullable public ObjectMetadata getObjectMetadata(String key) throws StorageException { ObjectMetadata obj = null;/*from w w w. j a v a 2s .com*/ try { obj = conn.getObjectMetadata(bucketName, key); } catch (AmazonS3Exception e) { if (404 != e.getStatusCode()) {// 404 == not found throw new StorageException("Error checking existence of " + key + ": " + e.getMessage(), e); } } return obj; }
From source file:org.geowebcache.s3.S3Ops.java
License:Open Source License
@Nullable public S3Object getObject(String key) throws StorageException { final S3Object object; try {//from w ww . j a v a2 s .c o m object = conn.getObject(bucketName, key); } catch (AmazonS3Exception e) { if (404 == e.getStatusCode()) {// 404 == not found return null; } throw new StorageException("Error fetching " + key + ": " + e.getMessage(), e); } if (isPendingDelete(object)) { return null; } return object; }
From source file:org.pentaho.amazon.s3.S3VfsFileChooserDialog.java
License:Apache License
private void createConnectionPanel() { // The Connection group Group connectionGroup = new Group(this, SWT.SHADOW_ETCHED_IN); connectionGroup.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.ConnectionGroup.Label")); //$NON-NLS-1$; GridLayout connectionGroupLayout = new GridLayout(); connectionGroupLayout.marginWidth = 5; connectionGroupLayout.marginHeight = 5; connectionGroupLayout.verticalSpacing = 5; connectionGroupLayout.horizontalSpacing = 5; GridData gData = new GridData(SWT.FILL, SWT.FILL, true, false); connectionGroup.setLayoutData(gData); connectionGroup.setLayout(connectionGroupLayout); // The composite we need in the group Composite textFieldPanel = new Composite(connectionGroup, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); textFieldPanel.setLayoutData(gridData); textFieldPanel.setLayout(new GridLayout(3, false)); // URL label and text field wlAccessKey = new Label(textFieldPanel, SWT.RIGHT); wlAccessKey.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.AccessKey.Label")); //$NON-NLS-1$ fdlAccessKey = new GridData(); fdlAccessKey.widthHint = 75;//from w w w . j a va 2s .c o m wlAccessKey.setLayoutData(fdlAccessKey); wAccessKey = new TextVar(getVariableSpace(), textFieldPanel, SWT.PASSWORD | SWT.SINGLE | SWT.LEFT | SWT.BORDER); fdAccessKey = new GridData(); fdAccessKey.widthHint = 150; wAccessKey.setLayoutData(fdAccessKey); wAccessKey.setText(Encr.decryptPasswordOptionallyEncrypted( Props.getInstance().getCustomParameter("S3VfsFileChooserDialog.AccessKey", ""))); wAccessKey.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent arg0) { handleConnectionButton(); } }); // // Place holder wPlaceHolderLabel = new Label(textFieldPanel, SWT.RIGHT); wPlaceHolderLabel.setText(""); fdlPlaceHolderLabel = new GridData(); fdlPlaceHolderLabel.widthHint = 75; wPlaceHolderLabel.setLayoutData(fdlPlaceHolderLabel); // UserID label and field wlSecretKey = new Label(textFieldPanel, SWT.RIGHT); wlSecretKey.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.SecretKey.Label")); fdlSecretKey = new GridData(); fdlSecretKey.widthHint = 75; wlSecretKey.setLayoutData(fdlSecretKey); wSecretKey = new TextVar(getVariableSpace(), textFieldPanel, SWT.PASSWORD | SWT.SINGLE | SWT.LEFT | SWT.BORDER); fdSecretKey = new GridData(); fdSecretKey.widthHint = 300; wSecretKey.setLayoutData(fdSecretKey); wSecretKey.setText(Encr.decryptPasswordOptionallyEncrypted( Props.getInstance().getCustomParameter("S3VfsFileChooserDialog.SecretKey", ""))); wSecretKey.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent arg0) { handleConnectionButton(); } }); // bucket // wlBucket = new Label(textFieldPanel, SWT.RIGHT); // wlBucket.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.Bucket.Label")); //$NON-NLS-1$ // fdlBucket = new GridData(); // fdlBucket.widthHint = 75; // wlBucket.setLayoutData(fdlBucket); // // wBucket = new Text(textFieldPanel, SWT.SINGLE | SWT.LEFT | SWT.BORDER); // fdBucket = new GridData(); // fdBucket.widthHint = 150; // wBucket.setLayoutData(fdBucket); // wBucket.addKeyListener(new KeyAdapter() { // public void keyPressed(KeyEvent e) { // handleConnectionButton(); // } // }); // Connection button wConnectionButton = new Button(textFieldPanel, SWT.CENTER); fdConnectionButton = new GridData(); fdConnectionButton.widthHint = 75; wConnectionButton.setLayoutData(fdConnectionButton); wConnectionButton.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.ConnectionButton.Label")); wConnectionButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // let's verify the accessKey/secretKey AmazonS3 s3Client = new AmazonS3Client(new AWSCredentials() { public String getAWSSecretKey() { return Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute(wSecretKey.getText())); } public String getAWSAccessKeyId() { return Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute(wAccessKey.getText())); } }); s3Client.getS3AccountOwner(); // s3 credentials valid, continue Props.getInstance().setCustomParameter("S3VfsFileChooserDialog.AccessKey", Encr.encryptPasswordIfNotUsingVariables(wAccessKey.getText())); Props.getInstance().setCustomParameter("S3VfsFileChooserDialog.SecretKey", Encr.encryptPasswordIfNotUsingVariables(wSecretKey.getText())); try { FileObject root = rootFile; root = resolveFile(buildS3FileSystemUrlString()); vfsFileChooserDialog.setSelectedFile(root); vfsFileChooserDialog.setRootFile(root); rootFile = root; } catch (FileSystemException e1) { MessageBox box = new MessageBox(getShell()); box.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.error")); //$NON-NLS-1$ box.setMessage(e1.getMessage()); log.logError(e1.getMessage(), e1); box.open(); return; } } catch (AmazonS3Exception ex) { // if anything went wrong, we have to show an error dialog MessageBox box = new MessageBox(getShell()); box.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.error")); //$NON-NLS-1$ box.setMessage(ex.getMessage()); log.logError(ex.getMessage(), ex); box.open(); return; } } }); // set the tab order textFieldPanel.setTabList(new Control[] { wAccessKey, wSecretKey, wConnectionButton }); // textFieldPanel.setTabList(new Control[] { wAccessKey, wBucket, wSecretKey, wPassword, wConnectionButton }); }