Skip to content

Commit 67c52e4

Browse files
author
Lowell Vaughn
committed
Merge branch 'master' of github.com:rackspace/java-cloudfiles
2 parents 15d88b4 + 346eb0a commit 67c52e4

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

src/main/java/com/rackspacecloud/client/cloudfiles/FilesClient.java

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,136 @@ else if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
18901890
throw new FilesAuthorizationException("You must be logged in", null, null);
18911891
}
18921892
}
1893+
/**
1894+
* Create a manifest on the server, including metadata
1895+
*
1896+
* @param container The name of the container
1897+
* @param obj The File containing the file to copy over
1898+
* @param contentType The MIME type of the file
1899+
* @param name The name of the file on the server
1900+
* @param manifest Set manifest content here
1901+
* @param callback The object to which any callbacks will be sent (null if you don't want callbacks)
1902+
* @throws IOException There was an IO error doing network communication
1903+
* @throws HttpException There was an error with the http protocol
1904+
* @throws FilesException
1905+
*/
1906+
public boolean createManifestObject(String container, String contentType, String name, String manifest, IFilesTransferCallback callback) throws IOException, HttpException, FilesException
1907+
{
1908+
return createManifestObject(container, contentType, name, manifest, new HashMap<String, String>(), callback);
1909+
}
1910+
/**
1911+
* Create a manifest on the server, including metadata
1912+
*
1913+
* @param container The name of the container
1914+
* @param obj The File containing the file to copy over
1915+
* @param contentType The MIME type of the file
1916+
* @param name The name of the file on the server
1917+
* @param manifest Set manifest content here
1918+
* @param metadata A map with the metadata as key names and values as the metadata values
1919+
* @throws IOException There was an IO error doing network communication
1920+
* @throws HttpException There was an error with the http protocol
1921+
* @throws FilesException
1922+
*/
1923+
public boolean createManifestObject(String container, String contentType, String name, String manifest, Map<String,String> metadata) throws IOException, HttpException, FilesException
1924+
{
1925+
return createManifestObject(container, contentType, name, manifest, metadata, null);
1926+
}
1927+
/**
1928+
* Create a manifest on the server, including metadata
1929+
*
1930+
* @param container The name of the container
1931+
* @param obj The File containing the file to copy over
1932+
* @param contentType The MIME type of the file
1933+
* @param name The name of the file on the server
1934+
* @param manifest Set manifest content here
1935+
* @param metadata A map with the metadata as key names and values as the metadata values
1936+
* @param callback The object to which any callbacks will be sent (null if you don't want callbacks)
1937+
* @throws IOException There was an IO error doing network communication
1938+
* @throws HttpException There was an error with the http protocol
1939+
* @throws FilesException
1940+
*/
1941+
public boolean createManifestObject(String container, String contentType, String name, String manifest, Map<String,String> metadata, IFilesTransferCallback callback) throws IOException, HttpException, FilesException
1942+
{
1943+
byte[] arr = new byte[0];
1944+
if (this.isLoggedin())
1945+
{
1946+
String objName = name;
1947+
if (isValidContainerName(container) && isValidObjectName(objName))
1948+
{
1949+
1950+
HttpPut method = null;
1951+
try {
1952+
method = new HttpPut(storageURL+"/"+sanitizeForURI(container)+"/"+sanitizeForURI(objName));
1953+
method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
1954+
method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
1955+
method.setHeader(FilesConstants.MANIFEST_HEADER, manifest);
1956+
ByteArrayEntity entity = new ByteArrayEntity (arr);
1957+
entity.setContentType(contentType);
1958+
method.setEntity(new RequestEntityWrapper(entity, callback));
1959+
for(String key : metadata.keySet()) {
1960+
// logger.warn("Key:" + key + ":" + sanitizeForURI(metadata.get(key)));
1961+
method.setHeader(FilesConstants.X_OBJECT_META + key, sanitizeForURI(metadata.get(key)));
1962+
}
1963+
1964+
FilesResponse response = new FilesResponse(client.execute(method));
1965+
1966+
if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
1967+
method.abort();
1968+
if(login()) {
1969+
method = new HttpPut(storageURL+"/"+sanitizeForURI(container)+"/"+sanitizeForURI(objName));
1970+
method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
1971+
method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
1972+
if (manifest != null){
1973+
method.setHeader(FilesConstants.MANIFEST_HEADER, manifest);
1974+
}
1975+
entity = new ByteArrayEntity (arr);
1976+
entity.setContentType(contentType);
1977+
method.setEntity(new RequestEntityWrapper(entity, callback));
1978+
for(String key : metadata.keySet()) {
1979+
method.setHeader(FilesConstants.X_OBJECT_META + key, sanitizeForURI(metadata.get(key)));
1980+
}
1981+
response = new FilesResponse(client.execute(method));
1982+
}
1983+
else {
1984+
throw new FilesAuthorizationException("Re-login failed", response.getResponseHeaders(), response.getStatusLine());
1985+
}
1986+
}
1987+
1988+
if (response.getStatusCode() == HttpStatus.SC_CREATED)
1989+
{
1990+
return true;
1991+
}
1992+
else if (response.getStatusCode() == HttpStatus.SC_PRECONDITION_FAILED)
1993+
{
1994+
throw new FilesException("Etag missmatch", response.getResponseHeaders(), response.getStatusLine());
1995+
}
1996+
else if (response.getStatusCode() == HttpStatus.SC_LENGTH_REQUIRED)
1997+
{
1998+
throw new FilesException("Length miss-match", response.getResponseHeaders(), response.getStatusLine());
1999+
}
2000+
else
2001+
{
2002+
throw new FilesException("Unexpected Server Response", response.getResponseHeaders(), response.getStatusLine());
2003+
}
2004+
}
2005+
finally{
2006+
if (method != null) method.abort();
2007+
}
2008+
}
2009+
else
2010+
{
2011+
if (!isValidObjectName(objName)) {
2012+
throw new FilesInvalidNameException(objName);
2013+
}
2014+
else {
2015+
throw new FilesInvalidNameException(container);
2016+
}
2017+
}
2018+
}
2019+
else {
2020+
throw new FilesAuthorizationException("You must be logged in", null, null);
2021+
}
2022+
}
18932023

