use of com.aliyun.oss.model.OSSSymlink in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseSymbolicLink.
/**
* Unmarshall symlink link from response headers.
*/
public static OSSSymlink parseSymbolicLink(ResponseMessage response) throws ResponseParseException {
try {
OSSSymlink smyLink = null;
String targetObject = response.getHeaders().get(OSSHeaders.OSS_HEADER_SYMLINK_TARGET);
if (targetObject != null) {
targetObject = HttpUtil.urlDecode(targetObject, "UTF-8");
smyLink = new OSSSymlink(null, targetObject);
}
smyLink.setMetadata(parseObjectMetadata(response.getHeaders()));
return smyLink;
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.model.OSSSymlink in project aliyun-oss-java-sdk by aliyun.
the class SymlinkTest method testNormalCreateSymlink.
@Test
public void testNormalCreateSymlink() {
final String symLink = "normal-create-sym-link";
try {
ossClient.putObject(bucketName, targetObject, new ByteArrayInputStream(content.getBytes()));
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("text/plain");
metadata.addUserMetadata("property", "property-value");
CreateSymlinkRequest createSymlinkRequest = new CreateSymlinkRequest(bucketName, symLink, targetObject);
createSymlinkRequest.setMetadata(metadata);
ossClient.createSymlink(createSymlinkRequest);
OSSSymlink symbolicLink = ossClient.getSymlink(bucketName, symLink);
Assert.assertEquals(symbolicLink.getSymlink(), symLink);
Assert.assertEquals(symbolicLink.getTarget(), targetObject);
Assert.assertEquals(symbolicLink.getMetadata().getContentType(), "text/plain");
Assert.assertEquals(symbolicLink.getMetadata().getUserMetadata().get("property"), "property-value");
Assert.assertEquals(symbolicLink.getRequestId().length(), REQUEST_ID_LEN);
ossClient.deleteObject(bucketName, symLink);
ossClient.deleteObject(bucketName, targetObject);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.OSSSymlink in project aliyun-oss-java-sdk by aliyun.
the class SymlinkTest method testUnnormalCreateSymlink.
@Test
public void testUnnormalCreateSymlink() {
final String symLink = "unnormal-create-sym-link";
try {
ossClient.createSymlink(bucketName, symLink, symLink);
OSSSymlink symbolicLink = ossClient.getSymlink(bucketName, symLink);
Assert.assertEquals(symbolicLink.getSymlink(), symLink);
Assert.assertEquals(symbolicLink.getTarget(), symLink);
try {
ossClient.getObject(bucketName, symLink);
} catch (OSSException e) {
Assert.assertEquals("InvalidTargetType", e.getErrorCode());
}
ossClient.deleteObject(bucketName, symLink);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.OSSSymlink in project aliyun-oss-java-sdk by aliyun.
the class SymlinkTest method testUnnormalgetSymlink.
@Test
public void testUnnormalgetSymlink() {
final String symLink = "unnormal-get-sym-link";
try {
OSSSymlink symbolicLink = ossClient.getSymlink(bucketName, symLink);
Assert.assertNull(symbolicLink.getSymlink());
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.NO_SUCH_KEY, e.getErrorCode());
}
try {
ossClient.createSymlink(bucketName, symLink, targetObject);
ossClient.getObject(bucketName, symLink);
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.NO_SUCH_SYM_LINK_TARGET, e.getErrorCode());
}
}
use of com.aliyun.oss.model.OSSSymlink in project aliyun-oss-java-sdk by aliyun.
the class SymlinkTest method testNormalgetSymlinkContent.
@Test
public void testNormalgetSymlinkContent() {
final String symLink = "normal-create-sym-link-content";
try {
ossClient.putObject(bucketName, targetObject, new ByteArrayInputStream(content.getBytes()));
ossClient.createSymlink(bucketName, symLink, targetObject);
OSSSymlink symbolicLink = ossClient.getSymlink(bucketName, symLink);
Assert.assertEquals(symbolicLink.getSymlink(), symLink);
Assert.assertEquals(symbolicLink.getTarget(), targetObject);
Assert.assertEquals(symbolicLink.getRequestId().length(), REQUEST_ID_LEN);
// content
OSSObject ossObject = ossClient.getObject(bucketName, symLink);
StringBuilder contentBuilder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(ossObject.getObjectContent()));
while (true) {
String line = reader.readLine();
if (line == null)
break;
contentBuilder.append(line);
}
reader.close();
Assert.assertEquals(contentBuilder.toString(), content);
// size
ObjectMetadata meta = ossClient.getObjectMetadata(bucketName, symLink);
Assert.assertEquals(meta.getContentLength(), content.length());
ossClient.deleteObject(bucketName, symLink);
ossClient.deleteObject(bucketName, targetObject);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations