All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.distelli.aws.ClientConfigurations Maven / Gradle / Ivy

There is a newer version: 3.8.16
Show newest version
package com.distelli.aws;

import javax.inject.Singleton;
import com.amazonaws.ClientConfiguration;
import java.net.URI;
import java.net.URLDecoder;
import java.io.UnsupportedEncodingException;

@Singleton
public class ClientConfigurations {
    public ClientConfiguration withProxy(ClientConfiguration config, URI proxy) {
        if ( null == proxy ) return config;

        if ( null != proxy.getHost() ) {
            config.withProxyHost(proxy.getHost());
        }

        if ( proxy.getPort() > 0 ) {
            config.withProxyPort(proxy.getPort());
        }
        String userInfo = proxy.getRawUserInfo();
        if ( null != userInfo ) {
            int colon = userInfo.indexOf(':');
            String user, passwd;
            try {
                if ( colon < 0 ) {
                    user = URLDecoder.decode(userInfo, "UTF-8");
                    passwd = null;
                } else {
                    user = URLDecoder.decode(userInfo.substring(0, colon), "UTF-8");
                    passwd = URLDecoder.decode(userInfo.substring(colon+1), "UTF-8");
                }
            } catch ( UnsupportedEncodingException ex ) {
                throw new IllegalStateException(ex); // should never happen...
            }
            if ( null != user ) {
                config.withProxyUsername(user);
            }
            if ( null != passwd ) {
                config.withProxyPassword(passwd);
            }
        }
        return config;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy