Search in sources :

Example 6 with HttpRequestWithBody

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"));
}
Also used : HttpRequestWithBody(com.mashape.unirest.request.HttpRequestWithBody) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with HttpRequestWithBody

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;
}
Also used : HitWrapper(org.apache.zeppelin.elasticsearch.action.HitWrapper) HttpRequestWithBody(com.mashape.unirest.request.HttpRequestWithBody) ActionException(org.apache.zeppelin.elasticsearch.action.ActionException) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) JsonNode(com.mashape.unirest.http.JsonNode) ActionResponse(org.apache.zeppelin.elasticsearch.action.ActionResponse)

Aggregations

HttpRequestWithBody (com.mashape.unirest.request.HttpRequestWithBody)7 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.Test)3 JsonNode (com.mashape.unirest.http.JsonNode)2 BaseRequest (com.mashape.unirest.request.BaseRequest)2 MultipartBody (com.mashape.unirest.request.body.MultipartBody)2 Resource (io.discloader.discloader.client.render.util.Resource)2 SendableMessage (io.discloader.discloader.entity.sendable.SendableMessage)2 File (java.io.File)2 ActionException (org.apache.zeppelin.elasticsearch.action.ActionException)2 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)2 HitWrapper (org.apache.zeppelin.elasticsearch.action.HitWrapper)2 JSONObject (org.json.JSONObject)2 JsonParseException (com.google.gson.JsonParseException)1 HttpRequest (com.mashape.unirest.request.HttpRequest)1 DiscordException (io.discloader.discloader.common.exceptions.DiscordException)1 Iterator (java.util.Iterator)1 AggWrapper (org.apache.zeppelin.elasticsearch.action.AggWrapper)1 JSONArray (org.json.JSONArray)1