Package org.jets3t.service

Examples of org.jets3t.service.Jets3tProperties


     * upload or download operation when all the necessary parameters are provided.
     * @throws Exception
     */
    public static void main(String args[]) throws Exception {
        String propertiesFileName = "synchronize.properties";
        Jets3tProperties properties = null;

        // Required arguments
        String actionCommand = null;
        String s3Path = null;
        int reqArgCount = 0;
        List fileList = new ArrayList();
       
        // Options
        boolean doAction = true;
        boolean isQuiet = false;
        boolean isNoProgress = false;
        boolean isForce = false;
        boolean isKeepFiles = false;
        boolean isNoDelete = false;
        boolean isGzipEnabled = false;
        boolean isEncryptionEnabled = false;
        String aclString = null;
               
        // Parse arguments.
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                // Argument is an option.
                if (arg.equalsIgnoreCase("-h") || arg.equalsIgnoreCase("--help")) {
                    printHelpAndExit(true);
                } else if (arg.equalsIgnoreCase("-n") || arg.equalsIgnoreCase("--noaction")) {
                    doAction = false;
                } else if (arg.equalsIgnoreCase("-q") || arg.equalsIgnoreCase("--quiet")) {
                    isQuiet = true;
                } else if (arg.equalsIgnoreCase("-p") || arg.equalsIgnoreCase("--noprogress")) {
                    isNoProgress = true;
                } else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("--force")) {
                    isForce = true;
                } else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("--keepfiles")) {
                    isKeepFiles = true;
                } else if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("--nodelete")) {
                    isNoDelete = true;
                } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("--gzip")) {
                    isGzipEnabled = true;
                } else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("--crypto")) {
                    isEncryptionEnabled = true;
                } else if (arg.equalsIgnoreCase("--properties")) {
                    if (i + 1 < args.length) {
                        // Read the Synchronize properties file from the specified file           
                        i++;
                        propertiesFileName = args[i];
                        File propertiesFile = new File(propertiesFileName);
                        if (!propertiesFile.canRead()) {
                            System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found");
                            System.exit(2);                       
                        }
                        properties = Jets3tProperties.getInstance(
                            new FileInputStream(propertiesFileName), propertiesFile.getName());                       
                    } else {
                        System.err.println("ERROR: --properties option must be followed by a file path");
                        printHelpAndExit(false);                       
                    }
                } else if (arg.equalsIgnoreCase("--acl")) {
                    if (i + 1 < args.length) {
                        // Read the acl setting string            
                        i++;
                        aclString = args[i];
                       
                        if (!"PUBLIC_READ".equalsIgnoreCase(aclString)
                            && !"PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)
                            && !"PRIVATE".equalsIgnoreCase(aclString))
                        {
                            System.err.println("ERROR: Acess Control List setting \"acl\" must have one of the values "
                                + "PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE");
                            printHelpAndExit(false);                       
                        }                       
                    } else {
                        System.err.println("ERROR: --acl option must be followed by an ACL string");
                        printHelpAndExit(false);                       
                    }
                } else {
                    System.err.println("ERROR: Invalid option: " + arg);
                    printHelpAndExit(false);
                }
            } else {
                // Argument is one of the required parameters.
                if (reqArgCount == 0) {
                    actionCommand = arg.toUpperCase(Locale.getDefault());
                    if (!"UP".equals(actionCommand) && !"DOWN".equals(actionCommand)) {
                        System.err.println("ERROR: Invalid action command " + actionCommand
                            + ". Valid values are 'UP' or 'DOWN'");
                        printHelpAndExit(false);
                    }                   
                } else if (reqArgCount == 1) {
                    s3Path = arg;
                } else if (reqArgCount > 1) {
                    File file = new File(arg);
                   
                    if ("DOWN".equals(actionCommand)) {
                        if (reqArgCount > 2) {
                            System.err.println("ERROR: Only one target directory may be specified"
                                + " for " + actionCommand);
                            printHelpAndExit(false);
                        }
                        if (!file.canRead() || !file.isDirectory()) {
                            if (!file.mkdirs()) {
                                System.err.println("ERROR: Cannot create target download directory : "
                                    + file);                               
                            }
                        }        
                    } else {
                        if (!file.canRead()) {
                            if (properties != null && properties.getBoolProperty("upload.ignoreMissingPaths", false)) {
                                System.err.println("WARN: Ignoring missing upload path: " + file);
                                continue;
                            } else {
                                System.err.println("ERROR: Cannot read upload file/directory: "
                                    + file
                                    + "\n       To ignore missing paths set the property upload.ignoreMissingPaths");
                                printHelpAndExit(false);                           
                            }
                        }
                    }
                    fileList.add(file);
                }
                reqArgCount++;
            }
        }
       
        if (fileList.size() < 1) {
            // Missing one or more required parameters.
            System.err.println("ERROR: Missing required file path(s)");
            printHelpAndExit(false);
        }
       
        if (isKeepFiles && isNoDelete) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --nodelete cannot be used at the same time");
            printHelpAndExit(false);           
        }
       
        if (properties == null) {       
            // Read the Synchronize properties file from the classpath           
            properties = Jets3tProperties.getInstance(propertiesFileName);
            if (!properties.isLoaded()) {
                System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found in the classpath");
                System.exit(2);                       
            }
        }
               
        // Ensure the Synchronize properties file contains everything we need.
        if (!properties.containsKey("accesskey")) {
            System.err.println("ERROR: The properties file " + propertiesFileName + " must contain the property: accesskey");
            System.exit(2);           
        } else if (!properties.containsKey("secretkey")) {
            System.err.println("ERROR: The properties file " + propertiesFileName + " must contain the property: secretkey");
            System.exit(2);                       
        } else if (isEncryptionEnabled && !properties.containsKey("password")) {
            System.err.println("ERROR: You are using encryption, so the properties file " + propertiesFileName + " must contain the property: password");
            System.exit(2);                       
        }
       
        // Load the AWS credentials from encrypted file.
        AWSCredentials awsCredentials = new AWSCredentials(
            properties.getStringProperty("accesskey", null),
            properties.getStringProperty("secretkey", null));      
       
        if (aclString == null) {
            aclString = properties.getStringProperty("acl", "PRIVATE");
        }
        if (!"PUBLIC_READ".equalsIgnoreCase(aclString)
            && !"PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)
            && !"PRIVATE".equalsIgnoreCase(aclString))
        {
            System.err.println("ERROR: Acess Control List setting \"acl\" must have one of the values "
                + "PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE");
            System.exit(2);                                   
        }
        
        // Perform the UPload/DOWNload.
        Synchronize client = new Synchronize(
            new RestS3Service(awsCredentials, APPLICATION_DESCRIPTION, null),
            doAction, isQuiet, isNoProgress, isForce, isKeepFiles, isNoDelete, isGzipEnabled, isEncryptionEnabled);
        client.run(s3Path, fileList, actionCommand,
            properties.getStringProperty("password", null), aclString);
    }
