use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.
the class paloconnection method sendToServer.
public HttpEntity sendToServer(List<NameValuePair> qparams, String strAPIUrl) throws paloexception {
try {
URI uri = URIUtils.createURI("http", strServer, Integer.valueOf(strPort), strAPIUrl, URLEncodedUtils.format(qparams, "UTF-8"), null);
HttpGet req = new HttpGet(uri);
// System.out.println(req.getURI());
// Send to Server
HttpResponse rsp = paloHttpClient.execute(paloTargetHost, req);
HttpEntity entity = rsp.getEntity();
if (rsp.getStatusLine().getStatusCode() != 200) {
// Error had been occured
// Close Connection and thend raise paloexception error
CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
csv.setQuoteChar('"');
csv.readNext();
paloexception plX = new paloexception(csv.get(0), csv.get(1), csv.get(2));
csv.close();
entity.consumeContent();
// paloHttpClient.getConnectionManager().shutdown();
throw (plX);
} else {
return entity;
}
} catch (Exception e) {
// if(paloHttpClient!=null)paloHttpClient.getConnectionManager().shutdown();
throw new paloexception(e.getMessage());
}
}
use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.
the class DynamicsCRMClient method createAndExecuteRequest.
/**
* Created and executes a request
*
* @param uri the request URI
* @param httpEntity the entity to send.
* @param method HTTP method
*
* @return the response to the request.
* @throws ServiceUnavailableException
*/
protected HttpResponse createAndExecuteRequest(URI uri, HttpEntity httpEntity, HttpMethod method) throws ServiceUnavailableException {
boolean hasRetried = false;
while (true) {
try {
httpClient = (DefaultHttpClient) httpClientFactory.create(null, null);
HttpRequestBase request = null;
if (method == HttpMethod.POST) {
request = new HttpPost(uri);
} else if (method == HttpMethod.PATCH) {
request = new HttpPatch(uri);
} else if (method == HttpMethod.DELETE) {
request = new HttpDelete(uri);
} else {
throw new HttpClientException("Unsupported operation:" + method);
}
request.addHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
if (request instanceof HttpEntityEnclosingRequestBase) {
((HttpEntityEnclosingRequestBase) request).setEntity(httpEntity);
}
HttpResponse response = httpClient.execute(request);
if (isResponseSuccess(response.getStatusLine().getStatusCode())) {
request.releaseConnection();
EntityUtils.consume(response.getEntity());
return response;
} else {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && !hasRetried) {
refreshToken();
hasRetried = true;
continue;
}
HttpEntity entity = response.getEntity();
String message = null;
if (entity != null) {
message = odataClient.getDeserializer(ContentType.JSON).toError(entity.getContent()).getMessage();
} else {
message = response.getStatusLine().getReasonPhrase();
}
throw new HttpClientException(message);
}
} catch (Exception e) {
throw new HttpClientException(e);
}
}
}
use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.
the class WsdlTokenManager method getSOAPResponse.
private static String getSOAPResponse(URI issuerUri, String soapEnvelope) {
HttpResponse response = null;
// Create the request that will submit the request to the server
try {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
HttpClient client = new SystemDefaultHttpClient(params);
HttpPost post = new HttpPost(issuerUri);
StringEntity entity = new StringEntity(soapEnvelope);
post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
post.setEntity(entity);
response = client.execute(post);
return EntityUtils.toString(response.getEntity());
} catch (ClientProtocolException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}
return null;
}
use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.
the class RestClient method executePostRequest.
private HttpResponse executePostRequest(String apiURI, String payloadAsString) {
try {
HttpPost postRequest = new HttpPost(bonitaURI + apiURI);
StringEntity input = new StringEntity(payloadAsString);
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest, httpContext);
return response;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.apache.http.HttpResponse in project selenium-tests by Wikia.
the class GraphApi method createFacebookTestUser.
public HashMap<String, String> createFacebookTestUser(String appId) {
try {
HttpResponse response = createTestUser(appId);
String entity = EntityUtils.toString(response.getEntity());
return new Gson().fromJson(entity, new TypeToken<HashMap<String, String>>() {
}.getType());
} catch (IOException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
} catch (URISyntaxException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
}
}
Aggregations