08-07-2013 10:37 AM
HttpResponse response = null;
String processInstanceId = null;
String taskDefinitionKey = null;
String taskId = null;
CryptUtil crypt = CryptUtil.getInstance();
String pwdCrypt = crypt.encrypt(password);
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080),
new UsernamePasswordCredentials(user, pwdCrypt));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("localhost", 8080, "http"), basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
try {
HttpPost postMethod = new HttpPost("http://localhost:8080/activiti-rest/service/process-instance");
LoadProp lprop = new LoadProp();
String procUOIA = lprop.getProcKeyUOIA();
String groupUOIA = lprop.getGroupUOIA();
taskDefinitionKey = lprop.getTaskDefinitionKey();
Format formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String sData = formatter.format(data);
JSONObject jsonObj = new JSONObject();
jsonObj.put("processDefinitionId", procUOIA);
jsonObj.put("mittente", mittente);
jsonObj.put("oggetto", oggetto);
jsonObj.put("data", sData);
jsonObj.put("note", note);
jsonObj.put("group", groupUOIA);
//postMethod.setEntity(new StringEntity("{\"processDefinitionId\":\"" + procUOIA + "\"}", "UTF-8"));
StringEntity se = new StringEntity(jsonObj.toString(),"UTF-8");
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
postMethod.setEntity(se);
response = client.execute(postMethod, localcontext);
} catch (Exception e) {
e.printStackTrace(); }
try {
//System.out.println(IOUtils.toString(response.getEntity().getContent()));
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String json = sb.toString();
JSONObject jObj = new JSONObject(json);
processInstanceId = jObj.getString("processInstanceId");
} catch (Exception e) {
e.printStackTrace }
try{
HttpGet getMethod = new HttpGet("http://localhost:8080/activiti-rest/service/process-instance/" + processInstanceId);
response = client.execute(getMethod, localcontext);
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String json = sb.toString();
JSONObject jObj = new JSONObject(json);
if (jObj.get("tasks") != null && jObj.get("tasks").getClass().getName().equalsIgnoreCase("org.json.JSONArray")){
JSONArray jArray = jObj.getJSONArray("tasks");
for (int i = 0; i < jArray.length(); i++){
JSONObject jso = jArray.getJSONObject(i);
if(jso.getString("taskDefinitionKey").equalsIgnoreCase(taskDefinitionKey)){
taskId = jso.getString("taskId");
break;
}
}
}
if (taskId == null){
risp.setEsito("KO");
err.setDescrizione("Task del processo UOIA non trovato");
err.setCodice("106");
risp.setErrore(err);
return risp;
}
}
catch (Exception e) {
risp.setEsito("KO");
e.printStackTrace(); }
try{
File test = new File("E:/lecce.doc");
HttpPost postMethod =
new HttpPost("http://localhost:8080/activiti-rest/service/task/" + taskId + "/attachment");
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(test), test.length());
reqEntity.setContentType(FileUtil.getMimeType(test));
reqEntity.setChunked(true);
postMethod.setEntity(reqEntity);
response = client.execute(postMethod, localcontext);
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String json = sb.toString();
JSONObject jObj = new JSONObject(json);
System.out.println(jObj);
}
catch (Exception e) {
e.printStackTrace(); }
08-08-2013 04:56 AM
08-08-2013 10:12 AM
08-09-2013 04:13 AM
08-12-2013 08:58 AM
HttpPost postMethod =
andRequest: PUT /task/{taskId}/attachment
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.