use of org.apache.gobblin.r2.R2RestRequestBuilder in project incubator-gobblin by apache.
the class R2RestRequestBuilderTest method testBuildWriteRequest.
/**
* Build a {@link RestRequest} from a {@link GenericRecord}
*/
public void testBuildWriteRequest() throws URISyntaxException, IOException {
String urlTemplate = "http://www.test.com/a/part1:${part1}/a/part2:${part2}";
String verb = "update";
String protocolVersion = "2.0.0";
R2RestRequestBuilder builder = spy(new R2RestRequestBuilder(urlTemplate, verb, protocolVersion));
ArgumentCaptor<RestRequestBuilder> requestBuilderArgument = ArgumentCaptor.forClass(RestRequestBuilder.class);
Queue<BufferedRecord<GenericRecord>> queue = HttpTestUtils.createQueue(1, false);
AsyncRequest<GenericRecord, RestRequest> request = builder.buildRequest(queue);
verify(builder).build(requestBuilderArgument.capture());
RestRequestBuilder expected = new RestRequestBuilder(new URI("http://www.test.com/a/part1:01/a/part2:02?param1=01"));
expected.setMethod("PUT");
expected.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion);
expected.setHeader(RestConstants.HEADER_RESTLI_REQUEST_METHOD, verb.toLowerCase());
expected.setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON);
DataMap data = new DataMap();
data.put("id", "id0");
expected.setEntity(JACKSON_DATA_CODEC.mapToBytes(data));
HttpTestUtils.assertEqual(requestBuilderArgument.getValue(), expected);
Assert.assertEquals(request.getRecordCount(), 1);
Assert.assertEquals(queue.size(), 0);
}
use of org.apache.gobblin.r2.R2RestRequestBuilder in project incubator-gobblin by apache.
the class R2RestWriterBuilder method fromConfig.
@Override
public R2RestWriterBuilder fromConfig(Config config) {
config = config.withFallback(FALLBACK);
this.client = createClient(config);
String urlTemplate = config.getString(HttpConstants.URL_TEMPLATE);
String verb = config.getString(HttpConstants.VERB);
String protocolVersion = config.getString(HttpConstants.PROTOCOL_VERSION);
asyncRequestBuilder = new R2RestRequestBuilder(urlTemplate, verb, protocolVersion);
Set<String> errorCodeWhitelist = HttpUtils.getErrorCodeWhitelist(config);
responseHandler = new R2RestResponseHandler(errorCodeWhitelist, metricContext);
return this;
}
Aggregations