Search in sources :

Example 21 with HttpHost

use of org.apache.http.HttpHost in project elasticsearch by elastic.

the class RestClientBuilderTests method testBuild.

public void testBuild() throws IOException {
    try {
        RestClient.builder((HttpHost[]) null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("hosts must not be null", e.getMessage());
    }
    try {
        RestClient.builder();
        fail("should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals("no hosts provided", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200), null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("host cannot be null", e.getMessage());
    }
    try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) {
        assertNotNull(restClient);
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setMaxRetryTimeoutMillis(randomIntBetween(Integer.MIN_VALUE, 0));
        fail("should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals("maxRetryTimeoutMillis must be greater than 0", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setDefaultHeaders(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("defaultHeaders must not be null", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setDefaultHeaders(new Header[] { null });
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("default header must not be null", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setFailureListener(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("failureListener must not be null", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setHttpClientConfigCallback(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("httpClientConfigCallback must not be null", e.getMessage());
    }
    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setRequestConfigCallback(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("requestConfigCallback must not be null", e.getMessage());
    }
    int numNodes = randomIntBetween(1, 5);
    HttpHost[] hosts = new HttpHost[numNodes];
    for (int i = 0; i < numNodes; i++) {
        hosts[i] = new HttpHost("localhost", 9200 + i);
    }
    RestClientBuilder builder = RestClient.builder(hosts);
    if (randomBoolean()) {
        builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {

            @Override
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                return httpClientBuilder;
            }
        });
    }
    if (randomBoolean()) {
        builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {

            @Override
            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                return requestConfigBuilder;
            }
        });
    }
    if (randomBoolean()) {
        int numHeaders = randomIntBetween(1, 5);
        Header[] headers = new Header[numHeaders];
        for (int i = 0; i < numHeaders; i++) {
            headers[i] = new BasicHeader("header" + i, "value");
        }
        builder.setDefaultHeaders(headers);
    }
    if (randomBoolean()) {
        builder.setMaxRetryTimeoutMillis(randomIntBetween(1, Integer.MAX_VALUE));
    }
    if (randomBoolean()) {
        String pathPrefix = (randomBoolean() ? "/" : "") + randomAsciiOfLengthBetween(2, 5);
        while (pathPrefix.length() < 20 && randomBoolean()) {
            pathPrefix += "/" + randomAsciiOfLengthBetween(3, 6);
        }
        builder.setPathPrefix(pathPrefix + (randomBoolean() ? "/" : ""));
    }
    try (RestClient restClient = builder.build()) {
        assertNotNull(restClient);
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) BasicHeader(org.apache.http.message.BasicHeader) Header(org.apache.http.Header) HttpHost(org.apache.http.HttpHost) BasicHeader(org.apache.http.message.BasicHeader)

Example 22 with HttpHost

use of org.apache.http.HttpHost in project pinot by linkedin.

the class SegmentPushControllerAPIs method deleteOverlappingSegments.

public void deleteOverlappingSegments(String tableName, String segmentName) throws IOException {
    if (segmentName.contains(DAILY_SCHEDULE)) {
        for (String controllerHost : controllerHosts) {
            controllerHttpHost = new HttpHost(controllerHost, controllerPort);
            LOGGER.info("Getting overlapped segments for {}*************", segmentName);
            List<String> overlappingSegments = getOverlappingSegments(tableName, segmentName);
            if (overlappingSegments.isEmpty()) {
                LOGGER.info("No overlapping segments found");
            } else {
                LOGGER.info("Deleting overlapped segments****************");
                deleteOverlappingSegments(tableName, overlappingSegments);
            }
        }
    } else {
        LOGGER.info("No overlapping segments to delete for HOURLY");
    }
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 23 with HttpHost

use of org.apache.http.HttpHost in project android_frameworks_base by ParanoidAndroid.

the class ProxyTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mContext = getContext();
    mHttpHost = null;
    String proxyHost = Proxy.getHost(mContext);
    int proxyPort = Proxy.getPort(mContext);
    if (proxyHost != null) {
        mHttpHost = new HttpHost(proxyHost, proxyPort, "http");
    }
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 24 with HttpHost

use of org.apache.http.HttpHost in project android_frameworks_base by ParanoidAndroid.

the class RequestQueue method dump.

/**
     * debug tool: prints request queue to log
     */
synchronized void dump() {
    HttpLog.v("dump()");
    StringBuilder dump = new StringBuilder();
    int count = 0;
    Iterator<Map.Entry<HttpHost, LinkedList<Request>>> iter;
    if (!mPending.isEmpty()) {
        iter = mPending.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<HttpHost, LinkedList<Request>> entry = iter.next();
            String hostName = entry.getKey().getHostName();
            StringBuilder line = new StringBuilder("p" + count++ + " " + hostName + " ");
            LinkedList<Request> reqList = entry.getValue();
            ListIterator reqIter = reqList.listIterator(0);
            while (iter.hasNext()) {
                Request request = (Request) iter.next();
                line.append(request + " ");
            }
            dump.append(line);
            dump.append("\n");
        }
    }
    HttpLog.v(dump.toString());
}
Also used : HttpHost(org.apache.http.HttpHost) ListIterator(java.util.ListIterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 25 with HttpHost

use of org.apache.http.HttpHost in project android_frameworks_base by ParanoidAndroid.

the class RequestQueue method queueRequest.

protected synchronized void queueRequest(Request request, boolean head) {
    HttpHost host = request.mProxyHost == null ? request.mHost : request.mProxyHost;
    LinkedList<Request> reqList;
    if (mPending.containsKey(host)) {
        reqList = mPending.get(host);
    } else {
        reqList = new LinkedList<Request>();
        mPending.put(host, reqList);
    }
    if (head) {
        reqList.addFirst(request);
    } else {
        reqList.add(request);
    }
}
Also used : HttpHost(org.apache.http.HttpHost)

Aggregations

HttpHost (org.apache.http.HttpHost)579 IOException (java.io.IOException)108 CredentialsProvider (org.apache.http.client.CredentialsProvider)101 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)98 AuthScope (org.apache.http.auth.AuthScope)97 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)95 HttpResponse (org.apache.http.HttpResponse)94 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)82 Test (org.junit.Test)78 URI (java.net.URI)67 HttpGet (org.apache.http.client.methods.HttpGet)66 Header (org.apache.http.Header)56 HttpRequest (org.apache.http.HttpRequest)53 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)52 HttpEntity (org.apache.http.HttpEntity)47 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)47 URISyntaxException (java.net.URISyntaxException)44 RequestConfig (org.apache.http.client.config.RequestConfig)44 BasicScheme (org.apache.http.impl.auth.BasicScheme)44 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)43