Copyright Microsoft Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License 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.
/** * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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.microsoft.azure.storage.core; import java.net.HttpURLConnection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import com.microsoft.azure.storage.Constants;
RESERVED FOR INTERNAL USE. The base response class for the protocol layer
/** * RESERVED FOR INTERNAL USE. The base response class for the protocol layer */
public class BaseResponse {
Gets the ContentMD5
Params:
  • request – The response from server.
Returns:The ContentMD5.
/** * Gets the ContentMD5 * * @param request * The response from server. * @return The ContentMD5. */
public static String getContentMD5(final HttpURLConnection request) { return request.getHeaderField(Constants.HeaderConstants.CONTENT_MD5); }
Gets the Date
Params:
  • request – The response from server.
Returns:The Date.
/** * Gets the Date * * @param request * The response from server. * @return The Date. */
public static String getDate(final HttpURLConnection request) { final String retString = request.getHeaderField("Date"); return retString == null ? request.getHeaderField(Constants.HeaderConstants.DATE) : retString; }
Gets the Etag
Params:
  • request – The response from server.
Returns:The Etag.
/** * Gets the Etag * * @param request * The response from server. * @return The Etag. */
public static String getEtag(final HttpURLConnection request) { return request.getHeaderField(Constants.HeaderConstants.ETAG); }
Gets the ErrorCode
Params:
  • request – The response from server.
Returns:The ErrorCode.
/** * Gets the ErrorCode * * @param request * The response from server. * @return The ErrorCode. */
public static String getErrorCode(final HttpURLConnection request) { return request.getHeaderField(Constants.HeaderConstants.ERROR_CODE); }
Gets the metadata from the request.
Params:
  • request – The response from server.
Returns:the metadata from the request
/** * Gets the metadata from the request. * * @param request * The response from server. * * @return the metadata from the request */
public static HashMap<String, String> getMetadata(final HttpURLConnection request) { return getValuesByHeaderPrefix(request, Constants.HeaderConstants.PREFIX_FOR_STORAGE_METADATA); }
Gets the request id.
Params:
  • request – The response from server.
Returns:The request ID.
/** * Gets the request id. * * @param request * The response from server. * @return The request ID. */
public static String getRequestId(final HttpURLConnection request) { return request.getHeaderField(Constants.HeaderConstants.REQUEST_ID_HEADER); }
Gets if the request was encrypted by the server.
Params:
  • request – The response from the server.
Returns:A boolean indicating if the request was encrypted by the server.
/** * Gets if the request was encrypted by the server. * @param request * The response from the server. * @return A boolean indicating if the request was encrypted by the server. */
public static boolean isServerRequestEncrypted(HttpURLConnection request) { return Constants.TRUE.equals(request.getHeaderField(Constants.HeaderConstants.SERVER_REQUEST_ENCRYPTED)); }
Gets if the request was encrypted by the server.
Params:
  • request – The response from the server.
Returns:A boolean indicating if the request was encrypted by the server.
/** * Gets if the request was encrypted by the server. * @param request * The response from the server. * @return A boolean indicating if the request was encrypted by the server. */
public static boolean isServerEncrypted(HttpURLConnection request) { return Constants.TRUE.equals(request.getHeaderField(Constants.HeaderConstants.SERVER_ENCRYPTED)); }
Gets the hash of the client-provided encryption key used for encryption.
Params:
  • request –
Returns:
/** * Gets the hash of the client-provided encryption key used for encryption. * @param request * @return */
public static String getEncryptionKeyHash(HttpURLConnection request) { return request.getHeaderField(Constants.HeaderConstants.CLIENT_PROVIDED_ENCRYPTION_KEY_HASH); }
Returns all the header/value pairs with the given prefix.
Params:
  • request – the request object containing headers to parse.
  • prefix – the prefix for headers to be returned.
Returns:all the header/value pairs with the given prefix.
/** * Returns all the header/value pairs with the given prefix. * * @param request * the request object containing headers to parse. * @param prefix * the prefix for headers to be returned. * @return all the header/value pairs with the given prefix. */
private static HashMap<String, String> getValuesByHeaderPrefix(final HttpURLConnection request, final String prefix) { final HashMap<String, String> retVals = new HashMap<String, String>(); final Map<String, List<String>> headerMap = request.getHeaderFields(); final int prefixLength = prefix.length(); for (final Entry<String, List<String>> entry : headerMap.entrySet()) { if (entry.getKey() != null && entry.getKey().startsWith(prefix)) { final List<String> currHeaderValues = entry.getValue(); retVals.put(entry.getKey().substring(prefixLength), currHeaderValues.get(0)); } } return retVals; }
Private Default Ctor
/** * Private Default Ctor */
protected BaseResponse() { // No op } }