List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:com.yaozu.object.volley.toolbox.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>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);// w w w . ja v 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); 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:com.xjb.volley.toobox.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>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);//from w w w. j ava 2 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); for (String headerName : map.keySet()) { try { connection.addRequestProperty(headerName, map.get(headerName)); } catch (Exception e) { } } 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) { synchronized (HurlStack.class) { if (header.getKey().equals("Set-Cookie")) { String cookie = ""; List<String> list = header.getValue(); if (list.size() > 0) { for (int i = 0; i < list.size(); i++) { if (list.get(i).contains("IHOME_FRONT_SID")) { String[] ss = list.get(i).split(";"); cookie = ss[0]; } } } Header h = new BasicHeader(header.getKey(), cookie); response.addHeader(h); } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } } return response; }
From source file:de.huberlin.wbi.cfjava.data.Amap.java
public Amap<K, V> merge(Amap<K, V> tm2) { HashMap<K, V> newContent; if (tm2 == null) throw new IllegalArgumentException("Other term map must not be null."); newContent = new HashMap<>(); newContent.putAll(content); newContent.putAll(tm2.content);//from www .j a v a2 s. c o m return new Amap<>(newContent); }
From source file:com.hackerati.android.user_sdk.volley.HHurlStack.java
@Override public HttpResponse performRequest(final Request<?> request, final Map<String, String> additionalHeaders) throws IOException, AuthFailureError { String url = request.getUrl(); final HashMap<String, String> map = new HashMap<String, String>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);//from ww w . j a va2 s .co m if (mUrlRewriter != null) { final String rewritten = mUrlRewriter.rewriteUrl(url); if (rewritten == null) { throw new IOException("URL blocked by rewriter: " + url); } url = rewritten; } final URL parsedUrl = new URL(url); final HttpURLConnection connection = openConnection(parsedUrl, request); for (final String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } setConnectionParametersForRequest(connection, request); // Initialize HttpResponse with data from the HttpURLConnection. final ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); int responseCode; try { // Will throw IOException if server responds with 401. responseCode = connection.getResponseCode(); } catch (final IOException e) { // Will return 401, because now connection has the correct internal // state. 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."); } final StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(), connection.getResponseMessage()); final BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (final Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { final Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } return response; }
From source file:org.epics.archiverappliance.TomcatSetup.java
private HashMap<String, String> createEnvironment(String testName, String applianceName) { HashMap<String, String> environment = new HashMap<String, String>(); environment.putAll(System.getenv()); environment.remove("CLASSPATH"); environment.put("CATALINA_HOME", System.getenv("TOMCAT_HOME")); File workFolder = new File("tomcat_" + testName + File.separator + applianceName); assert (workFolder.exists()); environment.put("CATALINA_BASE", workFolder.getAbsolutePath()); environment.put(ConfigService.ARCHAPPL_CONFIGSERVICE_IMPL, ConfigServiceForTests.class.getName()); environment.put(DefaultConfigService.SITE_FOR_UNIT_TESTS_NAME, DefaultConfigService.SITE_FOR_UNIT_TESTS_VALUE); environment.put(ConfigService.ARCHAPPL_MYIDENTITY, applianceName); if (!System.getProperties().containsKey(ConfigService.ARCHAPPL_APPLIANCES)) { environment.put(ConfigService.ARCHAPPL_APPLIANCES, new File("./src/sitespecific/tests/classpathfiles/appliances.xml").getAbsolutePath()); } else {/* ww w.ja va 2 s .c o m*/ environment.put(ConfigService.ARCHAPPL_APPLIANCES, (String) System.getProperties().get(ConfigService.ARCHAPPL_APPLIANCES)); } if (!System.getProperties().containsKey(ConfigService.ARCHAPPL_PERSISTENCE_LAYER) || System.getProperties() .get(ConfigService.ARCHAPPL_PERSISTENCE_LAYER).equals(InMemoryPersistence.class.getName())) { environment.put(ConfigService.ARCHAPPL_PERSISTENCE_LAYER, "org.epics.archiverappliance.config.persistence.InMemoryPersistence"); } else { String persistenceFile = (String) System.getProperties().get(JDBM2Persistence.ARCHAPPL_JDBM2_FILENAME); logger.info("Persistence layer is provided by " + System.getProperties().get(ConfigService.ARCHAPPL_PERSISTENCE_LAYER)); assert (persistenceFile != null); String persistenceFileForMember = persistenceFile.replace(".jdbm2", "_" + applianceName + ".jdbm2"); environment.put(ConfigService.ARCHAPPL_PERSISTENCE_LAYER, (String) System.getProperties().get(ConfigService.ARCHAPPL_PERSISTENCE_LAYER)); environment.put(JDBM2Persistence.ARCHAPPL_JDBM2_FILENAME, persistenceFileForMember); logger.info("Persistence file for member " + persistenceFileForMember); } overrideEnvWithSystemProperty(environment, "ARCHAPPL_SHORT_TERM_FOLDER"); overrideEnvWithSystemProperty(environment, "ARCHAPPL_MEDIUM_TERM_FOLDER"); overrideEnvWithSystemProperty(environment, "ARCHAPPL_LONG_TERM_FOLDER"); if (logger.isDebugEnabled()) { for (String key : environment.keySet()) { logger.debug("Env " + key + "=" + environment.get(key)); } } return environment; }
From source file:com.baseproject.volley.toolbox.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>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);//w ww.ja v a 2 s . c o m if (mUrlRewriter != null) { String rewritten = mUrlRewriter.rewriteUrl(url); if (rewritten == null) { throw new IOException(Util.buildHttpErrorMsg("failed", -1, "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."); // } if (responseCode != HttpStatus.SC_NOT_MODIFIED && responseCode != HttpURLConnection.HTTP_OK) { InputStream in = null; try { in = connection.getErrorStream(); } catch (Exception e) { e.printStackTrace(); } if (in == null) { throw new IOException(Util.buildHttpErrorMsg("failed", responseCode, "unknown")); } else { throw new IOException(Util.convertStreamToString(in)); } } 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) { if (header.getKey().equals("Set-Cookie")) { List<String> cookieValue = header.getValue(); for (String c : cookieValue) { Header h = new BasicHeader(header.getKey(), c); response.addHeader(h); } } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } return response; }
From source file:com.enonic.cms.core.user.field.UserFieldTransformer.java
public Map<String, String> toStoreableMap(UserFields fields) { HashMap<String, String> result = new HashMap<String, String>(); for (UserField field : fields) { if (!field.isAddress() && !field.isPhoto()) { addSimpleField(result, field); }/*from www.ja v a 2 s .co m*/ } result.putAll(this.addressTransformer.toStoreableMap(fields)); return result; }
From source file:io.lqd.sdk.model.LQDevice.java
public JSONObject toJSON() { // Updating to avoid callbacks mInternetConnectivity = LQDevice.getInternetConnectivity(mContext); HashMap<String, Object> attrs = new HashMap<String, Object>(); if (mAttributes != null) { attrs.putAll(mAttributes); }//from www . j av a 2 s. c o m attrs.put("vendor", mVendor); attrs.put("platform", "Android"); attrs.put("model", mDeviceModel); try { attrs.put("system_version", Integer.parseInt(mSystemVersion)); } catch (NumberFormatException e) { attrs.put("system_version", mSystemVersion); } attrs.put("screen_size", mScreenSize); attrs.put("carrier", mCarrier); attrs.put("internet_connectivity", mInternetConnectivity); attrs.put("unique_id", mUid); attrs.put("app_bundle", mAppBundle); attrs.put("app_name", mAppName); attrs.put("app_version", mAppVersion); attrs.put("release_version", mReleaseVersion); attrs.put("liquid_version", mLiquidVersion); attrs.put("locale", mLocale); attrs.put("system_language", mSystemLanguage); JSONObject json = new JSONObject(); try { if (attrs != null) { for (String key : attrs.keySet()) { json.put(key, attrs.get(key)); } } return json; } catch (JSONException e) { LQLog.error("LQDevice toJSON: " + e.getMessage()); } return null; }
From source file:com.navercorp.volleyextensions.volleyer.multipart.stack.MultipartHurlStack.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>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders);//from w w w . j a va 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); 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); 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.android.volley.stack.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HashMap<String, String> map = new HashMap<String, String>(); if (!TextUtils.isEmpty(mUserAgent)) { map.put(HTTP.USER_AGENT, mUserAgent); }// w w w.j a v a 2 s. co m map.putAll(request.getHeaders()); URL parsedUrl = new URL(request.getUrl()); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } setConnectionParametersForRequest(connection, request); 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(new ProtocolVersion("HTTP", 1, 1), 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; }