18942024
/**
18952025
* Store a file on the server
@@ -2910,17 +3040,32 @@ public String getCdnManagementURL() {
29103040
/**
29113041
* @param config
29123042
*/
2913-
2914-
public boolean updateObjectMetadata(String container, String object,
3043+
public boolean updateObjectManifest(String container, String object, String manifest) throws FilesAuthorizationException,
3044+
HttpException, IOException, FilesInvalidNameException
3045+
{
3046+
return updateObjectMetadataAndManifest(container, object, new HashMap<String, String>(), manifest);
3047+
}
3048+
/**
3049+
* @param config
3050+
*/
3051+
public boolean updateObjectMetadata(String container, String object,
29153052
Map<String,String> metadata) throws FilesAuthorizationException,
3053+
HttpException, IOException, FilesInvalidNameException
3054+
{
3055+
return updateObjectMetadataAndManifest(container, object, metadata, null);
3056+
}
3057+
/**
3058+
* @param config
3059+
*/
3060+
public boolean updateObjectMetadataAndManifest(String container, String object,
3061+
Map<String,String> metadata, String manifest) throws FilesAuthorizationException,
29163062
HttpException, IOException, FilesInvalidNameException {
29173063
FilesResponse response;
29183064

29193065
if (!isLoggedin) {
29203066
throw new FilesAuthorizationException("You must be logged in",
29213067
null, null);
29223068
}
2923-
29243069
if (!isValidContainerName(container))
29253070
throw new FilesInvalidNameException(container);
29263071
if (!isValidObjectName(object))
@@ -2932,6 +3077,9 @@ public boolean updateObjectMetadata(String container, String object,
29323077
HttpPost method = null;
29333078
try {
29343079
method = new HttpPost(postUrl);
3080+
if (manifest != null){
3081+
method.setHeader(FilesConstants.MANIFEST_HEADER, manifest);
3082+
}
29353083
method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
29363084
method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
29373085
if (!(metadata == null || metadata.isEmpty())) {

src/main/java/com/rackspacecloud/client/cloudfiles/FilesConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class FilesConstants
4848
public static final String X_CDN_REFERRER_ACL = "X-Referrer-ACL ";
4949
/** HTTP Header used by Cloud Files for the MD5Sum of the object being created in a Container **/
5050
public static final String E_TAG = "ETag";
51+
/** HTTP Header used for Object Manifest **/
52+
public static final String MANIFEST_HEADER = "X-Object-Manifest";
5153
/** These constants are used for performing queries on the content of a container **/
5254
public static final String LIST_CONTAINER_NAME_QUERY = "prefix";
5355
public static final String LIST_CONTAINER_LIMIT_OBJ_COUNT_QUERY = "limit";

0 commit comments

Comments
 (0)