java 调用阿里云OSS


1、重写OSS

   1 import static com.aliyun.oss.common.utils.CodingUtils.assertParameterNotNull;
   2 import static com.aliyun.oss.common.utils.IOUtils.checkFile;
   3 import static com.aliyun.oss.common.utils.LogUtils.logException;
   4 import static com.aliyun.oss.internal.OSSConstants.DEFAULT_CHARSET_NAME;
   5 import static com.aliyun.oss.internal.OSSConstants.DEFAULT_OSS_ENDPOINT;
   6 import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER;
   7 import static com.aliyun.oss.internal.OSSUtils.ensureBucketNameValid;
   8 
   9 import java.io.File;
  10 import java.io.FileInputStream;
  11 import java.io.FileNotFoundException;
  12 import java.io.IOException;
  13 import java.io.InputStream;
  14 import java.io.UnsupportedEncodingException;
  15 import java.net.InetAddress;
  16 import java.net.MalformedURLException;
  17 import java.net.URI;
  18 import java.net.URISyntaxException;
  19 import java.net.URL;
  20 import java.net.UnknownHostException;
  21 import java.util.Date;
  22 import java.util.List;
  23 import java.util.Map;
  24 
  25 import com.aliyun.oss.*;
  26 import com.aliyun.oss.common.auth.Credentials;
  27 import com.aliyun.oss.common.auth.CredentialsProvider;
  28 import com.aliyun.oss.common.auth.DefaultCredentialProvider;
  29 import com.aliyun.oss.common.auth.ServiceSignature;
  30 import com.aliyun.oss.common.comm.*;
  31 import com.aliyun.oss.common.utils.BinaryUtil;
  32 import com.aliyun.oss.common.utils.DateUtil;
  33 import com.aliyun.oss.internal.*;
  34 import com.aliyun.oss.model.*;
  35 import com.aliyun.oss.model.SetBucketCORSRequest.CORSRule;
  36 
  37 
  38 public class OSSClient implements OSS {
  39 
  40     private CredentialsProvider credsProvider;
  41 
  42     private URI endpoint;
  43 
  44     private ServiceClient serviceClient;
  45 
  46     private OSSBucketOperation bucketOperation;
  47     private OSSObjectOperation objectOperation;
  48     private OSSMultipartOperation multipartOperation;
  49     private CORSOperation corsOperation;
  50     private OSSUploadOperation uploadOperation;
  51     private OSSDownloadOperation downloadOperation;
  52     private LiveChannelOperation liveChannelOperation;
  53 
  54 
  55     @Deprecated
  56     public OSSClient(String accessKeyId, String secretAccessKey) {
  57         this(DEFAULT_OSS_ENDPOINT, new DefaultCredentialProvider(accessKeyId, secretAccessKey));
  58     }
  59 
  60 
  61     @Deprecated
  62     public OSSClient(String endpoint, String accessKeyId, String secretAccessKey) {
  63         this(endpoint, new DefaultCredentialProvider(accessKeyId, secretAccessKey), null);
  64     }
  65 
  66 
  67     @Deprecated
  68     public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, String securityToken) {
  69         this(endpoint, new DefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken), null);
  70     }
  71 
  72     @Deprecated
  73     public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, ClientConfiguration config) {
  74         this(endpoint, new DefaultCredentialProvider(accessKeyId, secretAccessKey), config);
  75     }
  76 
  77     @Deprecated
  78     public OSSClient(String endpoint, String accessKeyId, String secretAccessKey, String securityToken,
  79                      ClientConfiguration config) {
  80         this(endpoint, new DefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken), config);
  81     }
  82 
  83     @Deprecated
  84     public OSSClient(String endpoint, CredentialsProvider credsProvider) {
  85         this(endpoint, credsProvider, null);
  86     }
  87 
  88     public OSSClient(String endpoint, CredentialsProvider credsProvider, ClientConfiguration config) {
  89         this.credsProvider = credsProvider;
  90         config = config == null ? new ClientConfiguration() : config;
  91         if (config.isRequestTimeoutEnabled()) {
  92             this.serviceClient = new TimeoutServiceClient(config);
  93         } else {
  94             this.serviceClient = new DefaultServiceClient(config);
  95         }
  96         initOperations();
  97         setEndpoint(endpoint);
  98     }
  99 
 100 
 101     public synchronized URI getEndpoint() {
 102         return URI.create(endpoint.toString());
 103     }
 104 
 105 
 106     public synchronized void setEndpoint(String endpoint) {
 107         URI uri = toURI(endpoint);
 108         this.endpoint = uri;
 109 
 110         if (isIpOrLocalhost(uri)) {
 111             serviceClient.getClientConfiguration().setSLDEnabled(true);
 112         }
 113 
 114         this.bucketOperation.setEndpoint(uri);
 115         this.objectOperation.setEndpoint(uri);
 116         this.multipartOperation.setEndpoint(uri);
 117         this.corsOperation.setEndpoint(uri);
 118         this.liveChannelOperation.setEndpoint(uri);
 119     }
 120 
 121     private boolean isIpOrLocalhost(URI uri) {
 122         if (uri.getHost().equals("localhost")) {
 123             return true;
 124         }
 125 
 126         InetAddress ia;
 127         try {
 128             ia = InetAddress.getByName(uri.getHost());
 129         } catch (UnknownHostException e) {
 130             return false;
 131         }
 132 
 133         if (uri.getHost().equals(ia.getHostAddress())) {
 134             return true;
 135         }
 136 
 137         return false;
 138     }
 139 
 140     private URI toURI(String endpoint) throws IllegalArgumentException {
 141         if (!endpoint.contains("://")) {
 142             ClientConfiguration conf = this.serviceClient.getClientConfiguration();
 143             endpoint = conf.getProtocol().toString() + "://" + endpoint;
 144         }
 145 
 146         try {
 147             return new URI(endpoint);
 148         } catch (URISyntaxException e) {
 149             throw new IllegalArgumentException(e);
 150         }
 151     }
 152 
 153     private void initOperations() {
 154         this.bucketOperation = new OSSBucketOperation(this.serviceClient, this.credsProvider);
 155         this.objectOperation = new OSSObjectOperation(this.serviceClient, this.credsProvider);
 156         this.multipartOperation = new OSSMultipartOperation(this.serviceClient, this.credsProvider);
 157         this.corsOperation = new CORSOperation(this.serviceClient, this.credsProvider);
 158         this.uploadOperation = new OSSUploadOperation(this.multipartOperation);
 159         this.downloadOperation = new OSSDownloadOperation(objectOperation);
 160         this.liveChannelOperation = new LiveChannelOperation(this.serviceClient, this.credsProvider);
 161     }
 162 
 163     @Override
 164     public void switchCredentials(Credentials creds) {
 165         if (creds == null) {
 166             throw new IllegalArgumentException("creds should not be null.");
 167         }
 168 
 169         this.credsProvider.setCredentials(creds);
 170     }
 171 
 172     @Override
 173     public void switchSignatureVersion(SignVersion signatureVersion) {
 174         if (signatureVersion == null) {
 175             throw new IllegalArgumentException("signatureVersion should not be null.");
 176         }
 177 
 178         this.getClientConfiguration().setSignatureVersion(signatureVersion);
 179     }
 180 
 181     public CredentialsProvider getCredentialsProvider() {
 182         return this.credsProvider;
 183     }
 184 
 185     public ClientConfiguration getClientConfiguration() {
 186         return serviceClient.getClientConfiguration();
 187     }
 188 
 189     @Override
 190     public Bucket createBucket(String bucketName) throws OSSException, ClientException {
 191         return this.createBucket(new CreateBucketRequest(bucketName));
 192     }
 193 
 194     @Override
 195     public Bucket createBucket(CreateBucketRequest createBucketRequest) throws OSSException, ClientException {
 196         return bucketOperation.createBucket(createBucketRequest);
 197     }
 198 
 199     @Override
 200     public void deleteBucket(String bucketName) throws OSSException, ClientException {
 201         this.deleteBucket(new GenericRequest(bucketName));
 202     }
 203 
 204     @Override
 205     public void deleteBucket(GenericRequest genericRequest) throws OSSException, ClientException {
 206         bucketOperation.deleteBucket(genericRequest);
 207     }
 208 
 209     @Override
 210     public List listBuckets() throws OSSException, ClientException {
 211         return bucketOperation.listBuckets();
 212     }
 213 
 214     @Override
 215     public BucketList listBuckets(ListBucketsRequest listBucketsRequest) throws OSSException, ClientException {
 216         return bucketOperation.listBuckets(listBucketsRequest);
 217     }
 218 
 219     @Override
 220     public BucketList listBuckets(String prefix, String marker, Integer maxKeys) throws OSSException, ClientException {
 221         return bucketOperation.listBuckets(new ListBucketsRequest(prefix, marker, maxKeys));
 222     }
 223 
 224     @Override
 225     public void setBucketAcl(String bucketName, CannedAccessControlList cannedACL)
 226             throws OSSException, ClientException {
 227         this.setBucketAcl(new SetBucketAclRequest(bucketName, cannedACL));
 228     }
 229 
 230     @Override
 231     public void setBucketAcl(SetBucketAclRequest setBucketAclRequest) throws OSSException, ClientException {
 232         bucketOperation.setBucketAcl(setBucketAclRequest);
 233     }
 234 
 235     @Override
 236     public AccessControlList getBucketAcl(String bucketName) throws OSSException, ClientException {
 237         return this.getBucketAcl(new GenericRequest(bucketName));
 238     }
 239 
 240     @Override
 241     public AccessControlList getBucketAcl(GenericRequest genericRequest) throws OSSException, ClientException {
 242         return bucketOperation.getBucketAcl(genericRequest);
 243     }
 244 
 245     @Override
 246     public BucketMetadata getBucketMetadata(String bucketName) throws OSSException, ClientException {
 247         return this.getBucketMetadata(new GenericRequest(bucketName));
 248     }
 249 
 250     @Override
 251     public BucketMetadata getBucketMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
 252         return bucketOperation.getBucketMetadata(genericRequest);
 253     }
 254 
 255     @Override
 256     public void setBucketReferer(String bucketName, BucketReferer referer) throws OSSException, ClientException {
 257         this.setBucketReferer(new SetBucketRefererRequest(bucketName, referer));
 258     }
 259 
 260     @Override
 261     public void setBucketReferer(SetBucketRefererRequest setBucketRefererRequest) throws OSSException, ClientException {
 262         bucketOperation.setBucketReferer(setBucketRefererRequest);
 263     }
 264 
 265     @Override
 266     public BucketReferer getBucketReferer(String bucketName) throws OSSException, ClientException {
 267         return this.getBucketReferer(new GenericRequest(bucketName));
 268     }
 269 
 270     @Override
 271     public BucketReferer getBucketReferer(GenericRequest genericRequest) throws OSSException, ClientException {
 272         return bucketOperation.getBucketReferer(genericRequest);
 273     }
 274 
 275     @Override
 276     public String getBucketLocation(String bucketName) throws OSSException, ClientException {
 277         return this.getBucketLocation(new GenericRequest(bucketName));
 278     }
 279 
 280     @Override
 281     public String getBucketLocation(GenericRequest genericRequest) throws OSSException, ClientException {
 282         return bucketOperation.getBucketLocation(genericRequest);
 283     }
 284 
 285     @Override
 286     public boolean doesBucketExist(String bucketName) throws OSSException, ClientException {
 287         return this.doesBucketExist(new GenericRequest(bucketName));
 288     }
 289 
 290     @Override
 291     public boolean doesBucketExist(GenericRequest genericRequest) throws OSSException, ClientException {
 292         return bucketOperation.doesBucketExists(genericRequest);
 293     }
 294 
 295 
 296     @Deprecated
 297     public boolean isBucketExist(String bucketName) throws OSSException, ClientException {
 298         return this.doesBucketExist(bucketName);
 299     }
 300 
 301     @Override
 302     public ObjectListing listObjects(String bucketName) throws OSSException, ClientException {
 303         return listObjects(new ListObjectsRequest(bucketName, null, null, null, null));
 304     }
 305 
 306     @Override
 307     public ObjectListing listObjects(String bucketName, String prefix) throws OSSException, ClientException {
 308         return listObjects(new ListObjectsRequest(bucketName, prefix, null, null, null));
 309     }
 310 
 311     @Override
 312     public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws OSSException, ClientException {
 313         return bucketOperation.listObjects(listObjectsRequest);
 314     }
 315 
 316     @Override
 317     public VersionListing listVersions(String bucketName, String prefix) throws OSSException, ClientException {
 318         return listVersions(new ListVersionsRequest(bucketName, prefix, null, null, null, null));
 319     }
 320 
 321     @Override
 322     public VersionListing listVersions(String bucketName, String prefix, String keyMarker, String versionIdMarker,
 323                                        String delimiter, Integer maxResults) throws OSSException, ClientException {
 324         ListVersionsRequest request = new ListVersionsRequest()
 325                 .withBucketName(bucketName)
 326                 .withPrefix(prefix)
 327                 .withDelimiter(delimiter)
 328                 .withKeyMarker(keyMarker)
 329                 .withVersionIdMarker(versionIdMarker)
 330                 .withMaxResults(maxResults);
 331         return listVersions(request);
 332     }
 333 
 334     @Override
 335     public VersionListing listVersions(ListVersionsRequest listVersionsRequest) throws OSSException, ClientException {
 336         return bucketOperation.listVersions(listVersionsRequest);
 337     }
 338 
 339     @Override
 340     public PutObjectResult putObject(String bucketName, String key, InputStream input)
 341             throws OSSException, ClientException {
 342         return putObject(bucketName, key, input, null);
 343     }
 344 
 345     @Override
 346     public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata)
 347             throws OSSException, ClientException {
 348         return putObject(new PutObjectRequest(bucketName, key, input, metadata));
 349     }
 350 
 351     @Override
 352     public PutObjectResult putObject(String bucketName, String key, File file, ObjectMetadata metadata)
 353             throws OSSException, ClientException {
 354         return putObject(new PutObjectRequest(bucketName, key, file, metadata));
 355     }
 356 
 357     @Override
 358     public PutObjectResult putObject(String bucketName, String key, File file) throws OSSException, ClientException {
 359         return putObject(bucketName, key, file, null);
 360     }
 361 
 362     @Override
 363     public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws OSSException, ClientException {
 364         return objectOperation.putObject(putObjectRequest);
 365     }
 366 
 367     @Override
 368     public PutObjectResult putObject(URL signedUrl, String filePath, Map requestHeaders)
 369             throws OSSException, ClientException {
 370         return putObject(signedUrl, filePath, requestHeaders, false);
 371     }
 372 
 373     @Override
 374     public PutObjectResult putObject(URL signedUrl, String filePath, Map requestHeaders,
 375                                      boolean useChunkEncoding) throws OSSException, ClientException {
 376 
 377         FileInputStream requestContent = null;
 378         try {
 379             File toUpload = new File(filePath);
 380             if (!checkFile(toUpload)) {
 381                 throw new IllegalArgumentException("Illegal file path: " + filePath);
 382             }
 383             long fileSize = toUpload.length();
 384             requestContent = new FileInputStream(toUpload);
 385 
 386             return putObject(signedUrl, requestContent, fileSize, requestHeaders, useChunkEncoding);
 387         } catch (FileNotFoundException e) {
 388             throw new ClientException(e);
 389         } finally {
 390             if (requestContent != null) {
 391                 try {
 392                     requestContent.close();
 393                 } catch (IOException e) {
 394                 }
 395             }
 396         }
 397     }
 398 
 399     @Override
 400     public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength,
 401                                      Map requestHeaders) throws OSSException, ClientException {
 402         return putObject(signedUrl, requestContent, contentLength, requestHeaders, false);
 403     }
 404 
 405     @Override
 406     public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength,
 407                                      Map requestHeaders, boolean useChunkEncoding) throws OSSException, ClientException {
 408         return objectOperation.putObject(signedUrl, requestContent, contentLength, requestHeaders, useChunkEncoding);
 409     }
 410 
 411     @Override
 412     public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName,
 413                                        String destinationKey) throws OSSException, ClientException {
 414         return copyObject(new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey));
 415     }
 416 
 417     @Override
 418     public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest) throws OSSException, ClientException {
 419         return objectOperation.copyObject(copyObjectRequest);
 420     }
 421 
 422     @Override
 423     public OSSObject getObject(String bucketName, String key) throws OSSException, ClientException {
 424         return this.getObject(new GetObjectRequest(bucketName, key));
 425     }
 426 
 427     @Override
 428     public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File file) throws OSSException, ClientException {
 429         return objectOperation.getObject(getObjectRequest, file);
 430     }
 431 
 432     @Override
 433     public OSSObject getObject(GetObjectRequest getObjectRequest) throws OSSException, ClientException {
 434         return objectOperation.getObject(getObjectRequest);
 435     }
 436 
 437     @Override
 438     public OSSObject getObject(URL signedUrl, Map requestHeaders) throws OSSException, ClientException {
 439         GetObjectRequest getObjectRequest = new GetObjectRequest(signedUrl, requestHeaders);
 440         return objectOperation.getObject(getObjectRequest);
 441     }
 442 
 443     @Override
 444     public OSSObject selectObject(SelectObjectRequest selectObjectRequest) throws OSSException, ClientException {
 445         return objectOperation.selectObject(selectObjectRequest);
 446     }
 447 
 448     @Override
 449     public SimplifiedObjectMeta getSimplifiedObjectMeta(String bucketName, String key)
 450             throws OSSException, ClientException {
 451         return this.getSimplifiedObjectMeta(new GenericRequest(bucketName, key));
 452     }
 453 
 454     @Override
 455     public SimplifiedObjectMeta getSimplifiedObjectMeta(GenericRequest genericRequest)
 456             throws OSSException, ClientException {
 457         return this.objectOperation.getSimplifiedObjectMeta(genericRequest);
 458     }
 459 
 460     @Override
 461     public ObjectMetadata getObjectMetadata(String bucketName, String key) throws OSSException, ClientException {
 462         return this.getObjectMetadata(new GenericRequest(bucketName, key));
 463     }
 464 
 465     @Override
 466     public SelectObjectMetadata createSelectObjectMetadata(CreateSelectObjectMetadataRequest createSelectObjectMetadataRequest) throws OSSException, ClientException {
 467         return objectOperation.createSelectObjectMetadata(createSelectObjectMetadataRequest);
 468     }
 469 
 470     @Override
 471     public ObjectMetadata getObjectMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
 472         return objectOperation.getObjectMetadata(genericRequest);
 473     }
 474 
 475     @Override
 476     public ObjectMetadata headObject(String bucketName, String key) throws OSSException, ClientException {
 477         return this.headObject(new HeadObjectRequest(bucketName, key));
 478     }
 479 
 480     @Override
 481     public ObjectMetadata headObject(HeadObjectRequest headObjectRequest) throws OSSException, ClientException {
 482         return objectOperation.headObject(headObjectRequest);
 483     }
 484 
 485     @Override
 486     public AppendObjectResult appendObject(AppendObjectRequest appendObjectRequest)
 487             throws OSSException, ClientException {
 488         return objectOperation.appendObject(appendObjectRequest);
 489     }
 490 
 491     @Override
 492     public void deleteObject(String bucketName, String key) throws OSSException, ClientException {
 493         this.deleteObject(new GenericRequest(bucketName, key));
 494     }
 495 
 496     @Override
 497     public void deleteObject(GenericRequest genericRequest) throws OSSException, ClientException {
 498         objectOperation.deleteObject(genericRequest);
 499     }
 500 
 501     @Override
 502     public void deleteVersion(String bucketName, String key, String versionId) throws OSSException, ClientException {
 503         deleteVersion(new DeleteVersionRequest(bucketName, key, versionId));
 504     }
 505 
 506     @Override
 507     public void deleteVersion(DeleteVersionRequest deleteVersionRequest) throws OSSException, ClientException {
 508         objectOperation.deleteVersion(deleteVersionRequest);
 509     }
 510 
 511     @Override
 512     public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest)
 513             throws OSSException, ClientException {
 514         return objectOperation.deleteObjects(deleteObjectsRequest);
 515     }
 516 
 517     @Override
 518     public DeleteVersionsResult deleteVersions(DeleteVersionsRequest deleteVersionsRequest)
 519             throws OSSException, ClientException {
 520         return objectOperation.deleteVersions(deleteVersionsRequest);
 521     }
 522 
 523     @Override
 524     public boolean doesObjectExist(String bucketName, String key) throws OSSException, ClientException {
 525         return doesObjectExist(new GenericRequest(bucketName, key));
 526     }
 527 
 528     @Override
 529     public boolean doesObjectExist(String bucketName, String key, boolean isOnlyInOSS) {
 530         if (isOnlyInOSS) {
 531             return doesObjectExist(bucketName, key);
 532         } else {
 533             return objectOperation.doesObjectExistWithRedirect(new GenericRequest(bucketName, key));
 534         }
 535     }
 536 
 537     @Deprecated
 538     @Override
 539     public boolean doesObjectExist(HeadObjectRequest headObjectRequest) throws OSSException, ClientException {
 540         return doesObjectExist(new GenericRequest(headObjectRequest.getBucketName(), headObjectRequest.getKey()));
 541     }
 542 
 543     @Override
 544     public boolean doesObjectExist(GenericRequest genericRequest) throws OSSException, ClientException {
 545         return objectOperation.doesObjectExist(genericRequest);
 546     }
 547 
 548     @Override
 549     public boolean doesObjectExist(GenericRequest genericRequest, boolean isOnlyInOSS) throws OSSException, ClientException {
 550         if (isOnlyInOSS) {
 551             return objectOperation.doesObjectExist(genericRequest);
 552         } else {
 553             return objectOperation.doesObjectExistWithRedirect(genericRequest);
 554         }
 555     }
 556 
 557     @Override
 558     public void setObjectAcl(String bucketName, String key, CannedAccessControlList cannedACL)
 559             throws OSSException, ClientException {
 560         this.setObjectAcl(new SetObjectAclRequest(bucketName, key, cannedACL));
 561     }
 562 
 563     @Override
 564     public void setObjectAcl(SetObjectAclRequest setObjectAclRequest) throws OSSException, ClientException {
 565         objectOperation.setObjectAcl(setObjectAclRequest);
 566     }
 567 
 568     @Override
 569     public ObjectAcl getObjectAcl(String bucketName, String key) throws OSSException, ClientException {
 570         return this.getObjectAcl(new GenericRequest(bucketName, key));
 571     }
 572 
 573     @Override
 574     public ObjectAcl getObjectAcl(GenericRequest genericRequest) throws OSSException, ClientException {
 575         return objectOperation.getObjectAcl(genericRequest);
 576     }
 577 
 578     @Override
 579     public RestoreObjectResult restoreObject(String bucketName, String key) throws OSSException, ClientException {
 580         return this.restoreObject(new GenericRequest(bucketName, key));
 581     }
 582 
 583     @Override
 584     public RestoreObjectResult restoreObject(GenericRequest genericRequest) throws OSSException, ClientException {
 585         return objectOperation.restoreObject(genericRequest);
 586     }
 587 
 588     @Override
 589     public void setObjectTagging(String bucketName, String key, Map tags)
 590             throws OSSException, ClientException {
 591         this.setObjectTagging(new SetObjectTaggingRequest(bucketName, key, tags));
 592     }
 593 
 594     @Override
 595     public void setObjectTagging(String bucketName, String key, TagSet tagSet) throws OSSException, ClientException {
 596         this.setObjectTagging(new SetObjectTaggingRequest(bucketName, key, tagSet));
 597     }
 598 
 599     @Override
 600     public void setObjectTagging(SetObjectTaggingRequest setObjectTaggingRequest) throws OSSException, ClientException {
 601         objectOperation.setObjectTagging(setObjectTaggingRequest);
 602     }
 603 
 604     @Override
 605     public TagSet getObjectTagging(String bucketName, String key) throws OSSException, ClientException {
 606         return this.getObjectTagging(new GenericRequest(bucketName, key));
 607     }
 608 
 609     @Override
 610     public TagSet getObjectTagging(GenericRequest genericRequest) throws OSSException, ClientException {
 611         return objectOperation.getObjectTagging(genericRequest);
 612     }
 613 
 614     @Override
 615     public void deleteObjectTagging(String bucketName, String key) throws OSSException, ClientException {
 616         this.deleteObjectTagging(new GenericRequest(bucketName, key));
 617     }
 618 
 619     @Override
 620     public void deleteObjectTagging(GenericRequest genericRequest) throws OSSException, ClientException {
 621         objectOperation.deleteObjectTagging(genericRequest);
 622     }
 623 
 624     @Override
 625     public URL generatePresignedUrl(String bucketName, String key, Date expiration) throws ClientException {
 626         return generatePresignedUrl(bucketName, key, expiration, HttpMethod.GET);
 627     }
 628 
 629     @Override
 630     public URL generatePresignedUrl(String bucketName, String key, Date expiration, HttpMethod method)
 631             throws ClientException {
 632         GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key);
 633         request.setExpiration(expiration);
 634         request.setMethod(method);
 635 
 636         return generatePresignedUrl(request);
 637     }
 638 
 639     @Override
 640     public URL generatePresignedUrl(GeneratePresignedUrlRequest request) throws ClientException {
 641 
 642         assertParameterNotNull(request, "request");
 643 
 644         if (request.getBucketName() == null) {
 645             throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetBucketName"));
 646         }
 647         ensureBucketNameValid(request.getBucketName());
 648 
 649         if (request.getExpiration() == null) {
 650             throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetExpiration"));
 651         }
 652         String url;
 653 
 654         if (serviceClient.getClientConfiguration().getSignatureVersion() != null && serviceClient.getClientConfiguration().getSignatureVersion() == SignVersion.V2) {
 655             url = SignV2Utils.buildSignedURL(request, credsProvider.getCredentials(), serviceClient.getClientConfiguration(), endpoint);
 656         } else {
 657             url = SignUtils.buildSignedURL(request, credsProvider.getCredentials(), serviceClient.getClientConfiguration(), endpoint);
 658         }
 659 
 660         try {
 661             return new URL(url);
 662         } catch (MalformedURLException e) {
 663             throw new ClientException(e);
 664         }
 665     }
 666 
 667     @Override
 668     public void abortMultipartUpload(AbortMultipartUploadRequest request) throws OSSException, ClientException {
 669         multipartOperation.abortMultipartUpload(request);
 670     }
 671 
 672     @Override
 673     public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request)
 674             throws OSSException, ClientException {
 675         return multipartOperation.completeMultipartUpload(request);
 676     }
 677 
 678     @Override
 679     public InitiateMultipartUploadResult initiateMultipartUpload(InitiateMultipartUploadRequest request)
 680             throws OSSException, ClientException {
 681         return multipartOperation.initiateMultipartUpload(request);
 682     }
 683 
 684     @Override
 685     public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest request)
 686             throws OSSException, ClientException {
 687         return multipartOperation.listMultipartUploads(request);
 688     }
 689 
 690     @Override
 691     public PartListing listParts(ListPartsRequest request) throws OSSException, ClientException {
 692         return multipartOperation.listParts(request);
 693     }
 694 
 695     @Override
 696     public UploadPartResult uploadPart(UploadPartRequest request) throws OSSException, ClientException {
 697         return multipartOperation.uploadPart(request);
 698     }
 699 
 700     @Override
 701     public UploadPartCopyResult uploadPartCopy(UploadPartCopyRequest request) throws OSSException, ClientException {
 702         return multipartOperation.uploadPartCopy(request);
 703     }
 704 
 705     @Override
 706     public void setBucketCORS(SetBucketCORSRequest request) throws OSSException, ClientException {
 707         corsOperation.setBucketCORS(request);
 708     }
 709 
 710     @Override
 711     public List getBucketCORSRules(String bucketName) throws OSSException, ClientException {
 712         return this.getBucketCORSRules(new GenericRequest(bucketName));
 713     }
 714 
 715     @Override
 716     public List getBucketCORSRules(GenericRequest genericRequest) throws OSSException, ClientException {
 717         return corsOperation.getBucketCORSRules(genericRequest);
 718     }
 719 
 720     @Override
 721     public void deleteBucketCORSRules(String bucketName) throws OSSException, ClientException {
 722         this.deleteBucketCORSRules(new GenericRequest(bucketName));
 723     }
 724 
 725     @Override
 726     public void deleteBucketCORSRules(GenericRequest genericRequest) throws OSSException, ClientException {
 727         corsOperation.deleteBucketCORS(genericRequest);
 728     }
 729 
 730     @Override
 731     public ResponseMessage optionsObject(OptionsRequest request) throws OSSException, ClientException {
 732         return corsOperation.optionsObject(request);
 733     }
 734 
 735     @Override
 736     public void setBucketLogging(SetBucketLoggingRequest request) throws OSSException, ClientException {
 737         bucketOperation.setBucketLogging(request);
 738     }
 739 
 740     @Override
 741     public BucketLoggingResult getBucketLogging(String bucketName) throws OSSException, ClientException {
 742         return this.getBucketLogging(new GenericRequest(bucketName));
 743     }
 744 
 745     @Override
 746     public BucketLoggingResult getBucketLogging(GenericRequest genericRequest) throws OSSException, ClientException {
 747         return bucketOperation.getBucketLogging(genericRequest);
 748     }
 749 
 750     @Override
 751     public void deleteBucketLogging(String bucketName) throws OSSException, ClientException {
 752         this.deleteBucketLogging(new GenericRequest(bucketName));
 753     }
 754 
 755     @Override
 756     public void deleteBucketLogging(GenericRequest genericRequest) throws OSSException, ClientException {
 757         bucketOperation.deleteBucketLogging(genericRequest);
 758     }
 759 
 760     @Override
 761     public void putBucketImage(PutBucketImageRequest request) throws OSSException, ClientException {
 762         bucketOperation.putBucketImage(request);
 763     }
 764 
 765     @Override
 766     public GetBucketImageResult getBucketImage(String bucketName) throws OSSException, ClientException {
 767         return bucketOperation.getBucketImage(bucketName, new GenericRequest());
 768     }
 769 
 770     @Override
 771     public GetBucketImageResult getBucketImage(String bucketName, GenericRequest genericRequest)
 772             throws OSSException, ClientException {
 773         return bucketOperation.getBucketImage(bucketName, genericRequest);
 774     }
 775 
 776     @Override
 777     public void deleteBucketImage(String bucketName) throws OSSException, ClientException {
 778         bucketOperation.deleteBucketImage(bucketName, new GenericRequest());
 779     }
 780 
 781     @Override
 782     public void deleteBucketImage(String bucketName, GenericRequest genericRequest)
 783             throws OSSException, ClientException {
 784         bucketOperation.deleteBucketImage(bucketName, genericRequest);
 785     }
 786 
 787     @Override
 788     public void putImageStyle(PutImageStyleRequest putImageStyleRequest) throws OSSException, ClientException {
 789         bucketOperation.putImageStyle(putImageStyleRequest);
 790     }
 791 
 792     @Override
 793     public void deleteImageStyle(String bucketName, String styleName) throws OSSException, ClientException {
 794         bucketOperation.deleteImageStyle(bucketName, styleName, new GenericRequest());
 795     }
 796 
 797     @Override
 798     public void deleteImageStyle(String bucketName, String styleName, GenericRequest genericRequest)
 799             throws OSSException, ClientException {
 800         bucketOperation.deleteImageStyle(bucketName, styleName, genericRequest);
 801     }
 802 
 803     @Override
 804     public GetImageStyleResult getImageStyle(String bucketName, String styleName) throws OSSException, ClientException {
 805         return bucketOperation.getImageStyle(bucketName, styleName, new GenericRequest());
 806     }
 807 
 808     @Override
 809     public GetImageStyleResult getImageStyle(String bucketName, String styleName, GenericRequest genericRequest)
 810             throws OSSException, ClientException {
 811         return bucketOperation.getImageStyle(bucketName, styleName, genericRequest);
 812     }
 813 
 814     @Override
 815     public List