Java 类com.amazonaws.SdkClientException 实例源码

项目:ibm-cos-sdk-java    文件:ListKeysRequestProtocolMarshaller.java   
public Request<ListKeysRequest> marshall(ListKeysRequest listKeysRequest) {

        if (listKeysRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListKeysRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listKeysRequest);

            protocolMarshaller.startMarshalling();
            ListKeysRequestMarshaller.getInstance().marshall(listKeysRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:DownloadPartCallable.java   
public File call() throws Exception {
    partFile = File.createTempFile(
            destinationFile.getName() + "-tmp",
            TEMP_FILE_MIDDLE_NAME + getPartRequest.getPartNumber().toString(),
            new File(destinationFilePath.substring(0, destinationFilePath.lastIndexOf(File.separator))));
    try {
        partFile.deleteOnExit();
    } catch (SecurityException exception) {
        LOG.warn("SecurityException denied delete access to file " + partFile.getAbsolutePath());
    }

    if (s3.getObject(getPartRequest, partFile) == null) {
        throw new SdkClientException(
                "There is no object in S3 satisfying this request. The getObject method returned null");
    }
    return partFile;
}
项目:ibm-cos-sdk-java    文件:ObjectMetadata.java   
/**
 * <p>
 * Returns the content range of the object if response contains the Content-Range header.
 * </p>
 * <p>
 * If the request specifies a range or part number, then response returns the Content-Range range header.
 * Otherwise, the response does not return Content-Range header.
 * </p>
 * @return
 *      Returns content range if the object is requested with specific range or part number,
 *      null otherwise.
 */
public Long[] getContentRange() {
    String contentRange = (String) metadata.get(Headers.CONTENT_RANGE);
    Long[] range = null;
    if (contentRange != null) {
        String[] tokens = contentRange.split("[ -/]+");
        try {
            range = new Long[] { Long.parseLong(tokens[1]), Long.parseLong(tokens[2]) };
        } catch (NumberFormatException nfe) {
            throw new SdkClientException(
                    "Unable to parse content range. Header 'Content-Range' has corrupted data" + nfe.getMessage(),
                    nfe);
        }
    }
    return range;
}
项目:ibm-cos-sdk-java    文件:CreateKeyRequestProtocolMarshaller.java   
public Request<CreateKeyRequest> marshall(CreateKeyRequest createKeyRequest) {

        if (createKeyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<CreateKeyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    createKeyRequest);

            protocolMarshaller.startMarshalling();
            CreateKeyRequestMarshaller.getInstance().marshall(createKeyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:EnableKeyRotationRequestProtocolMarshaller.java   
public Request<EnableKeyRotationRequest> marshall(EnableKeyRotationRequest enableKeyRotationRequest) {

        if (enableKeyRotationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<EnableKeyRotationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    enableKeyRotationRequest);

            protocolMarshaller.startMarshalling();
            EnableKeyRotationRequestMarshaller.getInstance().marshall(enableKeyRotationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws SdkClientException, AmazonServiceException {
    listObjectsRequest = beforeClientExecution(listObjectsRequest);
    rejectNull(listObjectsRequest.getBucketName(), "The bucket name parameter must be specified when listing objects in a bucket");

    /**
     * This flag shows whether we need to url decode S3 key names. This flag is enabled
     * only when the customers don't explicitly call {@link ListObjectsRequest#setEncodingType(String)},
     * otherwise, it will be disabled for maintaining backwards compatibility.
     */
    final boolean shouldSDKDecodeResponse = listObjectsRequest.getEncodingType() == null;

    Request<ListObjectsRequest> request = createRequest(listObjectsRequest.getBucketName(), null, listObjectsRequest, HttpMethodName.GET);
    addParameterIfNotNull(request, "prefix", listObjectsRequest.getPrefix());
    addParameterIfNotNull(request, "marker", listObjectsRequest.getMarker());
    addParameterIfNotNull(request, "delimiter", listObjectsRequest.getDelimiter());
    if (listObjectsRequest.getMaxKeys() != null && listObjectsRequest.getMaxKeys().intValue() >= 0) request.addParameter("max-keys", listObjectsRequest.getMaxKeys().toString());
    request.addParameter("encoding-type", shouldSDKDecodeResponse ? Constants.URL_ENCODING : listObjectsRequest.getEncodingType());

    return invoke(request, new Unmarshallers.ListObjectsUnmarshaller(shouldSDKDecodeResponse), listObjectsRequest.getBucketName(), null);
}
项目:ibm-cos-sdk-java    文件:IonParser.java   
@Override
public Object getEmbeddedObject() throws IOException {
    if (currentToken != JsonToken.VALUE_EMBEDDED_OBJECT) {
        return null;
    }
    IonType currentType = reader.getType();
    switch (currentType) {
        case BLOB:
        case CLOB:
            return ByteBuffer.wrap(reader.newBytes());
        case TIMESTAMP:
            return reader.timestampValue().dateValue();
        default:
            throw new SdkClientException(String.format("Cannot return embedded object for Ion type %s", currentType));
    }
}
项目:ibm-cos-sdk-java    文件:AwsRegionProviderChain.java   
@Override
public String getRegion() throws SdkClientException {
    for (AwsRegionProvider provider : providers) {
        try {
            final String region = provider.getRegion();
            if (region != null) {
                return region;
            }
        } catch (Exception e) {
            // Ignore any exceptions and move onto the next provider
            LOG.debug("Unable to load region from " + provider.toString() +
                      ": " + e.getMessage());
        }
    }
    // Note: This is a bug in the provider chain. The chain should return null when no region is found according to
    // the interface, but an exception is thrown  here instead. This class is used in too many places to change now.
    // TODO: In 2.0, be sure this bug does not carry through.
    throw new SdkClientException("Unable to load region information from any provider in the chain");
}
项目:ibm-cos-sdk-java    文件:EncryptRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(EncryptRequest encryptRequest, ProtocolMarshaller protocolMarshaller) {

    if (encryptRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(encryptRequest.getKeyId(), KEYID_BINDING);
        protocolMarshaller.marshall(encryptRequest.getPlaintext(), PLAINTEXT_BINDING);
        protocolMarshaller.marshall(encryptRequest.getEncryptionContext(), ENCRYPTIONCONTEXT_BINDING);
        protocolMarshaller.marshall(encryptRequest.getGrantTokens(), GRANTTOKENS_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:ProfilesConfigFileWriter.java   
@Override
protected void onEndOfFile() {
    // Append profiles that don't exist in the original file
    for (Entry<String, Profile> entry : newProfiles.entrySet()) {
        String profileName = entry.getKey();
        Profile profile    = entry.getValue();

        if ( !existingProfileProperties.containsKey(profileName) ) {
            // The profile name is not found in the file
            // Append the profile properties
            writeProfile(profile);
            writeLine("");
        }
    }

    // Flush the "real" writer
    try {
        writer.flush();
    } catch (IOException ioe) {
        throw new SdkClientException(
                "Unable to write to the target file to persist the profile credentials.",
                ioe);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void deleteVersion(DeleteVersionRequest deleteVersionRequest)
        throws SdkClientException, AmazonServiceException {
    deleteVersionRequest = beforeClientExecution(deleteVersionRequest);
    rejectNull(deleteVersionRequest,
        "The delete version request object must be specified when deleting a version");

    String bucketName = deleteVersionRequest.getBucketName();
    String key = deleteVersionRequest.getKey();
    String versionId = deleteVersionRequest.getVersionId();

    rejectNull(bucketName, "The bucket name must be specified when deleting a version");
    rejectNull(key, "The key must be specified when deleting a version");
    rejectNull(versionId, "The version ID must be specified when deleting a version");

    Request<DeleteVersionRequest> request = createRequest(bucketName, key, deleteVersionRequest, HttpMethodName.DELETE);
    if (versionId != null) request.addParameter("versionId", versionId);

    if (deleteVersionRequest.getMfa() != null) {
        populateRequestWithMfaDetails(request, deleteVersionRequest.getMfa());
    }

    invoke(request, voidResponseHandler, bucketName, key);
}
项目:ibm-cos-sdk-java    文件:EC2MetadataClient.java   
/**
 * Reads a response from the Amazon EC2 Instance Metadata Service and
 * returns the content as a string.
 *
 * @param connection
 *            The connection to the Amazon EC2 Instance Metadata Service.
 *
 * @return The content contained in the response from the Amazon EC2
 *         Instance Metadata Service.
 *
 * @throws IOException
 *             If any problems ocurred while reading the response.
 */
private String readResponse(HttpURLConnection connection) throws IOException {
    if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
        throw new SdkClientException("The requested metadata is not found at " + connection.getURL());

    InputStream inputStream = connection.getInputStream();

    try {
        StringBuilder buffer = new StringBuilder();
        while (true) {
            int c = inputStream.read();
            if (c == -1) break;
            buffer.append((char)c);
        }

        return buffer.toString();
    } finally {
        inputStream.close();
    }
}
项目:ibm-cos-sdk-java    文件:ContentCryptoScheme.java   
/**
 * Creates and initializes a {@link CipherLite} for content
 * encrypt/decryption.
 * 
 * @param cek
 *            content encrypting key
 * @param iv
 *            initialization vector
 * @param cipherMode
 *            such as {@link Cipher#ENCRYPT_MODE}
 * @param securityProvider
 *            optional security provider to be used but only if there is no
 *            specific provider defined for the specified scheme.
 * @return the cipher lite created and initialized.
 */
CipherLite createCipherLite(SecretKey cek, byte[] iv, int cipherMode,
        Provider securityProvider) {
    String specificProvider = getSpecificCipherProvider();
    Cipher cipher;
    try {
        if (specificProvider != null) { // use the specific provider if defined
                cipher = Cipher.getInstance(getCipherAlgorithm(), specificProvider);
        } else if (securityProvider != null) { // use the one optionally specified in the input
            cipher = Cipher.getInstance(getCipherAlgorithm(), securityProvider);
        } else { // use the default provider
            cipher = Cipher.getInstance(getCipherAlgorithm());
        }
        cipher.init(cipherMode, cek, new IvParameterSpec(iv));
        return newCipherLite(cipher, cek, cipherMode);
    } catch (Exception e) {
        throw e instanceof RuntimeException
            ? (RuntimeException) e
            : new SdkClientException(
                "Unable to build cipher: "
                    + e.getMessage()
                    + "\nMake sure you have the JCE unlimited strength policy files installed and "
                    + "configured for your JVM",
                e);
    }
}
项目:ibm-cos-sdk-java    文件:GrantListEntryMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(GrantListEntry grantListEntry, ProtocolMarshaller protocolMarshaller) {

    if (grantListEntry == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(grantListEntry.getKeyId(), KEYID_BINDING);
        protocolMarshaller.marshall(grantListEntry.getGrantId(), GRANTID_BINDING);
        protocolMarshaller.marshall(grantListEntry.getName(), NAME_BINDING);
        protocolMarshaller.marshall(grantListEntry.getCreationDate(), CREATIONDATE_BINDING);
        protocolMarshaller.marshall(grantListEntry.getGranteePrincipal(), GRANTEEPRINCIPAL_BINDING);
        protocolMarshaller.marshall(grantListEntry.getRetiringPrincipal(), RETIRINGPRINCIPAL_BINDING);
        protocolMarshaller.marshall(grantListEntry.getIssuingAccount(), ISSUINGACCOUNT_BINDING);
        protocolMarshaller.marshall(grantListEntry.getOperations(), OPERATIONS_BINDING);
        protocolMarshaller.marshall(grantListEntry.getConstraints(), CONSTRAINTS_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:AwsChunkedEncodingInputStream.java   
private byte[] createSignedChunk(byte[] chunkData) {
    StringBuilder chunkHeader = new StringBuilder();
    // chunk-size
    chunkHeader.append(Integer.toHexString(chunkData.length));
    // sig-extension
    final String chunkStringToSign =
            CHUNK_STRING_TO_SIGN_PREFIX + "\n" +
            dateTime + "\n" +
            keyPath + "\n" +
            priorChunkSignature + "\n" +
            AbstractAWSSigner.EMPTY_STRING_SHA256_HEX + "\n" +
            BinaryUtils.toHex(sha256.digest(chunkData));
    final String chunkSignature =
        BinaryUtils.toHex(aws4Signer.signWithMac(chunkStringToSign, hmacSha256));
    priorChunkSignature = chunkSignature;
    chunkHeader.append(CHUNK_SIGNATURE_HEADER)
               .append(chunkSignature)
               .append(CRLF)
               ;
    try {
        byte[] header = chunkHeader.toString().getBytes(UTF8);
        byte[] trailer = CRLF.getBytes(UTF8);
        byte[] signedChunk = new byte[header.length + chunkData.length + trailer.length];
        System.arraycopy(header, 0, signedChunk, 0, header.length);
        System.arraycopy(chunkData, 0, signedChunk, header.length, chunkData.length);
        System.arraycopy(trailer, 0,
                signedChunk, header.length + chunkData.length,
                trailer.length);
        return signedChunk;
    } catch (Exception e) {
        throw new SdkClientException("Unable to sign the chunked data. " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void setBucketCrossOriginConfiguration(
        SetBucketCrossOriginConfigurationRequest setBucketCrossOriginConfigurationRequest) {
    setBucketCrossOriginConfigurationRequest = beforeClientExecution(setBucketCrossOriginConfigurationRequest);
    rejectNull(setBucketCrossOriginConfigurationRequest,
            "The set bucket cross origin configuration request object must be specified.");

    String bucketName = setBucketCrossOriginConfigurationRequest.getBucketName();
    BucketCrossOriginConfiguration bucketCrossOriginConfiguration = setBucketCrossOriginConfigurationRequest.getCrossOriginConfiguration();

    rejectNull(bucketName,
            "The bucket name parameter must be specified when setting bucket cross origin configuration.");
    rejectNull(bucketCrossOriginConfiguration,
            "The cross origin configuration parameter must be specified when setting bucket cross origin configuration.");

    Request<SetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName, null, setBucketCrossOriginConfigurationRequest, HttpMethodName.PUT);
    request.addParameter("cors", null);

    byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketCrossOriginConfiguration);
    request.addHeader("Content-Length", String.valueOf(content.length));
    request.addHeader("Content-Type", "application/xml");
    request.setContent(new ByteArrayInputStream(content));
    try {
        byte[] md5 = Md5Utils.computeMD5Hash(content);
        String md5Base64 = BinaryUtils.toBase64(md5);
        request.addHeader("Content-MD5", md5Base64);
    } catch ( Exception e ) {
        throw new SdkClientException("Couldn't compute md5 sum", e);
    }

    invoke(request, voidResponseHandler, bucketName, null);
}
项目:ibm-cos-sdk-java    文件:EC2CredentialsUtils.java   
/**
 * Connects to the given endpoint to read the resource
 * and returns the text contents.
 *
 * @param endpoint
 *            The service endpoint to connect to.
 *
 * @param retryPolicy
 *            The custom retry policy that determines whether a
 *            failed request should be retried or not.
 *
 * @return The text payload returned from the Amazon EC2 endpoint
 *         service for the specified resource path.
 *
 * @throws IOException
 *             If any problems were encountered while connecting to the
 *             service for the requested resource path.
 * @throws SdkClientException
 *             If the requested service is not found.
 */
public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy) throws IOException {
    int retriesAttempted = 0;
    InputStream inputStream = null;

    while (true) {
        try {
            HttpURLConnection connection = connectionUtils.connectToEndpoint(endpoint);

            int statusCode = connection.getResponseCode();

            if (statusCode == HttpURLConnection.HTTP_OK) {
                inputStream = connection.getInputStream();
                return IOUtils.toString(inputStream);
            } else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
                // This is to preserve existing behavior of EC2 Instance metadata service.
                throw new SdkClientException("The requested metadata is not found at " + connection.getURL());
            } else {
                if (!retryPolicy.shouldRetry(retriesAttempted++, CredentialsEndpointRetryParameters.builder().withStatusCode(statusCode).build())) {
                    inputStream = connection.getErrorStream();
                    handleErrorResponse(inputStream, statusCode, connection.getResponseMessage());
                }
            }
        } catch (IOException ioException) {
            if (!retryPolicy.shouldRetry(retriesAttempted++, CredentialsEndpointRetryParameters.builder().withException(ioException).build())) {
                throw ioException;
            }
            LOG.debug("An IOException occured when connecting to service endpoint: " + endpoint  + "\n Retrying to connect again.");
        } finally {
            IOUtils.closeQuietly(inputStream, LOG);
        }
    }

}
项目:ibm-cos-sdk-java    文件:SimpleTypeJsonUnmarshallers.java   
public Character unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception {
    String charString = unmarshallerContext.readText();

    if (charString == null) return null;

    charString = charString.trim();
    if (charString.isEmpty() || charString.length() > 1)
        throw new SdkClientException("'" + charString
                + "' cannot be converted to Character");
    return Character.valueOf(charString.charAt(0));
}
项目:ibm-cos-sdk-java    文件:SimpleTypeCborUnmarshallers.java   
public BigDecimal unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception {
    JsonParser parser = unmarshallerContext.getJsonParser();
    Unmarshaller<BigInteger, JsonUnmarshallerContext> bigIntegerUnmarshaller = unmarshallerContext.getUnmarshaller(BigInteger.class);

    JsonToken current = parser.getCurrentToken();
    if (current != JsonToken.START_ARRAY) {
        throw new SdkClientException("Invalid BigDecimal Format.");
    }
    parser.nextToken();
    int exponent = parser.getIntValue();
    parser.nextToken();
    BigInteger mantissa = bigIntegerUnmarshaller.unmarshall(unmarshallerContext);
    return new BigDecimal(mantissa, exponent);
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeStartArray() {
    try {
        writer.stepIn(IonType.LIST);
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeEndObject() {
    try {
        writer.stepOut();
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeValue(boolean bool) {
    try {
        writer.writeBool(bool);
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeValue(long val) {
    try {
        writer.writeInt(val);
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeValue(double val) {
    try {
        writer.writeFloat(val);
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey,
                                   String destinationBucketName, String destinationKey)
        throws SdkClientException, AmazonServiceException {
    return copyObject(new CopyObjectRequest(sourceBucketName, sourceKey,
                                            destinationBucketName, destinationKey));
}
项目:ibm-cos-sdk-java    文件:SdkIonGenerator.java   
@Override
public StructuredJsonGenerator writeValue(ByteBuffer bytes) {
    try {
        writer.writeBlob(BinaryUtils.copyAllBytesFrom(bytes));
    } catch (IOException e) {
        throw new SdkClientException(e);
    }
    return this;
}
项目:ibm-cos-sdk-java    文件:GenerateRandomRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(GenerateRandomRequest generateRandomRequest, ProtocolMarshaller protocolMarshaller) {

    if (generateRandomRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(generateRandomRequest.getNumberOfBytes(), NUMBEROFBYTES_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:S3V4AuthErrorRetryStrategy.java   
/**
 * If the response doesn't have the x-amz-region header we have to resort to sending a request
 * to s3-external-1
 *
 * @return
 */
private AuthRetryParameters redirectToS3External() {
    AWSS3V4Signer v4Signer = buildSigV4Signer(Regions.US_EAST_1.getName());
    try {
        URI bucketEndpoint = new URI(
                String.format("https://%s.s3-external-1.amazonaws.com", endpointResolver.getBucketName()));
        return buildRetryParams(v4Signer, bucketEndpoint);
    } catch (URISyntaxException e) {
        throw new SdkClientException(
                "Failed to re-send the request to \"s3-external-1.amazonaws.com\". " + V4_REGION_WARNING, e);
    }
}
项目:ibm-cos-sdk-java    文件:IonParser.java   
private JsonToken getJsonToken() {
    if (reader.isNullValue()) {
        return JsonToken.VALUE_NULL;
    }

    IonType currentType = reader.getType();
    switch (currentType) {
        case BLOB:
        case CLOB:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        case BOOL:
            return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
        case DECIMAL:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case FLOAT:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case INT:
            return JsonToken.VALUE_NUMBER_INT;
        case LIST:
            return JsonToken.START_ARRAY;
        case SEXP:
            return JsonToken.START_ARRAY;
        case STRING:
            return JsonToken.VALUE_STRING;
        case STRUCT:
            return JsonToken.START_OBJECT;
        case SYMBOL:
            return JsonToken.VALUE_STRING;
        case TIMESTAMP:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        default:
            throw new SdkClientException(String.format("Unhandled Ion type %s", currentType));
    }
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public HeadBucketResult headBucket(HeadBucketRequest headBucketRequest)
        throws SdkClientException, AmazonServiceException {
    headBucketRequest = beforeClientExecution(headBucketRequest);
    String bucketName = headBucketRequest.getBucketName();

    rejectNull(bucketName,
            "The bucketName parameter must be specified.");

    Request<HeadBucketRequest> request = createRequest(bucketName, null,
            headBucketRequest, HttpMethodName.HEAD);

    return invoke(request, new HeadBucketResultHandler(), bucketName, null);
}
项目:ibm-cos-sdk-java    文件:AliasListEntryMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(AliasListEntry aliasListEntry, ProtocolMarshaller protocolMarshaller) {

    if (aliasListEntry == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(aliasListEntry.getAliasName(), ALIASNAME_BINDING);
        protocolMarshaller.marshall(aliasListEntry.getAliasArn(), ALIASARN_BINDING);
        protocolMarshaller.marshall(aliasListEntry.getTargetKeyId(), TARGETKEYID_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClient.java   
/**
 * Executes the request and returns the result.
 */
private Response<Output> execute() {
    if (executionContext == null) {
        throw new SdkClientException(
                "Internal SDK Error: No execution context parameter specified.");
    }
    try {
        return executeWithTimer();
    } catch (InterruptedException ie) {
        throw handleInterruptedException(ie);
    } catch (AbortedException ae) {
        throw handleAbortedException(ae);
    }
}
项目:ibm-cos-sdk-java    文件:DeleteAliasRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(DeleteAliasRequest deleteAliasRequest, ProtocolMarshaller protocolMarshaller) {

    if (deleteAliasRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(deleteAliasRequest.getAliasName(), ALIASNAME_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:GetKeyPolicyRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(GetKeyPolicyRequest getKeyPolicyRequest, ProtocolMarshaller protocolMarshaller) {

    if (getKeyPolicyRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(getKeyPolicyRequest.getKeyId(), KEYID_BINDING);
        protocolMarshaller.marshall(getKeyPolicyRequest.getPolicyName(), POLICYNAME_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:ListGrantsRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(ListGrantsRequest listGrantsRequest, ProtocolMarshaller protocolMarshaller) {

    if (listGrantsRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(listGrantsRequest.getLimit(), LIMIT_BINDING);
        protocolMarshaller.marshall(listGrantsRequest.getMarker(), MARKER_BINDING);
        protocolMarshaller.marshall(listGrantsRequest.getKeyId(), KEYID_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
项目:ibm-cos-sdk-java    文件:AbstractAmazonS3.java   
@Override
public ListObjectsV2Result listObjectsV2(String bucketName)
        throws SdkClientException, AmazonServiceException {
    ListObjectsV2Request request = new ListObjectsV2Request();
    request.setBucketName(bucketName);
    return listObjectsV2(request);
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void changeObjectStorageClass(String bucketName, String key, StorageClass newStorageClass)
    throws SdkClientException, AmazonServiceException {
    rejectNull(bucketName,
        "The bucketName parameter must be specified when changing an object's storage class");
    rejectNull(key,
        "The key parameter must be specified when changing an object's storage class");
    rejectNull(newStorageClass,
        "The newStorageClass parameter must be specified when changing an object's storage class");

    copyObject(new CopyObjectRequest(bucketName, key, bucketName, key)
        .withStorageClass(newStorageClass.toString()));
}
项目:ibm-cos-sdk-java    文件:ProfileStaticCredentialsProvider.java   
private AWSCredentials fromStaticCredentials() {

    //IBM bx Credentials loaded
    if (!StringUtils.isNullOrEmpty(profile.getIBMApiKey())){
        return new BasicIBMOAuthCredentials(profile.getIBMApiKey(),
                profile.getIBMServiceInstanceId());
    }

    if (StringUtils.isNullOrEmpty(profile.getAwsAccessIdKey())) {
        throw new SdkClientException(String.format(
                "Unable to load credentials into profile [%s]: AWS Access Key ID is not specified.",
                profile.getProfileName()));
    }
    if (StringUtils.isNullOrEmpty(profile.getAwsSecretAccessKey())) {
        throw new SdkClientException(String.format(
                "Unable to load credentials into profile [%s]: AWS Secret Access Key is not specified.",
                profile.getAwsSecretAccessKey()));
    }

    if (profile.getAwsSessionToken() == null) {
        return new BasicAWSCredentials(profile.getAwsAccessIdKey(),
                                       profile.getAwsSecretAccessKey());
    } else {
        if (profile.getAwsSessionToken().isEmpty()) {
            throw new SdkClientException(String.format(
                    "Unable to load credentials into profile [%s]: AWS Session Token is empty.",
                    profile.getProfileName()));
        }

        return new BasicSessionCredentials(profile.getAwsAccessIdKey(),
                                           profile.getAwsSecretAccessKey(),
                                           profile.getAwsSessionToken());
    }
}
项目:ibm-cos-sdk-java    文件:AWS3Signer.java   
protected boolean shouldUseHttpsScheme(SignableRequest<?> request) throws SdkClientException {
    try {
        String protocol = StringUtils.lowerCase(request.getEndpoint().toURL().getProtocol());
        if (protocol.equals("http")) {
            return false;
        } else if (protocol.equals("https")) {
            return true;
        } else {
            throw new SdkClientException("Unknown request endpoint protocol " +
                    "encountered while signing request: " + protocol);
        }
    } catch (MalformedURLException e) {
        throw new SdkClientException("Unable to parse request endpoint during signing", e);
    }
}
项目:ibm-cos-sdk-java    文件:EnableKeyRotationRequestMarshaller.java   
/**
 * Marshall the given parameter object.
 */
public void marshall(EnableKeyRotationRequest enableKeyRotationRequest, ProtocolMarshaller protocolMarshaller) {

    if (enableKeyRotationRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(enableKeyRotationRequest.getKeyId(), KEYID_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}