如何使用httpclient 4.3.6调用DCTM 7.1 REST API?
How to use httpclient 4.3.6 to invoke DCTM 7.1 REST API?
我希望使用 REST API 与 Documentum 存储库进行交互。我想使用 http-client 4.3 jar 来执行此交互。
我希望有人可以提供示例,帮助我指明如何与 DCTM 交互的正确方向。
我无法找到一个清晰简单的示例来说明如何执行此操作。
谢谢
我知道现在回答这个问题有点晚了。但我想回答以帮助那些仍然需要代码来向其他人发出请求的人 api。这是向其余 api 发送 post 请求以启动工作流的完整示例。
其他需要可以查看EMC提供的名为Documentum xCP Rest Services的文档:https://support.emc.com/docu52500_Documentum-xCP-REST-Services-2.1-Development-Guide.pdf?language=en_US&request=akamai与本例对比,根据需要修改。
更新:
此外,如果您不使用 xcp,这里是休息文档 api 没有它 emc.com/collateral/TechnicalDocument/docu57895.pdf
您也可以在此处查看我的回答 以从其余部分获取对象数据和内容api(没有 xcp)
String strResponse = "";
String process_id = "system_name of the process you want to start";
String url = "Your App Url Here/processes/" + process_id;
String json = "{"+
"\"run-stateless\" : \"false\","+
"\"data\" :"+
" { "+
" \"variables\" : "+
" { \"Variable name\" : \"Variable value\" } "+
" } "+
"}";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
BufferedReader rd = null;
CloseableHttpResponse cls = null;
try {
HttpPost request = new HttpPost(url);
// set timeouts as you like
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(60 * 1000).setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(20 * 1000).build();
request.setConfig(config);
StringEntity params = new StringEntity(json);
request.addHeader("Accept", "application/json");
request.addHeader(
"Authorization",
"Basic "
+ com.documentum.xmlconfig.util.Base64
.encode("username here" + ":"
+ "password here"));
request.addHeader("Content-Type", "application/vnd.emc.xcp+json");
request.setEntity(params);
try {
cls = httpClient.execute(request);
HttpEntity entity = cls.getEntity();
rd = new BufferedReader(new InputStreamReader(
entity.getContent()));
String line = "";
while (line != null) {
line = rd.readLine();
strResponse += line;
}
strResponse = strResponse.trim().replace("\n", "");
String statusline = cls.getStatusLine().toString();
if (!statusline.contains("200") && !statusline.contains("201")) {
Log.write("Process is not started");
// log the strResponse or do something with it
} else {
System.out.println("Process started successfully");
}
} catch (Exception e) {
e.printStackTrace();
}
} finally {
// using commons-io-2.4.jar
IOUtils.closeQuietly(httpClient);
IOUtils.closeQuietly(cls);
IOUtils.closeQuietly(rd);
}
我希望使用 REST API 与 Documentum 存储库进行交互。我想使用 http-client 4.3 jar 来执行此交互。
我希望有人可以提供示例,帮助我指明如何与 DCTM 交互的正确方向。
我无法找到一个清晰简单的示例来说明如何执行此操作。
谢谢
我知道现在回答这个问题有点晚了。但我想回答以帮助那些仍然需要代码来向其他人发出请求的人 api。这是向其余 api 发送 post 请求以启动工作流的完整示例。
其他需要可以查看EMC提供的名为Documentum xCP Rest Services的文档:https://support.emc.com/docu52500_Documentum-xCP-REST-Services-2.1-Development-Guide.pdf?language=en_US&request=akamai与本例对比,根据需要修改。
更新:
此外,如果您不使用 xcp,这里是休息文档 api 没有它 emc.com/collateral/TechnicalDocument/docu57895.pdf
您也可以在此处查看我的回答
String strResponse = "";
String process_id = "system_name of the process you want to start";
String url = "Your App Url Here/processes/" + process_id;
String json = "{"+
"\"run-stateless\" : \"false\","+
"\"data\" :"+
" { "+
" \"variables\" : "+
" { \"Variable name\" : \"Variable value\" } "+
" } "+
"}";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
BufferedReader rd = null;
CloseableHttpResponse cls = null;
try {
HttpPost request = new HttpPost(url);
// set timeouts as you like
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(60 * 1000).setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(20 * 1000).build();
request.setConfig(config);
StringEntity params = new StringEntity(json);
request.addHeader("Accept", "application/json");
request.addHeader(
"Authorization",
"Basic "
+ com.documentum.xmlconfig.util.Base64
.encode("username here" + ":"
+ "password here"));
request.addHeader("Content-Type", "application/vnd.emc.xcp+json");
request.setEntity(params);
try {
cls = httpClient.execute(request);
HttpEntity entity = cls.getEntity();
rd = new BufferedReader(new InputStreamReader(
entity.getContent()));
String line = "";
while (line != null) {
line = rd.readLine();
strResponse += line;
}
strResponse = strResponse.trim().replace("\n", "");
String statusline = cls.getStatusLine().toString();
if (!statusline.contains("200") && !statusline.contains("201")) {
Log.write("Process is not started");
// log the strResponse or do something with it
} else {
System.out.println("Process started successfully");
}
} catch (Exception e) {
e.printStackTrace();
}
} finally {
// using commons-io-2.4.jar
IOUtils.closeQuietly(httpClient);
IOUtils.closeQuietly(cls);
IOUtils.closeQuietly(rd);
}