use of org.eclipse.jetty.client.HttpClient 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;
}
use of org.eclipse.jetty.client.HttpClient in project elastic-job by dangdangdotcom.
the class RestfulServerTest method sentRequest.
private static ContentExchange sentRequest(final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange result = new ContentExchange();
result.setMethod("POST");
result.setRequestContentType(MediaType.APPLICATION_JSON);
result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
result.setURL(URL);
httpClient.send(result);
result.waitForDone();
return result;
} finally {
httpClient.stop();
}
}
use of org.eclipse.jetty.client.HttpClient in project elastic-job by dangdangdotcom.
the class RestfulTestsUtil method sentGetRequest.
public static String sentGetRequest(final String url) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod("GET");
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseContent();
} finally {
httpClient.stop();
}
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class HttpConnectionOverFCGI method acquireBuffer.
private ByteBuffer acquireBuffer() {
HttpClient client = destination.getHttpClient();
ByteBufferPool bufferPool = client.getByteBufferPool();
return bufferPool.acquire(client.getResponseBufferSize(), true);
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class AbstractHttpClientServerTest method start.
public void start(Handler handler) throws Exception {
server = new Server();
ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration());
serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
connector = new ServerConnector(server, null, null, serverBufferPool, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory);
// connector.setPort(9000);
server.addConnector(connector);
server.setHandler(handler);
server.start();
QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client");
client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") {
@Override
public HttpDestination newHttpDestination(Origin origin) {
return new HttpDestinationOverFCGI(client, origin) {
@Override
protected DuplexConnectionPool newConnectionPool(HttpClient client) {
return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) {
@Override
protected void leaked(LeakDetector.LeakInfo leakInfo) {
connectionLeaks.incrementAndGet();
}
};
}
};
}
}, null);
client.setExecutor(executor);
clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
client.setByteBufferPool(clientBufferPool);
client.start();
}
Aggregations