Search in sources :

Example 1 with UnexpectedResponseException

use of io.airlift.http.client.UnexpectedResponseException in project trino by trinodb.

the class TestQueryResource method testGetQueryInfoDispatchFailure.

@Test
public void testGetQueryInfoDispatchFailure() {
    String queryId = runToCompletion("SELECT");
    QueryInfo info = getQueryInfo(queryId);
    assertFalse(info.isScheduled());
    assertNotNull(info.getFailureInfo());
    assertEquals(info.getFailureInfo().getErrorCode(), SYNTAX_ERROR.toErrorCode());
    server.getAccessControl().deny(privilege("query", VIEW_QUERY));
    try {
        assertThatThrownBy(() -> getQueryInfo(queryId)).isInstanceOf(UnexpectedResponseException.class).matches(throwable -> ((UnexpectedResponseException) throwable).getStatusCode() == 403);
    } finally {
        server.getAccessControl().reset();
    }
}
Also used : UnexpectedResponseException(io.airlift.http.client.UnexpectedResponseException) QueryInfo(io.trino.execution.QueryInfo) Test(org.testng.annotations.Test)

Example 2 with UnexpectedResponseException

use of io.airlift.http.client.UnexpectedResponseException in project trino by trinodb.

the class PinotClient method doHttpActionWithHeadersJson.

protected <T> T doHttpActionWithHeadersJson(Request.Builder requestBuilder, Optional<String> requestBody, JsonCodec<T> codec, Multimap<String, String> additionalHeaders) {
    requestBuilder.addHeaders(additionalHeaders);
    requestBuilder.setHeader(ACCEPT, APPLICATION_JSON);
    if (requestBody.isPresent()) {
        requestBuilder.setHeader(CONTENT_TYPE, APPLICATION_JSON);
        requestBuilder.setBodyGenerator(StaticBodyGenerator.createStaticBodyGenerator(requestBody.get(), StandardCharsets.UTF_8));
    }
    Request request = requestBuilder.build();
    JsonResponseHandler<T> responseHandler = createJsonResponseHandler(codec);
    T response = null;
    try {
        response = httpClient.execute(request, responseHandler);
    } catch (UnexpectedResponseException e) {
        throw new PinotException(PinotErrorCode.PINOT_HTTP_ERROR, Optional.empty(), format("Unexpected response status: %d for request %s to url %s, with headers %s, full response %s", e.getStatusCode(), requestBody.orElse(""), request.getUri(), request.getHeaders(), response));
    }
    return response;
}
Also used : PinotException(io.trino.plugin.pinot.PinotException) ACCEPT(com.google.common.net.HttpHeaders.ACCEPT) Request(io.airlift.http.client.Request) UnexpectedResponseException(io.airlift.http.client.UnexpectedResponseException)

Aggregations

UnexpectedResponseException (io.airlift.http.client.UnexpectedResponseException)2 ACCEPT (com.google.common.net.HttpHeaders.ACCEPT)1 Request (io.airlift.http.client.Request)1 QueryInfo (io.trino.execution.QueryInfo)1 PinotException (io.trino.plugin.pinot.PinotException)1 Test (org.testng.annotations.Test)1