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);
}
}
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);
}
}
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();
}
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);
}
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());
}
}
}
}
Aggregations