Search in sources :

Example 91 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project coprhd-controller by CoprHD.

the class WinRMTarget method sendMessage.

public String sendMessage(String request) throws WinRMException {
    try {
        HttpPost post = new HttpPost(getUrl().toExternalForm());
        post.setEntity(new StringEntity(request, SOAP));
        HttpHost targetHost = new HttpHost(getHost(), getPort(), getProtocol());
        CloseableHttpClient client = getClient();
        HttpContext context = getContext();
        HttpResponse response = client.execute(targetHost, post, context);
        String text = EntityUtils.toString(response.getEntity());
        if (response.getStatusLine().getStatusCode() != 200) {
            handleError(response, text);
        }
        return text;
    } catch (WinRMException e) {
        throw e;
    } catch (Exception e) {
        throw new WinRMException(e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpHost(org.apache.http.HttpHost) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) MalformedURLException(java.net.MalformedURLException)

Example 92 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project telegram-notifications-plugin by jenkinsci.

the class TelegramBot method initializeProxy.

private void initializeProxy() {
    try {
        HttpHost proxy = getProxy();
        httpclient = getHttpClient(proxy);
        requestConfig = getRequestConfig(proxy);
        getOptions().setRequestConfig(requestConfig);
        LOG.log(Level.INFO, "Proxy successfully initialized");
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "TelegramBot: Failed to set proxy", e);
    }
}
Also used : HttpHost(org.apache.http.HttpHost) IOException(java.io.IOException)

Example 93 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project pancm_project by xuwujing.

the class IpHandler method build.

/**
 * 创建链接
 *
 * @param nodes
 * @return
 */
public static RestHighLevelClient build(String... nodes) {
    Objects.requireNonNull(nodes, "hosts can not null");
    ArrayList<HttpHost> ahosts = new ArrayList<HttpHost>();
    for (String host : nodes) {
        IpHandler addr = new IpHandler();
        addr.IpPortFromUrl(host);
        ahosts.add(new HttpHost(addr.getIp(), addr.getPort()));
    }
    httpHosts = ahosts.toArray(new HttpHost[0]);
    return init();
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 94 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project pancm_project by xuwujing.

the class EsScriptSearchTest method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 95 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project sling-org-apache-sling-testing-clients by apache.

the class FormBasedAuthInterceptor method doLogin.

private void doLogin(HttpRequest request, HttpContext context) throws IOException {
    // get host
    final HttpHost host = HttpClientContext.adapt(context).getTargetHost();
    // get the username and password from the credentials provider
    final CredentialsProvider credsProvider = HttpClientContext.adapt(context).getCredentialsProvider();
    final AuthScope scope = new AuthScope(host.getHostName(), host.getPort());
    final String username = credsProvider.getCredentials(scope).getUserPrincipal().getName();
    final String password = credsProvider.getCredentials(scope).getPassword();
    List<NameValuePair> parameters = new LinkedList<>();
    parameters.add(new BasicNameValuePair("j_username", username));
    parameters.add(new BasicNameValuePair("j_password", password));
    HttpEntity httpEntity = new UrlEncodedFormEntity(parameters, "utf-8");
    URI loginURI = URI.create(request.getRequestLine().getUri()).resolve(loginPath);
    HttpPost loginPost = new HttpPost(loginURI);
    loginPost.setEntity(httpEntity);
    try (CloseableHttpClient client = HttpClientBuilder.create().setServiceUnavailableRetryStrategy(new ServerErrorRetryStrategy()).disableRedirectHandling().build()) {
        try (CloseableHttpResponse response = client.execute(host, loginPost, context)) {
            StatusLine sl = response.getStatusLine();
            if (sl.getStatusCode() >= 400) {
                LOG.error("Got error login response code {} from '{}'", sl.getStatusCode(), loginURI.toString());
                LOG.error("Dumping headers: ");
                for (Header header : response.getAllHeaders()) {
                    LOG.error("\t '{}' = '{}'", header.getName(), header.getValue());
                }
                try (InputStream inputStream = response.getEntity().getContent()) {
                    String responseText = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
                    LOG.error("Error response body was : '{}'", responseText);
                }
            } else if (getLoginCookie(context, loginTokenName) == null) {
                LOG.error("Login response {} from '{}' did not include cookie '{}'.", sl.getStatusCode(), loginURI.toString(), loginTokenName);
            } else {
                LOG.debug("Login response {} from '{}'", sl.getStatusCode(), loginURI.toString());
            }
        }
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) ServerErrorRetryStrategy(org.apache.sling.testing.clients.util.ServerErrorRetryStrategy) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) CredentialsProvider(org.apache.http.client.CredentialsProvider) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URI(java.net.URI) LinkedList(java.util.LinkedList) StatusLine(org.apache.http.StatusLine) Header(org.apache.http.Header) HttpHost(org.apache.http.HttpHost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) AuthScope(org.apache.http.auth.AuthScope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader)

Aggregations

HttpHost (org.apache.http.HttpHost)598 IOException (java.io.IOException)111 CredentialsProvider (org.apache.http.client.CredentialsProvider)105 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)102 HttpResponse (org.apache.http.HttpResponse)101 AuthScope (org.apache.http.auth.AuthScope)101 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)99 Test (org.junit.Test)86 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)84 URI (java.net.URI)68 HttpGet (org.apache.http.client.methods.HttpGet)66 HttpRequest (org.apache.http.HttpRequest)60 Header (org.apache.http.Header)56 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)56 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)48 HttpEntity (org.apache.http.HttpEntity)47 RequestConfig (org.apache.http.client.config.RequestConfig)45 BasicScheme (org.apache.http.impl.auth.BasicScheme)45 URISyntaxException (java.net.URISyntaxException)44 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)43