List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:ch.cyberduck.core.azure.AzureWriteFeature.java
@Override public StatusOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try {//from www . j a v a 2 s.c o m final CloudAppendBlob blob = session.getClient() .getContainerReference(containerService.getContainer(file).getName()) .getAppendBlobReference(containerService.getKey(file)); if (StringUtils.isNotBlank(status.getMime())) { blob.getProperties().setContentType(status.getMime()); } final HashMap<String, String> headers = new HashMap<>(); // Add previous metadata when overwriting file headers.putAll(status.getMetadata()); blob.setMetadata(headers); // Remove additional headers not allowed in metadata and move to properties if (headers.containsKey(HttpHeaders.CACHE_CONTROL)) { blob.getProperties().setCacheControl(headers.get(HttpHeaders.CACHE_CONTROL)); headers.remove(HttpHeaders.CACHE_CONTROL); } if (headers.containsKey(HttpHeaders.CONTENT_TYPE)) { blob.getProperties().setCacheControl(headers.get(HttpHeaders.CONTENT_TYPE)); headers.remove(HttpHeaders.CONTENT_TYPE); } final Checksum checksum = status.getChecksum(); if (Checksum.NONE != checksum) { switch (checksum.algorithm) { case md5: try { blob.getProperties().setContentMD5( Base64.toBase64String(Hex.decodeHex(status.getChecksum().hash.toCharArray()))); headers.remove(HttpHeaders.CONTENT_MD5); } catch (DecoderException e) { // Ignore } break; } } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); options.setStoreBlobContentMD5(preferences.getBoolean("azure.upload.md5")); final BlobOutputStream out; if (status.isAppend()) { options.setStoreBlobContentMD5(false); out = blob.openWriteExisting(AccessCondition.generateEmptyCondition(), options, context); } else { out = blob.openWriteNew(AccessCondition.generateEmptyCondition(), options, context); } return new VoidStatusOutputStream(out) { @Override protected void handleIOException(final IOException e) throws IOException { if (StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if (cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch (StorageException e) { throw new AzureExceptionMappingService().map("Upload {0} failed", e, file); } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
From source file:com.oplay.nohelper.volley.toolbox.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError, NetworkError { if (request.getHasHttpResponse()) { throw new NetworkError("Slow Network leads to more HttpResponse"); }//from ww w. j a v a 2 s . c o m String url = request.getUrl(); request.addMarker(url); HashMap<String, String> map = new HashMap<String, String>(); 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); response.setEntity(entityFromConnection(connection)); request.addMarker("network-http-complete"); 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:och.service.props.impl.MultiProps.java
@Override public Map<String, String> toMap() { HashMap<String, String> out = new HashMap<>(); for (int i = list.size() - 1; i > -1; i--) { out.putAll(list.get(i).toMap()); }/*from w w w. java2 s . c o m*/ return out; }
From source file:cn.bidaround.ytcore.util.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 . j av a 2s . 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.miya38.connection.volley.CustomHurlStack.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 w w w . ja v a 2 s . c om 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); final 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."); } 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) { // bug fix y-miyazaki start for (final String value : header.getValue()) { final Header h = new BasicHeader(header.getKey(), value); response.addHeader(h); } // bug fix y-miyazaki end } } return response; }
From source file:com.yangcong345.android.phone.manager.OkHttpStack.java
@Override public synchronized HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { String url = request.getUrl(); if (mUrlRewriter != null) { String rewritten = mUrlRewriter.rewriteUrl(url); if (rewritten == null) { throw new IOException("URL blocked by rewriter: " + url); }//from w w w .j a v a 2s. c o m url = rewritten; } /*init request builder*/ okhttp3.Request.Builder okRequestBuilder = new okhttp3.Request.Builder().url(url) .cacheControl(new CacheControl.Builder().maxAge(0, TimeUnit.SECONDS).build()); /*set request headers*/ HashMap<String, String> map = new HashMap<String, String>(); map.putAll(request.getHeaders()); map.putAll(additionalHeaders); for (String headerName : map.keySet()) { okRequestBuilder.addHeader(headerName, map.get(headerName)); } /*set request method*/ setRequestMethod(okRequestBuilder, request); okhttp3.Request okRequest = okRequestBuilder.build(); /*init request client*/ int timeoutMs = request.getTimeoutMs(); OkHttpClient.Builder okClientBuilder = new OkHttpClient.Builder(); okClientBuilder.followRedirects(HttpURLConnection.getFollowRedirects()) .followSslRedirects(HttpURLConnection.getFollowRedirects()) .connectTimeout(timeoutMs, TimeUnit.MILLISECONDS).readTimeout(timeoutMs, TimeUnit.MILLISECONDS); if (okRequest.isHttps() && mSslSocketFactory != null) { okClientBuilder.sslSocketFactory(mSslSocketFactory); } // Initialize HttpResponse with data from the HttpURLConnection. ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); OkHttpClient okClient = okClientBuilder.build(); Response okResponse = okClient.newCall(okRequest).execute(); int responseCode = okResponse.code(); 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, responseCode, okResponse.message()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) { response.setEntity(entityFromOkHttp(okResponse)); } for (int i = 0; i < okResponse.headers().size(); i++) { String name = okResponse.headers().name(i); String value = okResponse.headers().value(i); Header h = new BasicHeader(name, value); response.addHeader(h); } return response; }
From source file:com.android.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);/*from w ww . 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:net.doubledoordev.backend.web.http.FreemarkerHandler.java
@Override protected boolean handle(String uri, Request request, Response response) throws Exception { if (request.getServerPort() == Settings.SETTINGS.portHTTP && Strings.isNotBlank(SETTINGS.certificatePath)) { StringBuilder redirect = new StringBuilder(); redirect.append("https://").append(request.getServerName()); if (SETTINGS.portHTTPS != 443) redirect.append(':').append(SETTINGS.portHTTPS); redirect.append(request.getRequest().getRequestURI()); if (request.getRequest().getQueryString() != null) redirect.append('?').append(request.getRequest().getQueryString()); response.sendRedirect(redirect.toString()); return true; }//from ww w.j a v a 2s . com lastRequest = System.currentTimeMillis(); if (request.getSession(false) != null) request.getSession(); HashMap<String, Object> data = new HashMap<>(request.getSession().attributes().size() + 10); // Put all session data in map, take 1 data.putAll(request.getSession().attributes()); /** * Data processing */ if (request.getMethod() == Method.GET) { Server server = Settings.getServerByName(request.getParameter(SERVER)); if (server != null && server.canUserControl((User) data.get(USER))) { data.put(SERVER, server); if (uri.equals(FILEMANAGER_URL)) data.put("fm", new FileManager(server, request.getParameter(FILE))); } } else if (request.getMethod() == Method.POST) { uri = POST_HANDLER.handle(data, uri, request, response); } else { response.sendError(HttpStatus.METHOD_NOT_ALLOWED_405.getStatusCode()); } if (uri == null) return true; /** * fix up the url to match template */ if (uri.endsWith(SLASH_STR)) uri += INDEX; if (uri.startsWith(SLASH_STR)) uri = uri.substring(1); if (request.getSession().getAttribute(USER) == null && !Settings.SETTINGS.anonPages.contains(uri)) { response.sendError(HttpStatus.UNAUTHORIZED_401.getStatusCode()); return true; } else if (ADMINPAGES.contains(uri) && !((User) request.getSession().getAttribute(USER)).isAdmin()) { response.sendError(HttpStatus.UNAUTHORIZED_401.getStatusCode()); return true; } if (!uri.endsWith(Constants.TEMPLATE_EXTENSION)) uri += Constants.TEMPLATE_EXTENSION; // Put all session data in map, take 2 data.putAll(request.getSession().attributes()); try { freemarker.getTemplate(uri).process(data, response.getWriter()); return true; } catch (FileNotFoundException ignored) { return false; } }
From source file:com.event.app.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);//from w ww . j av a2 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.kubeiwu.commontool.khttp.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);//ww w. ja v a 2 s. com if (mUrlRewriter != null) { String rewritten = mUrlRewriter.rewriteUrl(url);// ?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()) {// header 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); //cookie? String key = header.getKey(); List<String> values = header.getValue(); if (key.equalsIgnoreCase("set-cookie")) { StringBuilder cookieString = new StringBuilder(); for (String value : values) { cookieString.append(value).append("\n");// \ncookie?? } cookieString.deleteCharAt(cookieString.length() - 1); Header h = new BasicHeader(header.getKey(), cookieString.toString()); response.addHeader(h); } else { Header h = new BasicHeader(header.getKey(), values.get(0)); response.addHeader(h); } } } System.out.println("performRequest---999999-getStatusLine=" + response.getStatusLine()); return response; }