/** * Returns extended error information for this request. * * @return A {@link StorageExtendedErrorInformation} object that represents the error details for the specified * request. */ public StorageExtendedErrorInformation parseErrorDetails() { try { if (this.getConnection() == null || this.getConnection().getErrorStream() == null) { return null; } return StorageErrorHandler.getExtendedErrorInformation(this.getConnection().getErrorStream()); } catch (final Exception e) { return null; } } }
/** * Returns either the held exception from the operation if it is set, otherwise the translated exception. * * @param opContext * an object used to track the execution of the operation * @return the exception to throw. */ protected final StorageException materializeException(final OperationContext opContext) { if (this.getException() != null) { return this.getException(); } return StorageException.translateException(this, null, opContext); }
@SuppressWarnings("incomplete-switch") public void validateLocation() { if (this.getStorageUri() != null) { if (!this.getStorageUri().validateLocationMode(this.locationMode)) { throw new UnsupportedOperationException(SR.STORAGE_URI_MISSING_LOCATION); } } // If the command only allows for a specific location, we should target // that location no matter what the retry policy says. switch (this.getRequestLocationMode()) { case PRIMARY_ONLY: if (this.getLocationMode() == LocationMode.SECONDARY_ONLY) { throw new IllegalArgumentException(SR.PRIMARY_ONLY_COMMAND); } this.setCurrentLocation(StorageLocation.PRIMARY); this.setLocationMode(LocationMode.PRIMARY_ONLY); break; case SECONDARY_ONLY: if (this.getLocationMode() == LocationMode.PRIMARY_ONLY) { throw new IllegalArgumentException(SR.SECONDARY_ONLY_COMMAND); } this.setCurrentLocation(StorageLocation.SECONDARY); this.setLocationMode(LocationMode.SECONDARY_ONLY); break; } this.getResult().setTargetLocation(this.currentLocation); }
public void initializeLocation() { if (this.getStorageUri() != null) { switch (this.getLocationMode()) { case PRIMARY_ONLY: case PRIMARY_THEN_SECONDARY: this.setCurrentLocation(StorageLocation.PRIMARY); break; case SECONDARY_ONLY: case SECONDARY_THEN_PRIMARY: this.setCurrentLocation(StorageLocation.SECONDARY); break; default: throw new IllegalArgumentException(String.format(SR.ARGUMENT_OUT_OF_RANGE_ERROR, "locationMode", this.getLocationMode())); } } else { this.setCurrentLocation(StorageLocation.PRIMARY); } }
public void applyLocationModeToRequest() { if (this.getRequestOptions().getLocationMode() != null) { this.setLocationMode(this.getRequestOptions().getLocationMode()); } }
if (task.getSendStream() != null) { Logger.info(opContext, LogConstants.UPLOAD); if (task.getLength() >= 0) { request.setFixedLengthStreamingMode(task.getLength()); final StreamMd5AndLength descriptor = Utility.writeToOutputStream(task.getSendStream(), request.getOutputStream(), task.getLength(), false /* rewindStream */, false /* calculate MD5 */, opContext, task.getRequestOptions()); task.validateStreamWrite(descriptor); Logger.info(opContext, LogConstants.UPLOADDONE); RequestResult currResult = task.getResult(); currResult.setStartDate(new Date()); ExecutionEngine.fireResponseReceivedEvent(opContext, request, task.getResult()); Logger.info(opContext, LogConstants.ERROR_RECEIVING_RESPONSE); if (!responseReceivedEventTriggered) { if (task.getResult().getStartDate() == null) { task.getResult().setStartDate(new Date()); ExecutionEngine.fireErrorReceivingResponseEvent(opContext, request, task.getResult()); RESULT_TYPE result = task.preProcessResponse(parentObject, client, opContext); Logger.info(opContext, LogConstants.PRE_PROCESS_DONE); if (!task.isNonExceptionedRetryableFailure()) {
task.initialize(opContext); if (Utility.validateMaxExecutionTimeout(task.getRequestOptions().getOperationExpiryTimeInMs())) { task.recoveryAction(opContext); Logger.info(opContext, LogConstants.RETRY); task.applyLocationModeToRequest(); task.initializeLocation(); Logger.info(opContext, LogConstants.STARTING); task.setRequestLocationMode(); task.validateLocation(); Logger.info(opContext, LogConstants.INIT_LOCATION, task.getCurrentLocation(), task.getLocationMode()); HttpURLConnection request = task.buildRequest(client, parentObject, opContext); task.setHeaders(request, parentObject, opContext); ExecutionEngine.fireSendingRequestEvent(opContext, request, task.getResult()); task.setIsSent(true); task.signRequest(request, client, opContext); task.setConnection(request);
request.setCurrentRequestByteCount(request.getCurrentRequestByteCount() + count); request.setCurrentDescriptor(descriptor);
if (request == null || request.getConnection() == null) { return translateClientException(cause); int responseCode = 0; try { responseCode = request.getConnection().getResponseCode(); responseMessage = request.getConnection().getResponseMessage(); } catch (final IOException e) { StorageExtendedErrorInformation extendedError = request.parseErrorDetails(); translatedException = new StorageException(request.getResult().getErrorCode(), responseMessage, responseCode, extendedError, cause);
if (request == null || request.getConnection() == null) { return translateClientException(cause); int responseCode = 0; try { responseCode = request.getConnection().getResponseCode(); responseMessage = request.getConnection().getResponseMessage(); } catch (final IOException e) { StorageExtendedErrorInformation extendedError = request.parseErrorDetails(); if (extendedError != null) {
if (task.getSendStream() != null) { Logger.info(opContext, LogConstants.UPLOAD); final StreamMd5AndLength descriptor = Utility.writeToOutputStream(task.getSendStream(), request.getOutputStream(), task.getLength(), false /* rewindStream */, false /* calculate MD5 */, opContext, task.getRequestOptions()); task.validateStreamWrite(descriptor); Logger.info(opContext, LogConstants.UPLOADDONE); RequestResult currResult = task.getResult(); currResult.setStartDate(new Date()); ExecutionEngine.fireResponseReceivedEvent(opContext, request, task.getResult()); Logger.info(opContext, LogConstants.ERROR_RECEIVING_RESPONSE); if (!responseReceivedEventTriggered) { if (task.getResult().getStartDate() == null) { task.getResult().setStartDate(new Date()); ExecutionEngine.fireErrorReceivingResponseEvent(opContext, request, task.getResult()); RESULT_TYPE result = task.preProcessResponse(parentObject, client, opContext); Logger.info(opContext, LogConstants.PRE_PROCESS_DONE); if (!task.isNonExceptionedRetryableFailure()) { result = task.postProcessResponse(request, parentObject, client, opContext, result); Logger.info(opContext, LogConstants.POST_PROCESS_DONE);
task.initialize(opContext); if (Utility.validateMaxExecutionTimeout(task.getRequestOptions().getOperationExpiryTimeInMs())) { task.recoveryAction(opContext); Logger.info(opContext, LogConstants.RETRY); task.applyLocationModeToRequest(); task.initializeLocation(); Logger.info(opContext, LogConstants.STARTING); task.setRequestLocationMode(); task.validateLocation(); Logger.info(opContext, LogConstants.INIT_LOCATION, task.getCurrentLocation(), task.getLocationMode()); HttpURLConnection request = task.buildRequest(client, parentObject, opContext); task.setHeaders(request, parentObject, opContext); ExecutionEngine.fireSendingRequestEvent(opContext, request, task.getResult()); task.setIsSent(true); task.signRequest(request, client, opContext); task.setConnection(request);
public void initializeLocation() { if (this.getStorageUri() != null) { switch (this.getLocationMode()) { case PRIMARY_ONLY: case PRIMARY_THEN_SECONDARY: this.setCurrentLocation(StorageLocation.PRIMARY); break; case SECONDARY_ONLY: case SECONDARY_THEN_PRIMARY: this.setCurrentLocation(StorageLocation.SECONDARY); break; default: throw new IllegalArgumentException(String.format(SR.ARGUMENT_OUT_OF_RANGE_ERROR, "locationMode", this.getLocationMode())); } } else { this.setCurrentLocation(StorageLocation.PRIMARY); } }
request.setCurrentRequestByteCount(request.getCurrentRequestByteCount() + count); request.setCurrentDescriptor(descriptor);
public void applyLocationModeToRequest() { if (this.getRequestOptions().getLocationMode() != null) { this.setLocationMode(this.getRequestOptions().getLocationMode()); } }
@SuppressWarnings("incomplete-switch") public void validateLocation() { if (this.getStorageUri() != null) { if (!this.getStorageUri().validateLocationMode(this.locationMode)) { throw new UnsupportedOperationException(SR.STORAGE_URI_MISSING_LOCATION); } } // If the command only allows for a specific location, we should target // that location no matter what the retry policy says. switch (this.getRequestLocationMode()) { case PRIMARY_ONLY: if (this.getLocationMode() == LocationMode.SECONDARY_ONLY) { throw new IllegalArgumentException(SR.PRIMARY_ONLY_COMMAND); } this.setCurrentLocation(StorageLocation.PRIMARY); this.setLocationMode(LocationMode.PRIMARY_ONLY); break; case SECONDARY_ONLY: if (this.getLocationMode() == LocationMode.PRIMARY_ONLY) { throw new IllegalArgumentException(SR.SECONDARY_ONLY_COMMAND); } this.setCurrentLocation(StorageLocation.SECONDARY); this.setLocationMode(LocationMode.SECONDARY_ONLY); break; } this.getResult().setTargetLocation(this.currentLocation); }
/** * Returns extended error information for this request. * * @return A {@link StorageExtendedErrorInformation} object that represents the error details for the specified * request. */ public StorageExtendedErrorInformation parseErrorDetails() { try { if (this.getConnection() == null || this.getConnection().getErrorStream() == null) { return null; } return StorageErrorHandler.getExtendedErrorInformation(this.getConnection().getErrorStream()); } catch (final Exception e) { return null; } } }
/** * Returns either the held exception from the operation if it is set, otherwise the translated exception. * * @param request * the reference to the HttpURLConnection for the operation. * @param opContext * an object used to track the execution of the operation * @return the exception to throw. */ protected final StorageException materializeException(final OperationContext opContext) { if (this.getException() != null) { return this.getException(); } return StorageException.translateException(this, null, opContext); }
/** * Parse the table extended error information from the response body. * * @param request * the request whose body to examine for the error information. * @return The {@link StorageExtendedErrorInformation} parsed from the body or null if parsing fails or the request * contains no body. */ public static StorageExtendedErrorInformation parseErrorDetails(StorageRequest<CloudTableClient, ?, ?> request) { try { if (request == null || request.getConnection().getErrorStream() == null) { return null; } return getExtendedErrorInformation(new InputStreamReader(request.getConnection().getErrorStream()), TablePayloadFormat.Json); } catch (Exception e) { return null; } }
/** * Parse the table extended error information from the response body. * * @param request * the request whose body to examine for the error information. * @return The {@link StorageExtendedErrorInformation} parsed from the body or null if parsing fails or the request * contains no body. */ public static StorageExtendedErrorInformation parseErrorDetails(StorageRequest<CloudTableClient, ?, ?> request) { try { if (request == null || request.getConnection().getErrorStream() == null) { return null; } return getExtendedErrorInformation(new InputStreamReader( request.getConnection().getErrorStream()), TablePayloadFormat.Json); } catch (Exception e) { return null; } }