Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.internal.config;
 
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
 
Internal configuration for the AWS Java SDK.
 
 public class InternalConfig {
 
     private static final InternalLogApi log = InternalLogFactory.getLog(InternalConfig.class);
 
     static final String DEFAULT_CONFIG_RESOURCE = "awssdk_config_default.json";
     static final String CONFIG_OVERRIDE_RESOURCE = "awssdk_config_override.json";
     private static final String SERVICE_REGION_DELIMITOR = "/";
 
     private final SignerConfig defaultSignerConfig;
     private final Map<StringSignerConfigserviceRegionSigners;
     private final Map<StringSignerConfigregionSigners;
     private final Map<StringSignerConfigserviceSigners;
     private final Map<StringHttpClientConfighttpClients;
 
 
     private final String userAgentTemplate;

    

Parameters:
defaults default configuration
override override configuration
 
         SignerConfigJsonHelper scb = defaults.getDefaultSigner();
         this. = scb == null ? null : scb.build();
 
          = mergeSignerMap(defaults.getRegionSigners(),
             override.getRegionSigners(), "region");
          = mergeSignerMap(defaults.getServiceSigners(),
             override.getServiceSigners(), "service");
             override.getServiceRegionSigners(),
             "service" +  + "region");
          = merge(defaults.getHttpClients(), override.getHttpClients());
 
          = append(
                 override.getHostRegexToRegionMappings(),
                 defaults.getHostRegexToRegionMappings());
 
         if (override.getUserAgentTemplate() != null) {
              = override.getUserAgentTemplate();
         } else {
              = defaults.getUserAgentTemplate();
         }
     }

    
Returns an immutable map by merging the override signer configuration into the default signer configuration for the given theme.

Parameters:
defaults default signer configuration
override signer configurations overrides
theme used for message logging. eg region, service, region+service
 
     private Map<StringSignerConfigmergeSignerMap(JsonIndex<SignerConfigJsonHelperSignerConfig>[] defaults,
             JsonIndex<SignerConfigJsonHelperSignerConfig>[] overridesString theme) {
         Map<StringSignerConfigmap = buildSignerMap(defaultstheme);
         Map<StringSignerConfigmapOverride = buildSignerMap(overridestheme);
         map.putAll(mapOverride);
         return Collections.unmodifiableMap(map);
    }
    private <C extends Builder<T>, T> Map<String, T> merge(JsonIndex<C, T>[] defaults,
            JsonIndex<C, T>[] overrides) {
        Map<String, T> map = buildMap(defaults);
        Map<String, T> mapOverride = buildMap(overrides);
        map.putAll(mapOverride);
        return Collections.unmodifiableMap(map);
    }
    private <C extends Builder<T>, T> Map<String, T> buildMap(JsonIndex<C, T>[] signerIndexes) {
        Map<String, T> map = new HashMap<String, T>();
        if (signerIndexes != null) {
            for (JsonIndex<C, T> indexsignerIndexes) {
                String region = index.getKey();
                T prev = map.put(regionindex.newReadOnlyConfig());
                if (prev != null) {
                    .warn("Duplicate definition of signer for "
                            + index.getKey());
                }
            }
        }
        return map;
    }
    private <C extends Builder<T>, T> List<T> append(
            C[] defaults, C[] overrides) {
        List<T> list = new LinkedList<T>();
        if (defaults != null) {
            for (C builder : defaults) {
                list.add(builder.build());
            }
        }
        if (overrides != null) {
            for (C builder : overrides) {
                list.add(builder.build());
            }
        }
        return list;
    }

    
Builds and returns a signer configuration map.

Parameters:
signerIndexes signer configuration entries loaded from JSON
theme used for message logging. eg region, service, region+service
            JsonIndex<SignerConfigJsonHelperSignerConfig>[] signerIndexesString theme) {
        Map<StringSignerConfigmap = new HashMap<StringSignerConfig>();
        if (signerIndexes != null) {
            for (JsonIndex<SignerConfigJsonHelperSignerConfigindexsignerIndexes) {
                String region = index.getKey();
                SignerConfig prev = map.put(regionindex.newReadOnlyConfig());
                if (prev != null) {
                    .warn("Duplicate definition of signer for " + theme + " "
                            + index.getKey());
                }
            }
        }
        return map;
    }

    
