use of com.mashape.unirest.request.HttpRequestWithBody in project javalin by tipsy.
the class TestDefaultContentType method test_allows_ISO_8859_1.
@Test
public void test_allows_ISO_8859_1() throws Exception {
app.get("/test-iso-encoding", ctx -> {
ctx.response().setCharacterEncoding("iso-8859-1");
ctx.result("");
});
HttpResponse<String> response = new HttpRequestWithBody(HttpMethod.GET, origin + "/test-iso-encoding").asString();
String charset = response.getHeaders().getFirst("Content-Type");
assertThat(charset, containsString("iso-8859-1"));
}
use of com.mashape.unirest.request.HttpRequestWithBody in project zeppelin by apache.
the class HttpBasedClient method index.
@Override
public ActionResponse index(String index, String type, String id, String data) {
ActionResponse response = null;
try {
HttpRequestWithBody request = null;
if (StringUtils.isEmpty(id)) {
request = Unirest.post(getUrl(index, type, id, false));
} else {
request = Unirest.put(getUrl(index, type, id, false));
}
request.header("Accept", "application/json").header("Content-Type", "application/json").body(data).getHttpRequest();
if (StringUtils.isNotEmpty(username)) {
request.basicAuth(username, password);
}
final HttpResponse<JsonNode> result = request.asJson();
final boolean isSucceeded = isSucceeded(result);
if (isSucceeded) {
response = new ActionResponse().succeeded(true).hit(new HitWrapper(getFieldAsString(result, "_index"), getFieldAsString(result, "_type"), getFieldAsString(result, "_id"), null));
} else {
throw new ActionException(result.getBody().toString());
}
} catch (final UnirestException e) {
throw new ActionException(e);
}
return response;
}
Aggregations