Example #1
0
 @Override
 public void setAuthContext(AuthContext info) {
   super.setAuthContext(info);
   //        try {
   //        	client = (AmazonS3)info.get(S3CLIENT_KEY);
   //            logger.debug("s3client=" + client);
   //        } catch (Exception e) {
   //            throw new StorageException(e);
   //        }
 }
Example #2
0
  @Override
  public void createContainer(String container, Config config) {
    super.createContainer(container, config);
    try {
      if (!client.doesBucketExist(container)) {

        client.createBucket(container);
      }
    } catch (Exception e) {
      throw new StorageException(e);
    }
  }
Example #3
0
 @Override
 public void deleteObject(String container, String object, Config config) {
   super.deleteObject(container, object, config);
   try {
     client.deleteObject(container, object);
   } catch (AmazonS3Exception awse) {
     if (awse.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
       throw new StorageException(awse);
     }
   } catch (Exception e) {
     throw new StorageException(e);
   }
 }
Example #4
0
  @Override
  public InputStream getObject(String container, String object, Config config) {
    super.getObject(container, object, config);
    InputStream stream;
    try {

      S3Object s3Obj = client.getObject(container, object);
      stream = s3Obj.getObjectContent();

    } catch (Exception e) {
      throw new StorageException(e);
    }
    return stream;
  }
Example #5
0
  @Override
  public void createObject(
      String container, String object, InputStream data, long length, Config config) {
    super.createObject(container, object, data, length, config);
    try {
      ObjectMetadata metadata = new ObjectMetadata();
      metadata.setContentLength(length);
      metadata.setContentType("application/octet-stream");

      client.putObject(container, object, data, metadata);
    } catch (Exception e) {
      throw new StorageException(e);
    }
  }
Example #6
0
 @Override
 public void deleteContainer(String container, Config config) {
   super.deleteContainer(container, config);
   try {
     if (client.doesBucketExist(container)) {
       client.deleteBucket(container);
     }
   } catch (AmazonS3Exception awse) {
     if (awse.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
       throw new StorageException(awse);
     }
   } catch (Exception e) {
     throw new StorageException(e);
   }
 }
Example #7
0
  @Override
  public void init(Config config, Logger logger) {
    super.init(config, logger);

    timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);

    parms.put(CONN_TIMEOUT_KEY, timeout);

    endpoint = config.get(ENDPOINT_KEY, ENDPOINT_DEFAULT);
    accessKey = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT);
    secretKey = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT);

    boolean pathStyleAccess = config.getBoolean(PATH_STYLE_ACCESS_KEY, PATH_STYLE_ACCESS_DEFAULT);

    String proxyHost = config.get(PROXY_HOST_KEY, "");
    String proxyPort = config.get(PROXY_PORT_KEY, "");

    parms.put(ENDPOINT_KEY, endpoint);
    parms.put(AUTH_USERNAME_KEY, accessKey);
    parms.put(AUTH_PASSWORD_KEY, secretKey);
    parms.put(PATH_STYLE_ACCESS_KEY, pathStyleAccess);
    parms.put(PROXY_HOST_KEY, proxyHost);
    parms.put(PROXY_PORT_KEY, proxyPort);

    logger.debug("using storage config: {}", parms);

    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setConnectionTimeout(timeout);
    clientConf.setSocketTimeout(timeout);
    clientConf.withUseExpectContinue(false);
    clientConf.withSignerOverride("S3SignerType");
    //        clientConf.setProtocol(Protocol.HTTP);
    if ((!proxyHost.equals("")) && (!proxyPort.equals(""))) {
      clientConf.setProxyHost(proxyHost);
      clientConf.setProxyPort(Integer.parseInt(proxyPort));
    }

    AWSCredentials myCredentials = new BasicAWSCredentials(accessKey, secretKey);
    client = new AmazonS3Client(myCredentials, clientConf);
    client.setEndpoint(endpoint);
    client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(pathStyleAccess));

    logger.debug("S3 client has been initialized");
  }
Example #8
0
 @Override
 public void dispose() {
   super.dispose();
   client = null;
 }