Search in sources :

Example 1 with HttpException

use of org.talend.sdk.component.api.service.http.HttpException in project component-runtime by Talend.

the class HttpClientFactoryImplTest method handleHttpError.

@Test
void handleHttpError() throws IOException {
    final HttpServer server = createTestServer(HttpURLConnection.HTTP_FORBIDDEN);
    try {
        server.start();
        final ComplexOk ok = newDefaultFactory().create(ComplexOk.class, null);
        ok.base("http://localhost:" + server.getAddress().getPort() + "/api");
        ok.main1("search yes");
    } catch (final HttpException e) {
        assertEquals(HttpURLConnection.HTTP_FORBIDDEN, e.getResponse().status());
        assertEquals("POST@Connection=keep-alive/Content-length=10/Content-type=application/x-www-form-urlencoded@/api/@search yes", e.getResponse().error(String.class));
    } finally {
        server.stop(0);
    }
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer) HttpException(org.talend.sdk.component.api.service.http.HttpException) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServer (com.sun.net.httpserver.HttpServer)1 Test (org.junit.jupiter.api.Test)1 HttpException (org.talend.sdk.component.api.service.http.HttpException)1