Hi,
I´ve been testing the new EMC RestFul Services and I haven´t found any java client in the web. The examples are written in python!!!!
I´ve spent a few hours to create the java client.
if anyone needs any specific client, please contact me through this thread.
I leave you the example of how to upload documents through rest, under folder:
Java Build Path: commons-codec-1.6.jar, commons-logging 1.1.1.jar, fluent-hc-4.2.5.jar, httpclient-4.2.5.jar, httpclient-cache-4.2.5, httpcore4.2.4.jar, httpmime-4.2.5.jar
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class CreateObjectsRest {
public static void main(String[] args) throws ClientProtocolException, IOException {
String path = "http://localhost:9080/dctm-rest/repositories/repository/folders/0b000406801e9ca8/objects";
createObjectUnderFolder (path);
}
private static void createObjectUnderFolder(String path) throws ClientProtocolException, IOException {
// TODO Auto-generated method stub
System.out.println ("*****createObjectUnderFolder REST*****");
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(path);
//format:Basic user:password (encode Base 64)
post.addHeader("Authorization", "Basic cGVwZTpwZXBl");
//format
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("format", "pdf"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//json y documento a importar
String json = "{\"properties\" : {\"object_name\" : \"REST DOCUMENT- PDF\", \"r_object_type\"
"dm_document\"}}";
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("data", new StringBody (json,"application/vnd.emc.documentum",Charset.forName("UTF-8")));
reqEntity.addPart("file", new FileBody( new File( "d:/doc.pdf" ) , "", "application/pdf", null));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
System.out.println ("response: " + response.getStatusLine());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}
I hope they serve!
Regards.