Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

In this page you can find the example usage for java.util HashMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:com.selene.volley.stack.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    //      if (!TextUtils.isEmpty(mUserAgent)) {
    //         map.put(HTTP.USER_AGENT, mUserAgent);
    //      }/*from  www . j  a  v a 2  s . co  m*/
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could
        // not be retrieved.
        // Signal to the caller that something was wrong with the
        // connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }

    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:org.yes.cart.orderexport.mail.EmailNotificationOrderExporterImpl.java

/**
 * Create email and sent it./*from ww w. ja v  a 2s. c  o  m*/
 *
 * @param order             given order
 * @param deliveries        deliveries to be exported
 * @param emailTemplateName optional email template name
 * @param emailsAddresses   set of email addresses
 * @param params            additional params
 */
protected void fillNotificationParameters(final CustomerOrder order,
        final List<CustomerOrderDelivery> deliveries, final String emailTemplateName,
        final Map<String, Object> params, final String... emailsAddresses) {

    if (StringUtils.isNotBlank(emailTemplateName)) {

        final CustomerOrder customerOrder = order;
        final Shop shop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster()
                : customerOrder.getShop();

        for (String emailAddr : emailsAddresses) {

            final HashMap<String, Object> map = new HashMap<String, Object>();

            if (params != null) {

                map.putAll(params);
            }

            map.put(StandardMessageListener.SHOP_CODE, shop.getCode());
            map.put(StandardMessageListener.CUSTOMER_EMAIL, emailAddr);
            map.put(StandardMessageListener.RESULT, true);
            map.put(StandardMessageListener.ROOT, customerOrder);
            map.put(StandardMessageListener.TEMPLATE_FOLDER,
                    themeService.getMailTemplateChainByShopId(shop.getShopId()));
            map.put(StandardMessageListener.SHOP, shop);
            map.put(StandardMessageListener.CUSTOMER, customerOrder.getCustomer());
            map.put(StandardMessageListener.SHIPPING_ADDRESS, customerOrder.getShippingAddressDetails());
            map.put(StandardMessageListener.BILLING_ADDRESS, customerOrder.getBillingAddressDetails());
            map.put(StandardMessageListener.TEMPLATE_NAME, emailTemplateName);
            map.put(StandardMessageListener.LOCALE, customerOrder.getLocale());

            final Map<String, String> carrier = new HashMap<String, String>();
            final Map<String, String> carrierSla = new HashMap<String, String>();
            for (final CustomerOrderDelivery delivery : deliveries) {

                final I18NModel carrierName = new FailoverStringI18NModel(
                        delivery.getCarrierSla().getCarrier().getDisplayName(),
                        delivery.getCarrierSla().getCarrier().getName());
                carrier.put(delivery.getDeliveryNum(), carrierName.getValue(customerOrder.getLocale()));
                final I18NModel carrierSlaName = new FailoverStringI18NModel(
                        delivery.getCarrierSla().getDisplayName(), delivery.getCarrierSla().getName());
                carrierSla.put(delivery.getDeliveryNum(), carrierSlaName.getValue(customerOrder.getLocale()));
            }
            map.put(StandardMessageListener.DELIVERY_CARRIER, carrier);
            map.put(StandardMessageListener.DELIVERY_CARRIER_SLA, carrierSla);
            map.put(StandardMessageListener.SUP_DELIVERIES, deliveries);

            sendNotification(map);

        }

    }

}

From source file:com.almende.eve.event.EventsFactory.java

/**
 * Store a list with subscriptions for an event.
 *
 * @param event the event/*from w  w w .j  av  a2s  . com*/
 * @param subscriptions the subscriptions
 */