View Full Code Here


    public RestS3Service(AWSCredentials awsCredentials, String invokingApplicationDescription,
        CredentialsProvider credentialsProvider) throws S3ServiceException
    {
        super(awsCredentials, invokingApplicationDescription);
       
        Jets3tProperties jets3tProperties = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);
       
        // Set HttpClient properties based on Jets3t Properties.
        HostConfiguration hostConfig = new HostConfiguration();
                       
        HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
        connectionParams.setConnectionTimeout(jets3tProperties.
            getIntProperty("httpclient.connection-timeout-ms", 60000));
        connectionParams.setSoTimeout(jets3tProperties.
            getIntProperty("httpclient.socket-timeout-ms", 60000));       
        connectionParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
            jets3tProperties.getIntProperty("httpclient.max-connections", 4));
        connectionParams.setStaleCheckingEnabled(jets3tProperties.
            getBoolProperty("httpclient.stale-checking-enabled", true));
       
        // Connection properties to take advantage of S3 window scaling.
        if (jets3tProperties.containsKey("httpclient.socket-receive-buffer")) {
            connectionParams.setReceiveBufferSize(jets3tProperties.
                getIntProperty("httpclient.socket-receive-buffer", 0));
        }
        if (jets3tProperties.containsKey("httpclient.socket-send-buffer")) {
            connectionParams.setSendBufferSize(jets3tProperties.
                getIntProperty("httpclient.socket-send-buffer", 0));
        }
       
        connectionParams.setTcpNoDelay(true);
       
        connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.setParams(connectionParams);
       
        // Set user agent string.
        HttpClientParams clientParams = new HttpClientParams();
        String userAgent = jets3tProperties.getStringProperty("httpclient.useragent", null);
        if (userAgent == null) {
            userAgent = ServiceUtils.getUserAgentDescription(
                getInvokingApplicationDescription());
        }
        log.debug("Setting user agent string: " + userAgent);
        clientParams.setParameter(HttpMethodParams.USER_AGENT, userAgent);

        clientParams.setBooleanParameter("http.protocol.expect-continue", true);

        // Replace default error retry handler.
        final int retryMaxCount = jets3tProperties.getIntProperty("httpclient.retry-max", 5);
       
        clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
            public boolean retryMethod(HttpMethod httpMethod, IOException ioe, int executionCount) {
                if (executionCount > retryMaxCount) {
                    log.warn("Retried connection " + executionCount
                        + " times, which exceeds the maximum retry count of " + retryMaxCount);
                    return false;                   
                }
                if  (ioe instanceof UnrecoverableIOException) {
                    log.debug("Deliberate interruption, will not retry");
                    return false;
                }
                log.warn("Retrying " + httpMethod.getName() + " request with path '"
                    + httpMethod.getPath() + "' - attempt " + executionCount
                    + " of " + retryMaxCount);
               
                // Build the authorization string for the method.
                try {
                    buildAuthorizationString(httpMethod);
                } catch (S3ServiceException e) {
                    log.warn("Unable to generate updated authorization string for retried request", e);
                }
               
                return true;
            }
        });
       
        httpClient = new HttpClient(clientParams, connectionManager);
        httpClient.setHostConfiguration(hostConfig);

        // Retrieve Proxy settings.
        boolean proxyAutodetect = jets3tProperties.getBoolProperty("httpclient.proxy-autodetect", true);       
        String proxyHostAddress = jets3tProperties.getStringProperty("httpclient.proxy-host", null);
        int proxyPort = jets3tProperties.getIntProperty("httpclient.proxy-port", -1);
       
        // Use explicit proxy settings, if available.
        if (proxyHostAddress != null && proxyPort != -1) {
            log.info("Using Proxy: " + proxyHostAddress + ":" + proxyPort);
            hostConfig.setProxy(proxyHostAddress, proxyPort);
View Full Code Here

     * upload or download operation when all the necessary parameters are provided.
     * @throws Exception
     */
    public static void main(String args[]) throws Exception {
        // Load default JetS3t properties
        Jets3tProperties myProperties =
            Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);       
        String propertiesFileName = "synchronize.properties";
        boolean synchronizePropertiesLoaded = false;

        // Required arguments
        String actionCommand = null;
        String s3Path = null;
        int reqArgCount = 0;
        List fileList = new ArrayList();
       
        // Options
        boolean doAction = true;
        boolean isQuiet = false;
        boolean isNoProgress = false;
        boolean isForce = false;
        boolean isKeepFiles = false;
        boolean isNoDelete = false;
        boolean isGzipEnabled = false;
        boolean isEncryptionEnabled = false;
        boolean isMoveEnabled = false;
        boolean isBatchMode = false;
        boolean isSkipMetadata = false;
        String aclString = null;
        int reportLevel = REPORT_LEVEL_ALL;
               
        // Parse arguments.
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                // Argument is an option.
                if (arg.equalsIgnoreCase("-h") || arg.equalsIgnoreCase("--help")) {
                    printHelpAndExit(true);
                } else if (arg.equalsIgnoreCase("-n") || arg.equalsIgnoreCase("--noaction")) {
                    doAction = false;
                } else if (arg.equalsIgnoreCase("-q") || arg.equalsIgnoreCase("--quiet")) {
                    isQuiet = true;
                } else if (arg.equalsIgnoreCase("-p") || arg.equalsIgnoreCase("--noprogress")) {
                    isNoProgress = true;
                } else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("--force")) {
                    isForce = true;
                } else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("--keepfiles")) {
                    isKeepFiles = true;
                } else if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("--nodelete")) {
                    isNoDelete = true;
                } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("--gzip")) {
                    isGzipEnabled = true;
                } else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("--crypto")) {
                    isEncryptionEnabled = true;
                } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("--move")) {
                    isMoveEnabled = true;
                } else if (arg.equalsIgnoreCase("-s") || arg.equalsIgnoreCase("--skipmetadata")) {
                    isSkipMetadata = true;
                } else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("--batch")) {
                    isBatchMode = true;
                } else if (arg.equalsIgnoreCase("--properties")) {
                    if (i + 1 < args.length) {
                        // Read the Synchronize properties file from the specified file           
                        i++;
                        propertiesFileName = args[i];
                        File propertiesFile = new File(propertiesFileName);
                        if (!propertiesFile.canRead()) {
                            System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found");
                            System.exit(2);                       
                        }
                        myProperties.loadAndReplaceProperties(
                            new FileInputStream(propertiesFileName), propertiesFile.getName());
                        synchronizePropertiesLoaded = true;
                    } else {
                        System.err.println("ERROR: --properties option must be followed by a file path");
                        printHelpAndExit(false);                       
                    }
                } else if (arg.equalsIgnoreCase("--acl")) {
                    if (i + 1 < args.length) {
                        // Read the acl setting string            
                        i++;
                        aclString = args[i];
                       
                        if (!"PUBLIC_READ".equalsIgnoreCase(aclString)
                            && !"PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)
                            && !"PRIVATE".equalsIgnoreCase(aclString))
                        {
                            System.err.println("ERROR: Acess Control List setting \"acl\" must have one of the values "
                                + "PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE");
                            printHelpAndExit(false);                       
                        }                       
                    } else {
                        System.err.println("ERROR: --acl option must be followed by an ACL string");
                        printHelpAndExit(false);                       
                    }
                } else if (arg.equalsIgnoreCase("--reportlevel")) {
                    if (i + 1 < args.length) {
                        // Read the report level integer
                        i++;
                        try {
                            reportLevel = Integer.parseInt(args[i]);
                           
                            if (reportLevel < 0 || reportLevel > 3) {
                                System.err.println("ERROR: Report Level setting \"reportlevel\" must have one of the values "
                                    + "0 (no reporting), 1 (actions only), 2 (differences only), 3 (DEFAULT - all reporting)");
                                printHelpAndExit(false);                       
                            }                                                       
                        } catch (NumberFormatException e) {
                            System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                            printHelpAndExit(false);                                                       
                        }
                    } else {
                        System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                        printHelpAndExit(false);
                    }
                } else {
                    System.err.println("ERROR: Invalid option: " + arg);
                    printHelpAndExit(false);
                }
            } else {
                // Argument is one of the required parameters.
                if (reqArgCount == 0) {
                    actionCommand = arg.toUpperCase(Locale.getDefault());
                    if (!"UP".equals(actionCommand) && !"DOWN".equals(actionCommand)) {
                        System.err.println("ERROR: Invalid action command " + actionCommand
                            + ". Valid values are 'UP' or 'DOWN'");
                        printHelpAndExit(false);
                    }                   
                } else if (reqArgCount == 1) {
                    s3Path = arg;
                } else if (reqArgCount > 1) {
                    File file = new File(arg);
                   
                    if ("DOWN".equals(actionCommand)) {
                        if (reqArgCount > 2) {
                            System.err.println("ERROR: Only one target directory may be specified"
                                + " for " + actionCommand);
                            printHelpAndExit(false);
                        }
                        if (file.exists() && !file.isDirectory()) {
                            System.err.println("ERROR: Target download location already exists but is not a directory: "
                                + file);                               
                        }        
                    } else {
                        if (!file.canRead()) {
                            if (myProperties != null && myProperties.getBoolProperty("upload.ignoreMissingPaths", false)) {
                                System.err.println("WARN: Ignoring missing upload path: " + file);
                                continue;
                            } else {
                                System.err.println("ERROR: Cannot read upload file/directory: "
                                    + file
                                    + "\n       To ignore missing paths set the property upload.ignoreMissingPaths");
                                printHelpAndExit(false);                           
                            }
                        }
                    }
                    fileList.add(file);
                }
                reqArgCount++;
            }
        }
       
        if (fileList.size() < 1) {
            // Missing one or more required parameters.
            System.err.println("ERROR: Missing required file path(s)");
            printHelpAndExit(false);
        }
       
        if (isKeepFiles && isNoDelete) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --nodelete cannot be used at the same time");
            printHelpAndExit(false);           
        }
       
        if (isKeepFiles && isMoveEnabled) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --move cannot be used at the same time");
            printHelpAndExit(false);           
        }
       
        if (isSkipMetadata && (isGzipEnabled || isEncryptionEnabled)) {
            // Incompatible options.
            System.err.println("ERROR: The --skipmetadata option cannot be used with the --gzip or --crypto options");
            printHelpAndExit(false);                       
        }
       
        if (!synchronizePropertiesLoaded) {       
            // Read the Synchronize properties file from the classpath
            Jets3tProperties synchronizeProperties =
                Jets3tProperties.getInstance(propertiesFileName);
            if (!synchronizeProperties.isLoaded()) {
                System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found in the classpath");
                System.exit(2);                       
            } else {
                myProperties.loadAndReplaceProperties(synchronizeProperties,
                    propertiesFileName + " in classpath");               
View Full Code Here

     * upload or download operation when all the necessary parameters are provided.
     * @throws Exception
     */
    public static void main(String args[]) throws Exception {
        // Load default JetS3t properties
        Jets3tProperties myProperties =
            Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);       
        String propertiesFileName = "synchronize.properties";
        boolean synchronizePropertiesLoaded = false;

        // Required arguments
        String actionCommand = null;
        String s3Path = null;
        int reqArgCount = 0;
        List fileList = new ArrayList();
       
        // Options
        boolean doAction = true;
        boolean isQuiet = false;
        boolean isNoProgress = false;
        boolean isForce = false;
        boolean isKeepFiles = false;
        boolean isNoDelete = false;
        boolean isGzipEnabled = false;
        boolean isEncryptionEnabled = false;
        boolean isMoveEnabled = false;
        boolean isBatchMode = false;
        boolean isSkipMetadata = false;
        String aclString = null;
        int reportLevel = REPORT_LEVEL_ALL;
        AWSCredentials awsCredentials = null;
               
        // Parse arguments.
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                // Argument is an option.
                if (arg.equalsIgnoreCase("-h") || arg.equalsIgnoreCase("--help")) {
                    printHelpAndExit(true);
                } else if (arg.equalsIgnoreCase("-n") || arg.equalsIgnoreCase("--noaction")) {
                    doAction = false;
                } else if (arg.equalsIgnoreCase("-q") || arg.equalsIgnoreCase("--quiet")) {
                    isQuiet = true;
                } else if (arg.equalsIgnoreCase("-p") || arg.equalsIgnoreCase("--noprogress")) {
                    isNoProgress = true;
                } else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("--force")) {
                    isForce = true;
                } else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("--keepfiles")) {
                    isKeepFiles = true;
                } else if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("--nodelete")) {
                    isNoDelete = true;
                } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("--gzip")) {
                    isGzipEnabled = true;
                } else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("--crypto")) {
                    isEncryptionEnabled = true;
                } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("--move")) {
                    isMoveEnabled = true;
                } else if (arg.equalsIgnoreCase("-s") || arg.equalsIgnoreCase("--skipmetadata")) {
                    isSkipMetadata = true;
                } else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("--batch")) {
                    isBatchMode = true;
                } else if (arg.equalsIgnoreCase("--properties")) {
                    if (i + 1 < args.length) {
                        // Read the Synchronize properties file from the specified file           
                        i++;
                        propertiesFileName = args[i];
                        File propertiesFile = new File(propertiesFileName);
                        if (!propertiesFile.canRead()) {
                            System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found");
                            System.exit(2);                       
                        }
                        myProperties.loadAndReplaceProperties(
                            new FileInputStream(propertiesFileName), propertiesFile.getName());
                        synchronizePropertiesLoaded = true;
                    } else {
                        System.err.println("ERROR: --properties option must be followed by a file path");
                        printHelpAndExit(false);                       
                    }
                } else if (arg.equalsIgnoreCase("--acl")) {
                    if (i + 1 < args.length) {
                        // Read the acl setting string            
                        i++;
                        aclString = args[i];
                       
                        if (!"PUBLIC_READ".equalsIgnoreCase(aclString)
                            && !"PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)
                            && !"PRIVATE".equalsIgnoreCase(aclString))
                        {
                            System.err.println("ERROR: Acess Control List setting \"acl\" must have one of the values "
                                + "PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE");
                            printHelpAndExit(false);                       
                        }                       
                    } else {
                        System.err.println("ERROR: --acl option must be followed by an ACL string");
                        printHelpAndExit(false);                       
                    }
                } else if (arg.equalsIgnoreCase("--reportlevel")) {
                    if (i + 1 < args.length) {
                        // Read the report level integer
                        i++;
                        try {
                            reportLevel = Integer.parseInt(args[i]);
                           
                            if (reportLevel < 0 || reportLevel > 3) {
                                System.err.println("ERROR: Report Level setting \"reportlevel\" must have one of the values "
                                    + "0 (no reporting), 1 (actions only), 2 (differences only), 3 (DEFAULT - all reporting)");
                                printHelpAndExit(false);                       
                            }                                                       
                        } catch (NumberFormatException e) {
                            System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                            printHelpAndExit(false);                                                       
                        }
                    } else {
                        System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                        printHelpAndExit(false);
                    }
                } else if (arg.equalsIgnoreCase("--credentials")) {
                    if (i + 1 < args.length) {
                        // Read the credentials file location
                        i++;
                        File credentialsFile = new File(args[i]);
                        if (!credentialsFile.canRead()) {
                            System.err.println("ERROR: Cannot read credentials file '" + credentialsFile + "'");
                            printHelpAndExit(false);                           
                        }                       
                        BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
                        while (awsCredentials == null) {
                            System.out.print("Password for credentials file '" + credentialsFile + "': ");
                            String credentialsPassword = inputReader.readLine();
                            try {
                                awsCredentials = AWSCredentials.load(credentialsPassword, credentialsFile);
                                // Set dummy accesskey and secretkey property values, to avoid prompting for these values later on.
                                myProperties.setProperty("accesskey", "");
                                myProperties.setProperty("secretkey", "");
                            } catch (S3ServiceException e) {
                                System.out.println("Failed to read AWS credentials from the file '" + credentialsFile + "'");
                            }
                        }
                    } else {
                        System.err.println("ERROR: --credentials option must be followed by a file path");
                        printHelpAndExit(false);
                    }
                } else {
                    System.err.println("ERROR: Invalid option: " + arg);
                    printHelpAndExit(false);
                }
            } else {
                // Argument is one of the required parameters.
                if (reqArgCount == 0) {
                    actionCommand = arg.toUpperCase(Locale.getDefault());
                    if (!"UP".equals(actionCommand) && !"DOWN".equals(actionCommand)) {
                        System.err.println("ERROR: Invalid action command " + actionCommand
                            + ". Valid values are 'UP' or 'DOWN'");
                        printHelpAndExit(false);
                    }                   
                } else if (reqArgCount == 1) {
                    s3Path = arg;
                } else if (reqArgCount > 1) {
                    File file = new File(arg);
                   
                    if ("DOWN".equals(actionCommand)) {
                        if (reqArgCount > 2) {
                            System.err.println("ERROR: Only one target directory may be specified"
                                + " for " + actionCommand);
                            printHelpAndExit(false);
                        }
                        if (file.exists() && !file.isDirectory()) {
                            System.err.println("ERROR: Target download location already exists but is not a directory: "
                                + file);                               
                        }        
                    } else {
                        if (!file.canRead()) {
                            if (myProperties != null && myProperties.getBoolProperty("upload.ignoreMissingPaths", false)) {
                                System.err.println("WARN: Ignoring missing upload path: " + file);
                                continue;
                            } else {
                                System.err.println("ERROR: Cannot read upload file/directory: "
                                    + file
                                    + "\n       To ignore missing paths set the property upload.ignoreMissingPaths");
                                printHelpAndExit(false);                           
                            }
                        }
                    }
                    fileList.add(file);
                }
                reqArgCount++;
            }
        }
       
        if (fileList.size() < 1) {
            // Missing one or more required parameters.
            System.err.println("ERROR: Missing required file path(s)");
            printHelpAndExit(false);
        }
       
        if (isKeepFiles && isNoDelete) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --nodelete cannot be used at the same time");
            printHelpAndExit(false);           
        }
       
        if (isKeepFiles && isMoveEnabled) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --move cannot be used at the same time");
            printHelpAndExit(false);           
        }
       
        if (isSkipMetadata && (isGzipEnabled || isEncryptionEnabled)) {
            // Incompatible options.
            System.err.println("ERROR: The --skipmetadata option cannot be used with the --gzip or --crypto options");
            printHelpAndExit(false);                       
        }
       
        if (!synchronizePropertiesLoaded) {       
            // Read the Synchronize properties file from the classpath
            Jets3tProperties synchronizeProperties =
                Jets3tProperties.getInstance(propertiesFileName);
            if (synchronizeProperties.isLoaded()) {
                myProperties.loadAndReplaceProperties(synchronizeProperties,
                    propertiesFileName + " in classpath");               
            }
        }
               
