List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:com.questdb.test.tools.HttpTestUtils.java
public static HttpClientBuilder clientBuilder(boolean ssl) throws Exception { return (ssl ? createHttpClient_AcceptsUntrustedCerts() : HttpClientBuilder.create()); }
From source file:v2.service.generic.library.utils.HttpClientUtil.java
public static HttpClient createHttpClientWithAuth(String credential, String principle) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(credential, principle); provider.setCredentials(AuthScope.ANY, credentials); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10 * 1000).build(); CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider) .setDefaultRequestConfig(requestConfig).build(); return httpclient; }
From source file:org.ligoj.app.http.security.RestAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) { final String userpassword = StringUtils.defaultString(authentication.getCredentials().toString(), ""); final String userName = StringUtils.lowerCase(authentication.getPrincipal().toString()); // First get the cookie final HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()); final HttpPost httpPost = new HttpPost(getSsoPostUrl()); // Do the POST try (CloseableHttpClient httpClient = clientBuilder.build()) { final String content = String.format(getSsoPostContent(), userName, userpassword); httpPost.setEntity(new StringEntity(content, StandardCharsets.UTF_8)); httpPost.setHeader("Content-Type", "application/json"); final HttpResponse httpResponse = httpClient.execute(httpPost); if (HttpStatus.SC_NO_CONTENT == httpResponse.getStatusLine().getStatusCode()) { // Succeed authentication, save the cookies data inside the authentication return newAuthentication(userName, userpassword, authentication, httpResponse); }// w ww . jav a2 s .c o m log.info("Failed authentication of {}[{}] : {}", userName, userpassword.length(), httpResponse.getStatusLine().getStatusCode()); httpResponse.getEntity().getContent().close(); } catch (final IOException e) { log.warn("Remote SSO server is not available", e); } throw new BadCredentialsException("Invalid user or password"); }
From source file:br.com.jbugbrasil.bot.telegram.api.httpclient.BotCloseableHttpClient.java
@Override public CloseableHttpClient get() { return HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setConnectionTimeToLive(70, TimeUnit.SECONDS).setMaxConnTotal(100).build(); }
From source file:eu.redzoo.article.javaworld.stability.RestServicesTest.java
@BeforeClass public static void setUp() throws Exception { server = new Tomcat(); server.setPort(9080);/*from w w w.j a va2 s . c o m*/ server.addWebapp("/service", new File("src/main/resources/webapp").getAbsolutePath()); server.start(); ClientConfig clientConfig = new ClientConfig(); // jersey specific clientConfig.connectorProvider(new ApacheConnectorProvider()); // jersey specific RequestConfig reqConfig = RequestConfig.custom() // apache HttpClient specific .build(); clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, reqConfig); // jersey specific client = ClientBuilder.newClient(clientConfig); HttpClientBuilder.create().setMaxConnPerRoute(30).setMaxConnTotal(150).setDefaultRequestConfig(reqConfig) .build(); }
From source file:org.keycloak.testsuite.saml.ConcurrentAuthnRequestTest.java
private static void loginRepeatedly(UserRepresentation user, URI samlEndpoint, Document samlRequest, String relayState, Binding requestBinding) { CloseableHttpResponse response = null; SamlClient.RedirectStrategyWithSwitchableFollowRedirect strategy = new SamlClient.RedirectStrategyWithSwitchableFollowRedirect(); ExecutorService threadPool = Executors.newFixedThreadPool(CONCURRENT_THREADS); try (CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(strategy).build()) { HttpUriRequest post = requestBinding.createSamlUnsignedRequest(samlEndpoint, relayState, samlRequest); Collection<Callable<Void>> futures = new LinkedList<>(); for (int i = 0; i < ITERATIONS; i++) { final int j = i; Callable<Void> f = () -> { performLogin(post, samlEndpoint, relayState, samlRequest, response, client, user, strategy); return null; };/*from ww w. j a va 2s .c o m*/ futures.add(f); } threadPool.invokeAll(futures); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.glaf.core.util.http.HttpClientUtils.java
/** * ??GET//from www .j a v a 2s .c o m * * @param url * ?? * @param encoding * * @param dataMap * ? * * @return */ public static String doGet(String url, String encoding, Map<String, String> dataMap) { StringBuffer buffer = new StringBuffer(); HttpGet httpGet = null; InputStreamReader is = null; BufferedReader reader = null; BasicCookieStore cookieStore = new BasicCookieStore(); HttpClientBuilder builder = HttpClientBuilder.create(); CloseableHttpClient client = builder.setDefaultCookieStore(cookieStore).build(); try { if (dataMap != null && !dataMap.isEmpty()) { StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> entry : dataMap.entrySet()) { String name = entry.getKey().toString(); String value = entry.getValue(); sb.append("&").append(name).append("=").append(value); } if (StringUtils.contains(url, "?")) { url = url + sb.toString(); } else { url = url + "?xxxx=1" + sb.toString(); } } httpGet = new HttpGet(url); HttpResponse response = client.execute(httpGet); HttpEntity entity = response.getEntity(); is = new InputStreamReader(entity.getContent(), encoding); reader = new BufferedReader(is); String tmp = reader.readLine(); while (tmp != null) { buffer.append(tmp); tmp = reader.readLine(); } } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { IOUtils.closeStream(reader); IOUtils.closeStream(is); if (httpGet != null) { httpGet.releaseConnection(); } try { client.close(); } catch (IOException ex) { } } return buffer.toString(); }
From source file:com.sandopolus.yeildify.service1.resources.RamdomResourceImpl.java
@PostConstruct public void init() { RAND = new SecureRandom(); JSON_MAPPER = new ObjectMapper(); HTTP_CLIENT = HttpClientBuilder.create().build(); }
From source file:net.acesinc.data.json.generator.log.HttpPostLogger.java
public HttpPostLogger(Map<String, Object> props) throws NoSuchAlgorithmException { this.url = (String) props.get(URL_PROP_NAME); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(SSLContext.getDefault(), new NoopHostnameVerifier()); this.httpClient = HttpClientBuilder.create().setSSLSocketFactory(sf).build(); }
From source file:nl.mineleni.cbsviewer.jsp.JSPIntegrationTest.java
/** * init XMLUnit.//from ww w . ja v a2 s . c om * * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { // XMLUnit.setIgnoreWhitespace(false); // XMLUnit.setIgnoreAttributeOrder(true); // XMLUnit.setIgnoreComments(true); // XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); client = HttpClientBuilder.create().build(); validatorclient = HttpClients.createSystem(); }