Search in sources :

Example 61 with ContentResponse

use of org.eclipse.jetty.client.api.ContentResponse in project jetty.project by eclipse.

the class JdbcLoginServiceTest method testGetNonExistantUser.

@Test
public void testGetNonExistantUser() throws Exception {
    try {
        startClient("foo", "bar");
        ContentResponse response = _client.GET(_baseUri.resolve("input.txt"));
        assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    } finally {
        stopClient();
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Test(org.junit.Test)

Example 62 with ContentResponse

use of org.eclipse.jetty.client.api.ContentResponse in project jetty.project by eclipse.

the class JdbcLoginServiceTest method testHead.

//Head requests to jetty-client are not working: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=394552
@Ignore
public void testHead() throws Exception {
    try {
        startClient();
        Request request = _client.newRequest(_baseUri.resolve("input.txt"));
        request.method(HttpMethod.HEAD);
        ContentResponse response = request.send();
        int responseStatus = response.getStatus();
        assertEquals(HttpStatus.OK_200, responseStatus);
    } finally {
        stopClient();
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) Ignore(org.junit.Ignore)

Example 63 with ContentResponse

use of org.eclipse.jetty.client.api.ContentResponse in project druid by druid-io.

the class KerberosJettyHttpClientProvider method get.

@Override
public HttpClient get() {
    final HttpClient httpClient = delegateProvider.get();
    httpClient.getAuthenticationStore().addAuthentication(new Authentication() {

        @Override
        public boolean matches(String type, URI uri, String realm) {
            return true;
        }

        @Override
        public Result authenticate(final Request request, ContentResponse response, Authentication.HeaderInfo headerInfo, Attributes context) {
            return new Result() {

                @Override
                public URI getURI() {
                    return request.getURI();
                }

                @Override
                public void apply(Request request) {
                    try {
                        // No need to set cookies as they are handled by Jetty Http Client itself.
                        URI uri = request.getURI();
                        if (DruidKerberosUtil.needToSendCredentials(httpClient.getCookieStore(), uri)) {
                            log.debug("No Auth Cookie found for URI[%s]. Existing Cookies[%s] Authenticating... ", uri, httpClient.getCookieStore().getCookies());
                            final String host = request.getHost();
                            DruidKerberosUtil.authenticateIfRequired(config);
                            UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
                            String challenge = currentUser.doAs(new PrivilegedExceptionAction<String>() {

                                @Override
                                public String run() throws Exception {
                                    return DruidKerberosUtil.kerberosChallenge(host);
                                }
                            });
                            request.getHeaders().add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challenge);
                        } else {
                            log.debug("Found Auth Cookie found for URI[%s].", uri);
                        }
                    } catch (Throwable e) {
                        Throwables.propagate(e);
                    }
                }
            };
        }
    });
    return httpClient;
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) Attributes(org.eclipse.jetty.util.Attributes) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) URI(java.net.URI) Authentication(org.eclipse.jetty.client.api.Authentication) HttpClient(org.eclipse.jetty.client.HttpClient) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 64 with ContentResponse

use of org.eclipse.jetty.client.api.ContentResponse in project jetty.project by eclipse.

the class HttpClientTest method testHTTP10WithKeepAliveAndNoContent.

@Test
public void testHTTP10WithKeepAliveAndNoContent() throws Exception {
    start(new EmptyServerHandler());
    ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).version(HttpVersion.HTTP_1_0).header(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.asString()).timeout(5, TimeUnit.SECONDS).send();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getHeaders().contains(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.asString()));
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Test(org.junit.Test)

Example 65 with ContentResponse

use of org.eclipse.jetty.client.api.ContentResponse in project jetty.project by eclipse.

the class HttpClientTest method test_GET_ResponseWithContent.

@Test
public void test_GET_ResponseWithContent() throws Exception {
    final byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            response.getOutputStream().write(data);
            baseRequest.setHandled(true);
        }
    });
    client.setConnectBlocking(true);
    ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort());
    Assert.assertNotNull(response);
    Assert.assertEquals(200, response.getStatus());
    byte[] content = response.getContent();
    Assert.assertArrayEquals(data, content);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Test(org.junit.Test)

Aggregations

ContentResponse (org.eclipse.jetty.client.api.ContentResponse)408 Test (org.junit.Test)322 HttpServletRequest (javax.servlet.http.HttpServletRequest)204 IOException (java.io.IOException)164 HttpServletResponse (javax.servlet.http.HttpServletResponse)159 ServletException (javax.servlet.ServletException)150 Request (org.eclipse.jetty.client.api.Request)117 HttpClient (org.eclipse.jetty.client.HttpClient)105 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)92 HttpServlet (javax.servlet.http.HttpServlet)48 Properties (java.util.Properties)45 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)45 InterruptedIOException (java.io.InterruptedIOException)42 Request (org.eclipse.jetty.server.Request)39 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)38 CountDownLatch (java.util.concurrent.CountDownLatch)37 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)29 BytesContentProvider (org.eclipse.jetty.client.util.BytesContentProvider)28 Test (org.testng.annotations.Test)28 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)27