private void putSubscriptions(final String event, final List<Callback> subscriptions) {

    final Map<String, List<Callback>> allSubscriptions = myAgent.getState().get(SUBSCRIPTIONS);

    final HashMap<String, List<Callback>> newSubscriptions = new HashMap<String, List<Callback>>();
    if (allSubscriptions != null) {
        newSubscriptions.putAll(allSubscriptions);
    }
    newSubscriptions.put(event, subscriptions);
    if (!myAgent.getState().putIfUnchanged(SUBSCRIPTIONS.getKey(), newSubscriptions, allSubscriptions)) {
        // Recursive retry.
        putSubscriptions(event, subscriptions);
        return;
    }
}

From source file:com.workplacesystems.queuj.Queue.java

/** Creates a new instance of QueueBuilder */
Queue(Queue parent_queue, QueueRestriction restriction, Index index, Class<B> process_builder_class,
        Class<? extends BatchProcessServer> process_server_class, Occurrence default_occurence,
        Visibility default_visibility, Access default_access, Resilience default_resilience,
        Output default_output, HashMap<String, Serializable> implementation_options) {
    this.parent_queue = parent_queue;
    this.restriction = restriction;
    this.index = index;
    this.process_builder_class = process_builder_class;
    this.process_server_class = process_server_class;
    this.default_occurence = default_occurence;
    this.default_visibility = default_visibility;
    this.default_access = default_access;
    this.default_resilience = default_resilience;
    this.default_output = default_output;
    HashMap<String, Serializable> implementation_options0 = new HashMap<String, Serializable>();
    if (parent_queue != null)
        implementation_options0.putAll(parent_queue.getImplementationOptions());
    implementation_options0.putAll(implementation_options);
    this.implementation_options = Collections.unmodifiableMap(implementation_options0);

    setId(this);//from   ww  w.j  av  a 2  s.c  o  m

    if (log.isDebugEnabled())
        log.debug("Creating Queue:" + new_line + toString());
}

From source file:com.daidiansha.acarry.control.network.core.volley.toolbox.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError, IOException {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);//from   w w  w.  ja v a2s . c  o  m
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);

    if (!TextUtils.isEmpty(mUserAgent)) {
        connection.setRequestProperty(HEADER_USER_AGENT, mUserAgent);
    }

    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    if (request instanceof MultiPartRequest) {
        setConnectionParametersForMultipartRequest(connection, (MultiPartRequest) request);
    } else {
        setConnectionParametersForRequest(connection, request);
    }

    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could
        // not be retrieved.
        // Signal to the caller that something was wrong with the
        // connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:com.volley.air.toolbox.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError, IOException {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);/* w  w w .j  a v a2  s. c  om*/
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);

    if (!TextUtils.isEmpty(mUserAgent)) {
        connection.setRequestProperty(HEADER_USER_AGENT, mUserAgent);
    }

    for (Entry<String, String> entry : map.entrySet()) {
        connection.addRequestProperty(entry.getKey(), entry.getValue());
    }
    if (request instanceof MultiPartRequest) {
        setConnectionParametersForMultipartRequest(connection, request);
    } else {
        setConnectionParametersForRequest(connection, request);
    }

    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could
        // not be retrieved.
        // Signal to the caller that something was wrong with the
        // connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:org.apache.struts2.convention.ConventionUnknownHandler.java

protected ActionConfig buildActionConfig(String path, ResultTypeConfig resultTypeConfig) {
    Map<String, ResultConfig> results = new HashMap<>();
    HashMap<String, String> params = new HashMap<>();
    if (resultTypeConfig.getParams() != null) {
        params.putAll(resultTypeConfig.getParams());
    }//from  w ww  .j a  v a  2s . com
    params.put(resultTypeConfig.getDefaultResultParam(), path);

    PackageConfig pkg = configuration.getPackageConfig(defaultParentPackageName);
    List<InterceptorMapping> interceptors = InterceptorBuilder.constructInterceptorReference(pkg,
            pkg.getFullDefaultInterceptorRef(), Collections.<String, String>emptyMap(), null, objectFactory);
    ResultConfig config = new ResultConfig.Builder(Action.SUCCESS, resultTypeConfig.getClassName())
            .addParams(params).build();
    results.put(Action.SUCCESS, config);

    return new ActionConfig.Builder(defaultParentPackageName, "execute", ActionSupport.class.getName())
            .addInterceptors(interceptors).addResultConfigs(results)
            .addAllowedMethod(pkg.getGlobalAllowedMethods()).build();
}

