-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0453c5
commit 9c39c6e
Showing
9 changed files
with
318 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/com/aliyun/oss/model/WriteGetObjectResponseRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.aliyun.oss.model; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
|
||
public class WriteGetObjectResponseRequest extends WebServiceRequest{ | ||
|
||
private String route; | ||
private String token; | ||
private int status; | ||
private File file; | ||
private InputStream inputStream; | ||
private ObjectMetadata metadata; | ||
|
||
public WriteGetObjectResponseRequest(String route, String token, int status, File file) { | ||
this(route, token, status, file, null); | ||
} | ||
|
||
public WriteGetObjectResponseRequest(String route, String token, int status, File file, ObjectMetadata metadata) { | ||
this.route = route; | ||
this.token = token; | ||
this.status = status; | ||
this.file = file; | ||
this.metadata = metadata; | ||
} | ||
|
||
public WriteGetObjectResponseRequest(String route, String token, int status, InputStream input) { | ||
this(route, token, status, input, null); | ||
} | ||
|
||
public WriteGetObjectResponseRequest(String route, String token, int status, InputStream input, ObjectMetadata metadata) { | ||
this.route = route; | ||
this.token = token; | ||
this.status = status; | ||
this.inputStream = input; | ||
this.metadata = metadata; | ||
} | ||
|
||
public String getRoute() { | ||
return route; | ||
} | ||
|
||
public void setRoute(String route) { | ||
this.route = route; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withRoute(String route) { | ||
this.route = route; | ||
return this; | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withToken(String token) { | ||
this.token = token; | ||
return this; | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(int status) { | ||
this.status = status; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withStatus(int status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public void setFile(File file) { | ||
this.file = file; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withFile(File file) { | ||
this.file = file; | ||
return this; | ||
} | ||
|
||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
public void setInputStream(InputStream inputStream) { | ||
this.inputStream = inputStream; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withInputStream(InputStream inputStream) { | ||
this.inputStream = inputStream; | ||
return this; | ||
} | ||
|
||
public ObjectMetadata getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(ObjectMetadata metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
public WriteGetObjectResponseRequest withMetadata(ObjectMetadata metadata) { | ||
this.metadata = metadata; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package samples; | ||
|
||
import com.aliyun.oss.model.*; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
|
||
public class WriteGetObjectResponseSample { | ||
private static String endpoint = "*** Provide OSS endpoint ***"; | ||
private static String accessKeyId = "*** Provide your AccessKeyId ***"; | ||
private static String accessKeySecret = "*** Provide your AccessKeySecret ***"; | ||
private static String bucketName = "*** Provide bucket name ***"; | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
|
||
/* | ||
* Constructs a client instance with your account for accessing OSS | ||
*/ | ||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); | ||
|
||
try { | ||
final int instreamLength = 128 * 1024; | ||
InputStream instream = null; | ||
String route = "test-ap-process-name-128364***6515-opap.oss-cn-beijing-internal.oss-object-process.aliyuncs.com"; | ||
String token = "OSSV1#UMoA43+Bi9b6Q1Lu6UjhLXnmq4I/wIFac3uZfBkgJtg2xtHkZJ4bZglDWyOgWRlGTrA8y/i6D9eH8PmAiq2NL2R/MD/UX6zvRhT8WMHUewgc9QWPs9LPHiZytkUZnGa39mnv/73cyPWTuxgxyk4dNhlzEE6U7PdzmCCu8gIrjuYLPrA9psRn0ZC8J2/DCZGVx0BE7AmIJTcNtLKTSjxsJyTts******"; | ||
int status = 200; | ||
|
||
instream = genFixedLengthInputStream(instreamLength); | ||
WriteGetObjectResponseRequest writeGetObjectResponseRequest = new WriteGetObjectResponseRequest(route, token, status, instream); | ||
// add CommonHeader | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Accept-Ranges", "*** Provide your Accept Ranges ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Cache-Control", "*** Provide your Cache Control ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Content-Disposition", "*** Provide your Content Disposition ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Content-Encoding", "*** Provide your Content Encoding ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Content-Range", "*** Provide your Content Range ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Content-Type", "*** Provide your Content Type ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-ETag", "*** Provide your ETag ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Expires", "*** Provide your Expires ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Last-Modified", "*** Provide your Last Modified ***"); | ||
// writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-Location", "*** Provide your Location ***"); | ||
|
||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentLength(instreamLength); | ||
writeGetObjectResponseRequest.setMetadata(metadata); | ||
|
||
ossClient.writeGetObjectResponse(writeGetObjectResponseRequest); | ||
} catch (OSSException oe) { | ||
System.out.println("Caught an OSSException, which means your request made it to OSS, " | ||
+ "but was rejected with an error response for some reason."); | ||
System.out.println("Error Message: " + oe.getMessage()); | ||
System.out.println("Error Code: " + oe.getErrorCode()); | ||
System.out.println("Request ID: " + oe.getRequestId()); | ||
System.out.println("Host ID: " + oe.getHostId()); | ||
} catch (ClientException ce) { | ||
System.out.println("Caught an ClientException, which means the client encountered " | ||
+ "a serious internal problem while trying to communicate with OSS, " | ||
+ "such as not being able to access the network."); | ||
System.out.println("Error Message: " + ce.getMessage()); | ||
} finally { | ||
/* | ||
* Do not forget to shut down the client finally to release all allocated resources. | ||
*/ | ||
ossClient.shutdown(); | ||
} | ||
} | ||
|
||
public static InputStream genFixedLengthInputStream(long fixedLength) { | ||
byte[] buf = new byte[(int) fixedLength]; | ||
for (int i = 0; i < buf.length; i++) | ||
buf[i] = 'a'; | ||
return new ByteArrayInputStream(buf); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/com/aliyun/oss/integrationtests/WriteGetObjectResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.aliyun.oss.integrationtests; | ||
|
||
import com.aliyun.oss.ClientException; | ||
import com.aliyun.oss.model.*; | ||
import junit.framework.Assert; | ||
import org.junit.Test; | ||
import java.io.InputStream; | ||
import static com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream; | ||
|
||
public class WriteGetObjectResponseTest extends TestBase{ | ||
|
||
@Test | ||
public void testWriteGetObjectResponse() { | ||
final int instreamLength = 128 * 1024; | ||
InputStream instream = null; | ||
String route = "test-ap-process-name-12836***16515-opap.oss-cn-beijing-internal.oss-object-process.aliyuncs.com"; | ||
String token = "OSSV1#UMoA43+Bi9b6Q1Lu6UjhLXnmq4I/wIFac3uZfBkgJtg2xtHkZJ4bZglDWyOgWRlGTrA8y/i6D9eH8PmAiq2NL2R/MD/UX6zvRhT8WMHUewgc9QWPs9LPHiZytkUZnGa39mnv/73cyPWTuxgxyk4dNhlzEE6U7PdzmCCu8gIrjuYLPrA9psRn0ZC8J2/DCZGVx0BE7AmIJTcNtLKTSjxsJyTts/******"; | ||
int status = 200; | ||
|
||
try { | ||
instream = genFixedLengthInputStream(instreamLength); | ||
WriteGetObjectResponseRequest writeGetObjectResponseRequest = new WriteGetObjectResponseRequest(route, token, status, instream); | ||
writeGetObjectResponseRequest.addHeader("x-oss-fwd-header-ETag", "D41D8CD98F00B204E9800998ECF8****"); | ||
ossClient.writeGetObjectResponse(writeGetObjectResponseRequest); | ||
} catch (ClientException e) { | ||
Assert.assertEquals(e.getErrorCode(), "UnknownHost"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |