use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android-player-samples by BrightcoveOS.
the class MainActivity method httpGet.
public String httpGet(String url) {
String domain = getResources().getString(R.string.ais_domain);
String result = "";
CookieStore cookieStore = new BasicCookieStore();
BasicHttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
// If we have a cookie stored, parse and use it. Otherwise, use a default http client.
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
if (!authorizationCookie.equals("")) {
String[] cookies = authorizationCookie.split(";");
for (int i = 0; i < cookies.length; i++) {
String[] kvp = cookies[i].split("=");
if (kvp.length != 2) {
throw new Exception("Illegal cookie: missing key/value pair.");
}
BasicClientCookie c = new BasicClientCookie(kvp[0], kvp[1]);
c.setDomain(domain);
cookieStore.addCookie(c);
}
}
HttpResponse httpResponse = httpClient.execute(httpGet, localContext);
result = EntityUtils.toString(httpResponse.getEntity());
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage());
}
return result;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project Activiti by Activiti.
the class BaseJPARestTestCase method assertResultsPresentInPostDataResponseWithStatusCheck.
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
int numberOfResultsExpected = 0;
if (expectedResourceIds != null) {
numberOfResultsExpected = expectedResourceIds.length;
}
// Do the actual call
HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
post.setEntity(new StringEntity(body.toString()));
HttpResponse response = executeHttpRequest(post, expectedStatusCode);
if (expectedStatusCode == HttpStatus.SC_OK) {
// Check status and size
JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
JsonNode dataNode = rootNode.get("data");
assertEquals(numberOfResultsExpected, dataNode.size());
// Check presence of ID's
if (expectedResourceIds != null) {
List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
Iterator<JsonNode> it = dataNode.iterator();
while (it.hasNext()) {
String id = it.next().get("id").textValue();
toBeFound.remove(id);
}
assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project Activiti by Activiti.
the class JpaRestTest method testGetJpaVariableViaHistoricProcessCollection.
@Deployment(resources = { "org/activiti/rest/api/jpa/jpa-process.bpmn20.xml" })
public void testGetJpaVariableViaHistoricProcessCollection() throws Exception {
// Get JPA managed entity through the repository
Message message = messageRepository.findOne(1L);
assertNotNull(message);
assertEquals("Hello World", message.getText());
// add the entity to the process variables and start the process
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("message", message);
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("jpa-process", processVariables);
assertNotNull(processInstance);
Task task = processEngine.getTaskService().createTaskQuery().singleResult();
assertEquals("Activiti is awesome!", task.getName());
// Request all variables (no scope provides) which include global and local
HttpResponse response = executeHttpRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES) + "?processInstanceId=" + processInstance.getId() + "&includeProcessVariables=true"), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
// check for message variable of type serializable
assertNotNull(responseNode);
JsonNode variablesArrayNode = responseNode.get("data").get(0).get("variables");
assertEquals(1, variablesArrayNode.size());
JsonNode variableNode = variablesArrayNode.get(0);
assertEquals("message", variableNode.get("name").asText());
assertEquals("serializable", variableNode.get("type").asText());
assertNotNull(variableNode.get("valueUrl"));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by DirtyUnicorns.
the class TestHttpClient method execute.
public HttpResponse execute(final HttpRequest request, final HttpHost targetHost, final HttpClientConnection conn) throws HttpException, IOException {
this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
this.httpexecutor.preProcess(request, this.httpproc, this.context);
HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
this.httpexecutor.postProcess(response, this.httpproc, this.context);
return response;
}
Aggregations