List of usage examples for org.apache.http.client.protocol HttpClientContext create
public static HttpClientContext create()
From source file:com.rometools.test.HttpClientFeedFetcherTest.java
/** * @see com.rometools.rome.fetcher.impl.AbstractJettyTest#getAuthenticatedFeedFetcher() *//*from w w w . j ava 2 s . c o m*/ @Override public FeedFetcher getAuthenticatedFeedFetcher() { HttpClientFeedFetcher fetcher = new HttpClientFeedFetcher(); fetcher.setContextSupplier(new ContextSupplier() { @Override public HttpClientContext getContext(HttpHost host) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username:password")); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); return context; } }); return fetcher; }
From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactory.java
/** * Add AuthCache to the execution context to use preemptive authentication. *///w ww . j av a 2s .co m @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); return context; }
From source file:com.alexkli.jhb.Worker.java
public Worker(CloseableHttpClient httpClient, BlockingQueue<QueueItem<HttpRequestBase>> queue, Jhb.Config config) {/*from w w w . j a v a 2s .com*/ this.httpClient = httpClient; this.context = HttpClientContext.create(); this.queue = queue; this.config = config; }
From source file:com.cloudera.livy.client.http.LivyConnection.java
LivyConnection(URI uri, final HttpConf config) { HttpClientContext ctx = HttpClientContext.create(); int port = uri.getPort() > 0 ? uri.getPort() : 8998; String path = uri.getPath() != null ? uri.getPath() : ""; this.uriRoot = path + "/clients"; RequestConfig reqConfig = new RequestConfig() { @Override//from w ww . j a v a2s.co m public int getConnectTimeout() { return (int) config.getTimeAsMs(CONNETION_TIMEOUT); } @Override public int getSocketTimeout() { return (int) config.getTimeAsMs(SOCKET_TIMEOUT); } }; HttpClientBuilder builder = HttpClientBuilder.create().disableAutomaticRetries().evictExpiredConnections() .evictIdleConnections(config.getTimeAsMs(CONNECTION_IDLE_TIMEOUT), TimeUnit.MILLISECONDS) .setConnectionManager(new BasicHttpClientConnectionManager()) .setConnectionReuseStrategy(new DefaultConnectionReuseStrategy()).setDefaultRequestConfig(reqConfig) .setMaxConnTotal(1).setUserAgent("livy-client-http"); this.server = uri; this.client = builder.build(); this.mapper = new ObjectMapper(); }
From source file:zz.pseas.ghost.client.GhostClient.java
public GhostClient(String charset) { super(); this.charset = charset; context = HttpClientContext.create(); }
From source file:org.xwiki.contrib.repository.npm.internal.NpmExtensionFile.java
public NpmExtensionFile(String packageName, String version, URI uriToDownload, HttpClientFactory httpClientFactory, Environment environment) { this.packageName = packageName; this.version = version; this.uriToDownload = uriToDownload; this.httpClientFactory = httpClientFactory; this.environment = environment; this.localContext = HttpClientContext.create(); }
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java
public void testRelativeLocation() throws Exception { HttpContext context = HttpClientContext.create(); HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/relative")); HttpResponse response = httpClient.execute(request, context); assertTrue(strategy.isRedirected(request, response, context)); HttpUriRequest redirected = strategy.getRedirect(request, response, context); assertEquals(TestConstants.roboHydra.resolve("/new/location"), redirected.getURI()); }
From source file:org.mycontroller.standalone.restclient.RestFactory.java
public T createAPI(URI uri, String userName, String password) { CloseableHttpClient httpclient = HttpClientBuilder.create().build(); HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password)); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache);//from w w w . ja v a 2s . co m ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, context); ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build(); client.register(JacksonJaxbJsonProvider.class); client.register(RequestLogger.class); client.register(ResponseLogger.class); ProxyBuilder<T> proxyBuilder = client.target(uri).proxyBuilder(proxyClazz); return proxyBuilder.build(); }
From source file:org.keycloak.testsuite.saml.ConcurrentAuthnRequestTest.java
public static void performLogin(HttpUriRequest post, URI samlEndpoint, String relayState, Document samlRequest, CloseableHttpResponse response, final CloseableHttpClient client, UserRepresentation user, RedirectStrategyWithSwitchableFollowRedirect strategy) { try {//from w w w. j av a2s .c o m HttpClientContext context = HttpClientContext.create(); response = client.execute(post, context); String loginPageText = EntityUtils.toString(response.getEntity(), "UTF-8"); response.close(); HttpUriRequest loginRequest = LoginBuilder.handleLoginPage(user, loginPageText); strategy.setRedirectable(false); response = client.execute(loginRequest, context); response.close(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (response != null) { EntityUtils.consumeQuietly(response.getEntity()); try { response.close(); } catch (IOException ex) { } } } }
From source file:com.mirth.connect.client.core.ConnectServiceUtil.java
public static void registerUser(String serverId, String mirthVersion, User user, String[] protocols, String[] cipherSuites) throws ClientException { CloseableHttpClient httpClient = null; CloseableHttpResponse httpResponse = null; NameValuePair[] params = { new BasicNameValuePair("serverId", serverId), new BasicNameValuePair("version", mirthVersion), new BasicNameValuePair("user", ObjectXMLSerializer.getInstance().serialize(user)) }; HttpPost post = new HttpPost(); post.setURI(URI.create(URL_CONNECT_SERVER + URL_REGISTRATION_SERVLET)); post.setEntity(new UrlEncodedFormEntity(Arrays.asList(params), Charset.forName("UTF-8"))); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build(); try {/*from w w w. j a va 2 s . c o m*/ HttpClientContext postContext = HttpClientContext.create(); postContext.setRequestConfig(requestConfig); httpClient = getClient(protocols, cipherSuites); httpResponse = httpClient.execute(post, postContext); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) { throw new Exception("Failed to connect to update server: " + statusLine); } } catch (Exception e) { throw new ClientException(e); } finally { HttpClientUtils.closeQuietly(httpResponse); HttpClientUtils.closeQuietly(httpClient); } }