use of org.apache.hc.core5.http.protocol.RequestContent in project datagear by datageartech.
the class HttpDataSet method resolveResult.
@Override
protected TemplateResolvedDataSetResult resolveResult(DataSetQuery query, List<DataSetProperty> properties, boolean resolveProperties) throws DataSetException {
String uri = null;
String headerContent = null;
String requestContent = null;
try {
uri = resolveTemplateUri(query);
headerContent = resolveTemplateHeaderContent(query);
requestContent = resolveTemplateRequestContent(query);
ClassicHttpRequest request = createHttpRequest(uri);
setHttpHeaders(request, headerContent);
setHttpEntity(request, requestContent);
JsonResponseHandler responseHandler = new JsonResponseHandler();
responseHandler.setProperties(properties);
responseHandler.setResponseDataJsonPath(getResponseDataJsonPath());
responseHandler.setDataSetQuery(query);
ResolvedDataSetResult result = this.httpClient.execute(request, responseHandler);
return new TemplateResolvedDataSetResult(result.getResult(), result.getProperties(), buildResolvedTemplate(uri, headerContent, requestContent));
} catch (DataSetException e) {
throw e;
} catch (Throwable t) {
throw new DataSetSourceParseException(t, buildResolvedTemplate(uri, headerContent, requestContent));
}
}
use of org.apache.hc.core5.http.protocol.RequestContent in project datagear by datageartech.
the class HttpDataSet method setHttpEntity.
protected void setHttpEntity(ClassicHttpRequest request, String requestContent) throws Throwable {
if (REQUEST_CONTENT_TYPE_FORM_URLENCODED.equals(this.requestContentType)) {
List<NameValuePair> params = toNameValuePairs(requestContent);
if (params == NOT_NAME_VALUE_PAIR_OBJ_ARRAY_JSON)
throw new RequestContentNotNameValueObjArrayJsonException(requestContent);
request.setEntity(new UrlEncodedFormEntity(params, Charset.forName(this.requestContentCharset)));
} else if (REQUEST_CONTENT_TYPE_JSON.equals(this.requestContentType)) {
ContentType contentType = ContentType.create(ContentType.APPLICATION_JSON.getMimeType(), Charset.forName(this.requestContentCharset));
StringEntity entity = new StringEntity(requestContent, contentType);
request.setEntity(entity);
} else
throw new DataSetException("Request content type [" + this.requestContentType + "] is not supported");
}
use of org.apache.hc.core5.http.protocol.RequestContent in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentOverwriteHeaders.
@Test
public void testRequestContentOverwriteHeaders() throws Exception {
final RequestContent interceptor = new RequestContent(true);
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.addHeader(new BasicHeader(HttpHeaders.CONTENT_LENGTH, "10"));
request.addHeader(new BasicHeader(HttpHeaders.TRANSFER_ENCODING, "whatever"));
request.setEntity(new StringEntity(""));
interceptor.process(request, request.getEntity(), context);
final Header h1 = request.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNotNull(h1);
Assertions.assertEquals("0", h1.getValue());
}
use of org.apache.hc.core5.http.protocol.RequestContent in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentAddHeaders.
@Test
public void testRequestContentAddHeaders() throws Exception {
final RequestContent interceptor = new RequestContent(true);
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.setEntity(new StringEntity(""));
interceptor.process(request, request.getEntity(), context);
final Header h1 = request.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNotNull(h1);
Assertions.assertEquals("0", h1.getValue());
final Header h2 = request.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
Assertions.assertNull(h2);
}
Aggregations