Returns the signer configuration for the specified service, not specific to any region.
    public SignerConfig getSignerConfig(String serviceName) {
        return getSignerConfig(serviceNamenull);
    }

    
Returns the http client configuration for the http client name.
    public HttpClientConfig getHttpClientConfig(String httpClientName) {
        return .get(httpClientName);
    }

    
Returns the signer configuration for the specified service name and an optional region name.

Parameters:
serviceName must not be null
regionName similar to the region name in Regions; can be null.
Returns:
the signer
    public SignerConfig getSignerConfig(String serviceNameString regionName) {
        if (serviceName == null)
            throw new IllegalArgumentException();
        SignerConfig signerConfig = null;
        if (regionName != null) {
            // Service+Region signer config has the highest precedence
            String key = serviceName +  +regionName;
            signerConfig = .get(key);
            if (signerConfig != null) {
                return signerConfig;
            }
            // Region signer config has the 2nd highest precedence
            signerConfig = .get(regionName);
            if (signerConfig != null) {
                return signerConfig;
            }
        }
        // Service signer config has the 3rd highest precedence
        signerConfig = .get(serviceName);
        // Fall back to the default
        return signerConfig == null ?  : signerConfig;
    }

    

Returns:
all the host-name-regex to region-name mappings.
        return Collections.unmodifiableList();
    }


    

Returns:
the custom user agent template, if configured
    public String getUserAgentTemplate() {
        return ;
    }
            throws JsonParseExceptionJsonMappingExceptionIOException {
        if (url == null)
            throw new IllegalArgumentException();
        InternalConfigJsonHelper target = Jackson.getObjectMapper().readValue(
                urlInternalConfigJsonHelper.class);
        return target;
    }

    
Loads and returns the AWS Java SDK internal configuration from the classpath.
    static InternalConfig load() throws JsonParseException,
        URL url = ClassLoaderHelper.getResource("/" + ,
                InternalConfig.class);
        if (url == null) { // Try without a leading "/"
            url = ClassLoaderHelper.getResource(,
                    InternalConfig.class);
        }
        InternalConfigJsonHelper config = loadfrom(url);
        InternalConfigJsonHelper configOverride;
        URL overrideUrl = ClassLoaderHelper.getResource(
                "/" + InternalConfig.class);
        if (overrideUrl == null) { // Try without a leading "/"
            overrideUrl = ClassLoaderHelper.getResource(
                    InternalConfig.class);
        }
        if (overrideUrl == null) {
            .debug("Configuration override " + 
                    + " not found.");
            configOverride = new InternalConfigJsonHelper();
        } else {
            configOverride = loadfrom(overrideUrl);
        }
        return new InternalConfig(configconfigOverride);
    }
    // For debugging purposes
    void dump() {
        StringBuilder sb = new StringBuilder().append("defaultSignerConfig: ")
                .append().append("\n")
                .append("serviceRegionSigners: ").append()
                .append("\n").append("regionSigners: ").append()
                .append("\n").append("serviceSigners: ").append()
                .append("\n").append("userAgentTemplate: ")
                    .append();
        .debug(sb.toString());
    }
    public static class Factory {
        private static final InternalConfig SINGELTON;
        static {
            InternalConfig config = null;
            try {
                config = InternalConfig.load();
            } catch(RuntimeException ex) {
                throw ex;
            } catch(Exception ex) {
                throw new IllegalStateException(
                        "Fatal: Failed to load the internal config for AWS Java SDK",
                        ex);
            }
             = config;
        }
        
Returns a non-null and immutable instance of the AWS SDK internal configuration.
        public static InternalConfig getInternalConfig() { return ; }
    }
New to GrepCode? Check out our FAQ X