From source file:retrieval.server.globaldatabase.RedisDatabase.java

public void putToPurge(String storage, Map<Long, Integer> toPurge) {
    try (Jedis redis = databasePurge.getResource()) {
        HashMap<Long, Integer> map;

        byte[] data = redis.hget(SerializationUtils.serialize(KEY_PURGE_STORE),
                SerializationUtils.serialize(storage));
        if (data != null) {
            map = (HashMap<Long, Integer>) SerializationUtils.deserialize(data);
        } else {// ww  w .ja  v a 2s. c  om
            map = new HashMap<Long, Integer>();
        }
        map.putAll(toPurge);
        redis.hset(SerializationUtils.serialize(KEY_PURGE_STORE), SerializationUtils.serialize(storage),
                SerializationUtils.serialize(map));
    }
    ;
}

From source file:com.androidex.volley.toolbox.HurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError, IOException {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);/*from w w w .  j av a 2  s  . c  o m*/
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);

    if (!TextUtils.isEmpty(mUserAgent)) {
        connection.setRequestProperty(HEADER_USER_AGENT, mUserAgent);
    }

    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    if (request instanceof MultiPartRequest) {
        setConnectionParametersForMultipartRequest(connection, request);
    } else {
        setConnectionParametersForRequest(connection, request);
    }

    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could
        // not be retrieved.
        // Signal to the caller that something was wrong with the
        // connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:org.jfrog.teamcity.agent.BaseBuildInfoExtractor.java

private Map<String, String> getMatrixParams() {
    Map<String, String> matrixParams = Maps.newHashMap();

    Properties buildInfoProperties = BuildInfoExtractorUtils
            .mergePropertiesWithSystemAndPropertyFile(new Properties());
    Properties filteredMatrixParams = BuildInfoExtractorUtils.filterDynamicProperties(buildInfoProperties,
            BuildInfoExtractorUtils.MATRIX_PARAM_PREDICATE);

    Enumeration<Object> propertyKeys = filteredMatrixParams.keys();
    while (propertyKeys.hasMoreElements()) {
        String key = propertyKeys.nextElement().toString();
        matrixParams.put(key, filteredMatrixParams.getProperty(key));
    }//  w  ww .j av a2  s . c  o  m
    matrixParams.put("build.name", runnerParams.get(BUILD_NAME));
    matrixParams.put("build.number", runnerContext.getBuild().getBuildNumber());
    matrixParams.put("build.timestamp", runnerParams.get(PROP_BUILD_TIMESTAMP));

    if (StringUtils.isNotBlank(runnerParams.get(PROP_PARENT_NAME))) {
        matrixParams.put("build.parentName", runnerParams.get(PROP_PARENT_NAME));
    }

    if (StringUtils.isNotBlank(runnerParams.get(PROP_PARENT_NUMBER))) {
        matrixParams.put("build.parentNumber", runnerParams.get(PROP_PARENT_NUMBER));
    }

    if (StringUtils.isNotBlank(runnerParams.get(PROP_VCS_REVISION))) {
        matrixParams.put(BuildInfoFields.VCS_REVISION, runnerParams.get(PROP_VCS_REVISION));
    }

    HashMap<String, String> allParamMap = Maps
            .newHashMap(runnerContext.getBuildParameters().getAllParameters());
    allParamMap.putAll(((BuildRunnerContextImpl) runnerContext).getConfigParameters());
    gatherBuildInfoParams(allParamMap, matrixParams, ClientProperties.PROP_DEPLOY_PARAM_PROP_PREFIX,
            Constants.ENV_PREFIX, Constants.SYSTEM_PREFIX);

    return matrixParams;
}