use of org.apache.http.client.methods.RequestBuilder in project webmagic by code4craft.
the class HttpClientDownloader method getHttpUriRequest.
protected HttpUriRequest getHttpUriRequest(Request request, Site site, Map<String, String> headers, HttpHost proxy) {
RequestBuilder requestBuilder = selectRequestMethod(request).setUri(request.getUrl());
if (headers != null) {
for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
}
}
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (site != null) {
requestConfigBuilder.setConnectionRequestTimeout(site.getTimeOut()).setSocketTimeout(site.getTimeOut()).setConnectTimeout(site.getTimeOut()).setCookieSpec(CookieSpecs.BEST_MATCH);
}
if (proxy != null) {
requestConfigBuilder.setProxy(proxy);
request.putExtra(Request.PROXY, proxy);
}
requestBuilder.setConfig(requestConfigBuilder.build());
return requestBuilder.build();
}
use of org.apache.http.client.methods.RequestBuilder in project asterixdb by apache.
the class TestExecutor method constructPostMethodUrl.
protected HttpUriRequest constructPostMethodUrl(String statement, URI uri, String stmtParam, List<CompilationUnit.Parameter> otherParams) {
RequestBuilder builder = RequestBuilder.post(uri);
if (stmtParam != null) {
for (CompilationUnit.Parameter param : upsertParam(otherParams, stmtParam, statement)) {
builder.addParameter(param.getName(), param.getValue());
}
builder.addParameter(stmtParam, statement);
} else {
// this seems pretty bad - we should probably fix the API and not the client
builder.setEntity(new StringEntity(statement, StandardCharsets.UTF_8));
}
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
use of org.apache.http.client.methods.RequestBuilder in project asterixdb by apache.
the class TestExecutor method constructGetMethod.
private HttpUriRequest constructGetMethod(URI endpoint, List<CompilationUnit.Parameter> params) {
RequestBuilder builder = RequestBuilder.get(endpoint);
for (CompilationUnit.Parameter param : params) {
builder.addParameter(param.getName(), param.getValue());
}
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
use of org.apache.http.client.methods.RequestBuilder in project asterixdb by apache.
the class CancellationTestExecutor method constructDeleteMethodUrl.
// Constructs a HTTP DELETE request.
private HttpUriRequest constructDeleteMethodUrl(URI uri, List<TestCase.CompilationUnit.Parameter> otherParams) {
RequestBuilder builder = RequestBuilder.delete(uri);
for (TestCase.CompilationUnit.Parameter param : otherParams) {
builder.addParameter(param.getName(), param.getValue());
}
builder.setCharset(StandardCharsets.UTF_8);
return builder.build();
}
use of org.apache.http.client.methods.RequestBuilder in project incubator-gobblin by apache.
the class ApacheHttpRequestBuilderTest method testBuildWriteRequest.
/**
* Build a {@link HttpUriRequest} from a {@link GenericRecord}
*/
public void testBuildWriteRequest() throws IOException {
String urlTemplate = "http://www.test.com/a/part1:${part1}/a/part2:${part2}";
String verb = "post";
ApacheHttpRequestBuilder builder = spy(new ApacheHttpRequestBuilder(urlTemplate, verb, "application/json"));
ArgumentCaptor<RequestBuilder> requestBuilderArgument = ArgumentCaptor.forClass(RequestBuilder.class);
Queue<BufferedRecord<GenericRecord>> queue = HttpTestUtils.createQueue(1, false);
AsyncRequest<GenericRecord, HttpUriRequest> request = builder.buildRequest(queue);
verify(builder).build(requestBuilderArgument.capture());
RequestBuilder expected = RequestBuilder.post();
expected.setUri("http://www.test.com/a/part1:01/a/part2:02?param1=01");
String payloadStr = "{\"id\":\"id0\"}";
expected.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()).setEntity(new StringEntity(payloadStr, ContentType.APPLICATION_JSON));
// Compare HttpUriRequest
HttpTestUtils.assertEqual(requestBuilderArgument.getValue(), expected);
Assert.assertEquals(request.getRecordCount(), 1);
Assert.assertEquals(queue.size(), 0);
}
Aggregations