()
| 432 | } |
| 433 | |
| 434 | public AmazonS3 S3Conn() { |
| 435 | |
| 436 | AmazonS3 s3Client = null; |
| 437 | try { |
| 438 | |
| 439 | AWSCredentials cred = new BasicAWSCredentials(accessKeyId, accessKeySecret); |
| 440 | ClientConfiguration clientConfig = new ClientConfiguration(); |
| 441 | if (endpoint.startsWith("https://")) { |
| 442 | clientConfig.setProtocol(Protocol.HTTPS); |
| 443 | } else { |
| 444 | clientConfig.setProtocol(Protocol.HTTP); |
| 445 | |
| 446 | } |
| 447 | // s3Client = AmazonS3ClientBuilder.standard() |
| 448 | // .withCredentials( new AWSStaticCredentialsProvider( |
| 449 | // cred ) ).withClientConfiguration( clientConfig ).withRegion( |
| 450 | // endpoint.substring( endpoint.indexOf( "s3." ) + 3, |
| 451 | // endpoint.indexOf( ".amazonaws" ) ) ).build(); |
| 452 | |
| 453 | |
| 454 | //生成云存储api client |
| 455 | s3Client = new AmazonS3Client(cred); |
| 456 | |
| 457 | //配置云存储服务地址 |
| 458 | s3Client.setEndpoint(endpoint); |
| 459 | |
| 460 | //设置客户端生成的http请求hos格式,目前只支持path type的格式,不支持bucket域名的格式 |
| 461 | S3ClientOptions s3ClientOptions = new S3ClientOptions(); |
| 462 | s3ClientOptions.setPathStyleAccess(true); |
| 463 | s3Client.setS3ClientOptions(s3ClientOptions); |
| 464 | if (s3Client != null) { |
| 465 | setCommandstate(true); |
| 466 | setOSSClient(s3Client); |
| 467 | } else { |
| 468 | System.out.println("Object-Based Storage Connect Error,may be wrong ak & sk?"); |
| 469 | |
| 470 | } |
| 471 | } catch (Exception e) { |
| 472 | e.printStackTrace(); |
| 473 | System.out.println("Object-Based Storage Connect Error:\n" + e.getLocalizedMessage()); |
| 474 | return null; |
| 475 | } |
| 476 | |
| 477 | return s3Client; |
| 478 | |
| 479 | } |
| 480 | |
| 481 | |
| 482 | /** |
no test coverage detected