@@ -1890,6 +1890,136 @@ else if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
1890
1890
throw new FilesAuthorizationException ("You must be logged in" , null , null );
1891
1891
}
1892
1892
}
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
+ }
1893
2023
1894
2024
/**
1895
2025
* Store a file on the server
@@ -2910,17 +3040,32 @@ public String getCdnManagementURL() {
2910
3040
/**
2911
3041
* @param config
2912
3042
*/
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 ,
2915
3052
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 ,
2916
3062
HttpException , IOException , FilesInvalidNameException {
2917
3063
FilesResponse response ;
2918
3064
2919
3065
if (!isLoggedin ) {
2920
3066
throw new FilesAuthorizationException ("You must be logged in" ,
2921
3067
null , null );
2922
3068
}
2923
-
2924
3069
if (!isValidContainerName (container ))
2925
3070
throw new FilesInvalidNameException (container );
2926
3071
if (!isValidObjectName (object ))
@@ -2932,6 +3077,9 @@ public boolean updateObjectMetadata(String container, String object,
2932
3077
HttpPost method = null ;
2933
3078
try {
2934
3079
method = new HttpPost (postUrl );
3080
+ if (manifest != null ){
3081
+ method .setHeader (FilesConstants .MANIFEST_HEADER , manifest );
3082
+ }
2935
3083
method .getParams ().setIntParameter ("http.socket.timeout" , connectionTimeOut );
2936
3084
method .setHeader (FilesConstants .X_AUTH_TOKEN , authToken );
2937
3085
if (!(metadata == null || metadata .isEmpty ())) {
0 commit comments