use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testActivateAlreadyActiveProcessDefinition.
/**
* Test activating already active process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testActivateAlreadyActiveProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CONFLICT);
closeResponse(response);
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testSuspendAlreadySuspendedProcessDefinition.
/**
* Test suspending already suspended process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendAlreadySuspendedProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertTrue(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_CONFLICT);
closeResponse(response);
}
use of org.apache.http.client.methods.HttpPut in project Activiti by Activiti.
the class ModelResourceTest method testUpdateUnexistingModel.
public void testUpdateUnexistingModel() throws Exception {
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, "unexisting"));
httpPut.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
use of org.apache.http.client.methods.HttpPut in project ats-framework by Axway.
the class HttpClient method performUploadFile.
@Override
protected void performUploadFile(String localFile, String remoteDir, String remoteFile) throws FileTransferException {
checkClientInitialized();
final String uploadUrl = constructUploadUrl(remoteDir, remoteFile);
log.info("Uploading " + uploadUrl);
HttpEntityEnclosingRequestBase uploadMethod;
Object uploadMethodObject = customProperties.get(HTTP_HTTPS_UPLOAD_METHOD);
if (uploadMethodObject == null || !uploadMethodObject.toString().equals(HTTP_HTTPS_UPLOAD_METHOD__POST)) {
uploadMethod = new HttpPut(uploadUrl);
} else {
uploadMethod = new HttpPost(uploadUrl);
}
String contentType = DEFAULT_HTTP_HTTPS_UPLOAD_CONTENT_TYPE;
Object contentTypeObject = customProperties.get(HTTP_HTTPS_UPLOAD_CONTENT_TYPE);
if (contentTypeObject != null) {
contentType = contentTypeObject.toString();
}
FileEntity fileUploadEntity = new FileEntity(new File(localFile), ContentType.parse(contentType));
uploadMethod.setEntity(fileUploadEntity);
HttpResponse response = null;
try {
// add headers specified by the user
addRequestHeaders(uploadMethod);
// upload the file
response = httpClient.execute(uploadMethod, httpContext);
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode < 200 || responseCode > 206) {
// 204 No Content - there was a file with same name on same location, we replaced it
throw new FileTransferException("Uploading '" + uploadUrl + "' returned '" + response.getStatusLine() + "'");
}
} catch (ClientProtocolException e) {
log.error("Unable to upload file!", e);
throw new FileTransferException(e);
} catch (IOException e) {
log.error("Unable to upload file!", e);
throw new FileTransferException(e);
} finally {
// the UPLOAD returns response body on error
if (response != null && response.getEntity() != null) {
HttpEntity responseEntity = response.getEntity();
// the underlying stream has been closed
try {
EntityUtils.consume(responseEntity);
} catch (IOException e) {
// we tried our best to release the resources
}
}
}
log.info("Successfully uploaded '" + localFile + "' to '" + remoteDir + remoteFile + "', host " + this.hostname);
}
use of org.apache.http.client.methods.HttpPut in project asterixdb by apache.
the class HyracksConnection method deployBinary.
@Override
public DeploymentId deployBinary(List<String> jars) throws Exception {
/** generate a deployment id */
DeploymentId deploymentId = new DeploymentId(UUID.randomUUID().toString());
List<URL> binaryURLs = new ArrayList<>();
if (jars != null && !jars.isEmpty()) {
CloseableHttpClient hc = new DefaultHttpClient();
try {
/** upload jars through a http client one-by-one to the CC server */
for (String jar : jars) {
int slashIndex = jar.lastIndexOf('/');
String fileName = jar.substring(slashIndex + 1);
String url = "http://" + ccHost + ":" + ccInfo.getWebPort() + "/applications/" + deploymentId.toString() + "&" + fileName;
HttpPut put = new HttpPut(url);
put.setEntity(new FileEntity(new File(jar), "application/octet-stream"));
HttpResponse response = hc.execute(put);
response.getEntity().consumeContent();
if (response.getStatusLine().getStatusCode() != 200) {
hci.unDeployBinary(deploymentId);
throw new HyracksException(response.getStatusLine().toString());
}
/** add the uploaded URL address into the URLs of jars to be deployed at NCs */
binaryURLs.add(new URL(url));
}
} finally {
hc.close();
}
}
/** deploy the URLs to the CC and NCs */
hci.deployBinary(binaryURLs, deploymentId);
return deploymentId;
}
Aggregations