View Full Code Here

    @Override
    protected void connectToRepository(Repository source, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider)
            throws AuthenticationException {
        try {
            Jets3tProperties jets3tProperties = new Jets3tProperties();
            if (proxyInfoProvider != null) {
                ProxyInfo proxyInfo = proxyInfoProvider.getProxyInfo("http");
                if (proxyInfo != null) {
                    jets3tProperties.setProperty("httpclient.proxy-autodetect", "false");
                    jets3tProperties.setProperty("httpclient.proxy-host", proxyInfo.getHost());
                    jets3tProperties.setProperty("httpclient.proxy-port", new Integer(proxyInfo.getPort()).toString());
                }
            }
            this.service = new RestS3Service(getCredentials(authenticationInfo), "mavens3wagon", null, jets3tProperties);
        } catch (S3ServiceException e) {
            throw new AuthenticationException("Cannot authenticate with current credentials", e);
View Full Code Here

    if (fs instanceof NativeS3FileSystem) {
      if (conf.getBoolean(ARCFileInputFormat.USE_S3_INPUTSTREAM, false)) {
        in = new S3InputStream(path.toUri(), conf.get("fs.s3n.awsAccessKeyId"), conf.get("fs.s3n.awsSecretAccessKey"), 1048576);
      }
      else {
        Jets3tProperties properties = Jets3tProperties.getInstance(org.jets3t.service.Constants.JETS3T_PROPERTIES_FILENAME);
        properties.setProperty("s3service.https-only","false");
      }
    }
    if (in == null) {
      in = fs.open(path);
    }
View Full Code Here

    if (fs instanceof NativeS3FileSystem) {
      if (conf.getBoolean(ARCFileInputFormat.USE_S3_INPUTSTREAM, false)) {
        in = new S3InputStream(path.toUri(), conf.get("fs.s3n.awsAccessKeyId"), conf.get("fs.s3n.awsSecretAccessKey"), 1048576);
      }
      else {
        Jets3tProperties properties = Jets3tProperties.getInstance(org.jets3t.service.Constants.JETS3T_PROPERTIES_FILENAME);
        properties.setProperty("s3service.https-only","false");
      }
    }
    if (in == null) {
      in = fs.open(path);
    }
View Full Code Here

            port = new Integer(portS).intValue();
            httpsPort = new Integer(httpsPortS).intValue();
            host = host.substring(0, ndx);
        }
       
        Jets3tProperties j3p = new Jets3tProperties();

        j3p.setProperty("s3service.s3-endpoint-http-port", portS);
        j3p.setProperty("s3service.s3-endpoint-https-port", httpsPortS);
        j3p.setProperty("s3service.disable-dns-buckets", "true");
        j3p.setProperty("s3service.s3-endpoint", host);  
        j3p.setProperty("s3service.https-only", this.useHttps);
        j3p.setProperty("storage-service.internal-error-retry-max", "0");
        j3p.setProperty("httpclient.socket-timeout-ms", "0");

        HostConfiguration hc = new HostConfiguration();
        if(allowSelfSigned && this.useHttps.equalsIgnoreCase("true"))
        {
            // magic needed for jets3t to work with self signed cert.
View Full Code Here

    {
        if (targetS3.isSelected()) {
            return new RestS3Service(credentials);
        } else {
            // Override endpoint property in JetS3t properties
            Jets3tProperties gsProperties = Jets3tProperties.getInstance(
                Constants.JETS3T_PROPERTIES_FILENAME);
            gsProperties.setProperty(
                "s3service.s3-endpoint", Constants.GS_DEFAULT_HOSTNAME);
            return new RestS3Service(credentials, null, null, gsProperties);
        }
    }
View Full Code Here

     * @param args
     * @throws Exception
     */
    public static void main(String args[]) throws Exception {
        // Load default JetS3t properties
        Jets3tProperties myProperties =
            Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);
        String propertiesFileName = "synchronize.properties";

        // Read the Synchronize properties file from the classpath
        Jets3tProperties synchronizeProperties =
            Jets3tProperties.getInstance(propertiesFileName);
        if (synchronizeProperties.isLoaded()) {
            myProperties.loadAndReplaceProperties(synchronizeProperties,
                propertiesFileName + " in classpath");
        }

        // Required arguments
View Full Code Here

TOP

Related Classes of org.jets3t.service.Jets3tProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.