use of org.apache.hc.client5.http.classic.methods.HttpDelete in project webdrivermanager by bonigarcia.
the class WdmServer method exchange.
public String exchange(String url, String method, String json, int timeoutSec) throws IOException {
String responseContent = null;
try (CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build()) {
HttpUriRequestBase request = null;
switch(method) {
case GET:
request = new HttpGet(url);
break;
case DELETE:
request = new HttpDelete(url);
break;
default:
case POST:
request = new HttpPost(url);
HttpEntity body = new StringEntity(json);
request.setEntity(body);
request.setHeader("Content-Type", "application/json");
break;
}
RequestConfig requestConfig = custom().setConnectTimeout(timeoutSec, TimeUnit.SECONDS).build();
request.setConfig(requestConfig);
try (CloseableHttpResponse response = closeableHttpClient.execute(request)) {
responseContent = IOUtils.toString(response.getEntity().getContent(), UTF_8);
}
}
return responseContent;
}
use of org.apache.hc.client5.http.classic.methods.HttpDelete in project geo-platform by geosdi.
the class GPJsonDeleteConnectorRequest method prepareHttpMethod.
/**
* @return {@link HttpDelete}
*/
@Override
protected HttpDelete prepareHttpMethod() throws Exception {
String uriPath = super.checkUriPath();
HttpDelete httpDelete = new HttpDelete(uriPath);
httpDelete.setConfig(super.prepareRequestConfig());
return httpDelete;
}
use of org.apache.hc.client5.http.classic.methods.HttpDelete in project spotify-web-api-java by spotify-web-api-java.
the class SpotifyHttpManager method delete.
@Override
public String delete(URI uri, Header[] headers, HttpEntity body) throws IOException, SpotifyWebApiException, ParseException {
assert (uri != null);
assert (!uri.toString().equals(""));
final HttpDelete httpDelete = new HttpDelete(uri);
httpDelete.setHeaders(headers);
httpDelete.setEntity(body);
SpotifyApi.LOGGER.log(Level.FINE, "DELETE request uses these headers: " + GSON.toJson(headers));
String responseBody = getResponseBody(execute(httpClient, httpDelete));
httpDelete.reset();
return responseBody;
}
use of org.apache.hc.client5.http.classic.methods.HttpDelete in project LinkAgent by shulieTech.
the class HttpClientv5MethodInterceptor method getParameters.
private Map getParameters(HttpRequest httpRequest) {
URI uri = null;
try {
uri = httpRequest.getUri();
} catch (URISyntaxException e) {
logger.error("获取不到url", e);
}
if (httpRequest instanceof HttpGet) {
HttpGet httpGet = (HttpGet) httpRequest;
return toMap(uri.getQuery());
}
if (httpRequest instanceof HttpPost) {
HttpPost httpPost = (HttpPost) httpRequest;
HttpEntity httpEntity = httpPost.getEntity();
Map parameters = toMap(uri.getQuery());
InputStream in = null;
try {
in = httpEntity.getContent();
parameters.putAll(toMap(toString(in)));
} catch (Throwable t) {
} finally {
if (in != null) {
try {
in.reset();
} catch (IOException e) {
}
}
}
return parameters;
}
if (httpRequest instanceof HttpPut) {
HttpPut httpPut = (HttpPut) httpRequest;
HttpEntity httpEntity = httpPut.getEntity();
Map parameters = toMap(uri.getQuery());
InputStream in = null;
try {
in = httpEntity.getContent();
parameters.putAll(toMap(toString(in)));
} catch (Throwable t) {
} finally {
if (in != null) {
try {
in.reset();
} catch (IOException e) {
}
}
}
return parameters;
}
if (httpRequest instanceof HttpDelete) {
HttpDelete httpDelete = (HttpDelete) httpRequest;
return toMap(uri.getQuery());
}
if (httpRequest instanceof HttpHead) {
HttpHead httpHead = (HttpHead) httpRequest;
return toMap(uri.getQuery());
}
if (httpRequest instanceof HttpOptions) {
HttpOptions httpOptions = (HttpOptions) httpRequest;
return toMap(uri.getQuery());
}
if (httpRequest instanceof HttpTrace) {
HttpTrace httpTrace = (HttpTrace) httpRequest;
return toMap(uri.getQuery());
}
if (httpRequest instanceof HttpPatch) {
HttpPatch httpPatch = (HttpPatch) httpRequest;
HttpEntity httpEntity = httpPatch.getEntity();
Map parameters = toMap(uri.getQuery());
InputStream in = null;
try {
in = httpEntity.getContent();
parameters.putAll(toMap(toString(in)));
} catch (Throwable t) {
} finally {
if (in != null) {
try {
in.reset();
} catch (IOException e) {
}
}
}
return parameters;
}
return Collections.EMPTY_MAP;
}
use of org.apache.hc.client5.http.classic.methods.HttpDelete in project wildfly-clustering-spring-session by wildfly-clustering.
the class AbstractSmokeITCase method accept.
@Override
public void accept(URL baseURL1, URL baseURL2) throws Exception {
URI uri1 = SessionServlet.createURI(baseURL1);
URI uri2 = SessionServlet.createURI(baseURL2);
try (CloseableHttpClient client = this.provider.apply(baseURL1, baseURL2)) {
String sessionId = null;
int value = 0;
for (int i = 0; i < 4; i++) {
for (URI uri : Arrays.asList(uri1, uri2)) {
for (int j = 0; j < 4; j++) {
try (CloseableHttpResponse response = client.execute(new HttpGet(uri))) {
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
Assert.assertEquals(String.valueOf(value++), response.getFirstHeader(SessionServlet.VALUE).getValue());
String requestSessionId = response.getFirstHeader(SessionServlet.SESSION_ID).getValue();
if (sessionId == null) {
sessionId = requestSessionId;
} else {
Assert.assertEquals(sessionId, requestSessionId);
}
}
}
if (!this.transactional) {
// Grace time between failover requests
Thread.sleep(500);
}
}
}
try (CloseableHttpResponse response = client.execute(new HttpDelete(uri1))) {
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
Assert.assertEquals(sessionId, response.getFirstHeader(SessionServlet.SESSION_ID).getValue());
}
try (CloseableHttpResponse response = client.execute(new HttpHead(uri2))) {
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
String newSessionId = response.containsHeader(SessionServlet.SESSION_ID) ? response.getFirstHeader(SessionServlet.SESSION_ID).getValue() : null;
Assert.assertNotEquals(sessionId, newSessionId);
}
}
}
Aggregations