/// <exception cref="System.IO.IOException"/> private Uri CreateURL(string collection, string resource, string subResource, IDictionary <string, object> parameters) { try { StringBuilder sb = new StringBuilder(); sb.Append(kmsUrl); if (collection != null) { sb.Append(collection); if (resource != null) { sb.Append("/").Append(URLEncoder.Encode(resource, Utf8)); if (subResource != null) { sb.Append("/").Append(subResource); } } } URIBuilder uriBuilder = new URIBuilder(sb.ToString()); if (parameters != null) { foreach (KeyValuePair <string, object> param in parameters) { object value = param.Value; if (value is string) { uriBuilder.AddParameter(param.Key, (string)value); } else { foreach (string s in (string[])value) { uriBuilder.AddParameter(param.Key, s); } } } } return(uriBuilder.Build().ToURL()); } catch (URISyntaxException ex) { throw new IOException(ex); } }
/// <since>4.1</since> /// <exception cref="Apache.Http.ProtocolException"></exception> protected internal virtual URI CreateLocationURI(string location) { try { URIBuilder b = new URIBuilder(new URI(location).Normalize()); string host = b.GetHost(); if (host != null) { b.SetHost(host.ToLower(CultureInfo.InvariantCulture)); } string path = b.GetPath(); if (TextUtils.IsEmpty(path)) { b.SetPath("/"); } return(b.Build()); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } }
/* * Uploads the imagefile using HTTP PUT method */ /// <exception cref="System.IO.IOException"/> private static void UploadImage(Uri url, Configuration conf, NNStorage storage, NNStorage.NameNodeFile nnf, long txId, Canceler canceler) { FilePath imageFile = storage.FindImageFile(nnf, txId); if (imageFile == null) { throw new IOException("Could not find image with txid " + txId); } HttpURLConnection connection = null; try { URIBuilder uriBuilder = new URIBuilder(url.ToURI()); // write all params for image upload request as query itself. // Request body contains the image to be uploaded. IDictionary <string, string> @params = ImageServlet.GetParamsForPutImage(storage, txId, imageFile.Length(), nnf); foreach (KeyValuePair <string, string> entry in @params) { uriBuilder.AddParameter(entry.Key, entry.Value); } Uri urlWithParams = uriBuilder.Build().ToURL(); connection = (HttpURLConnection)connectionFactory.OpenConnection(urlWithParams, UserGroupInformation .IsSecurityEnabled()); // Set the request to PUT connection.SetRequestMethod("PUT"); connection.SetDoOutput(true); int chunkSize = conf.GetInt(DFSConfigKeys.DfsImageTransferChunksizeKey, DFSConfigKeys .DfsImageTransferChunksizeDefault); if (imageFile.Length() > chunkSize) { // using chunked streaming mode to support upload of 2GB+ files and to // avoid internal buffering. // this mode should be used only if more than chunkSize data is present // to upload. otherwise upload may not happen sometimes. connection.SetChunkedStreamingMode(chunkSize); } SetTimeout(connection); // set headers for verification ImageServlet.SetVerificationHeadersForPut(connection, imageFile); // Write the file to output stream. WriteFileToPutRequest(conf, connection, imageFile, canceler); int responseCode = connection.GetResponseCode(); if (responseCode != HttpURLConnection.HttpOk) { throw new TransferFsImage.HttpPutFailedException(string.Format("Image uploading failed, status: %d, url: %s, message: %s" , responseCode, urlWithParams, connection.GetResponseMessage()), responseCode); } } catch (AuthenticationException e) { throw new IOException(e); } catch (URISyntaxException e) { throw new IOException(e); } finally { if (connection != null) { connection.Disconnect(); } } }
private void Start() { _yandexForecastURIBuilder = new URIBuilder(_yandexForecastURL); }