List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:org.fcrepo.examples.models.integration.ExampleNodeTypesIT.java
public ExampleNodeTypesIT() { connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(Integer.MAX_VALUE); connectionManager.setDefaultMaxPerRoute(20); connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); client = HttpClientBuilder.create().setConnectionManager(connectionManager).build(); modelSetsDirectory = new File(modelSetsPath); if (!modelSetsDirectory.exists()) { throw new Error("Cannot find model sets"); }//from ww w .ja v a 2s . c o m }
From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurer.java
protected HttpClientConfigurer(URI targetHost) { httpClientBuilder = HttpClientBuilder.create(); this.targetHost = new HttpHost(targetHost.getHost(), targetHost.getPort(), targetHost.getScheme()); }
From source file:edu.chalmers.dat076.moviefinder.service.TraktHandler.java
public TraktHandler() { httpClient = HttpClientBuilder.create().build(); }
From source file:org.everit.authentication.cas.ecm.tests.SecureHttpClient.java
/** * Constructor./*from www.j a va 2s .c om*/ */ public SecureHttpClient(final String principal, final BundleContext bundleContext) throws Exception { this.principal = principal; httpClientContext = HttpClientContext.create(); httpClientContext.setCookieStore(new BasicCookieStore()); KeyStore trustStore = KeyStore.getInstance("jks"); trustStore.load(bundleContext.getBundle().getResource("/jetty-keystore").openStream(), "changeit".toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(trustStore); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, trustManagers, new SecureRandom()); httpClient = HttpClientBuilder.create().setSslcontext(sslContext) .setRedirectStrategy(new DefaultRedirectStrategy()).build(); }
From source file:org.wisdom.test.http.Options.java
/** * Refreshes the options, and restores defaults. *///from w w w . j ava 2s . co m public static void refresh() { // Load timeouts Object connectionTimeout = Options.getOption(Option.CONNECTION_TIMEOUT); if (connectionTimeout == null) { connectionTimeout = CONNECTION_TIMEOUT; } Object socketTimeout = Options.getOption(Option.SOCKET_TIMEOUT); if (socketTimeout == null) { socketTimeout = SOCKET_TIMEOUT; } // Create common default configuration final BasicCookieStore store = new BasicCookieStore(); RequestConfig clientConfig = RequestConfig.custom() .setConnectTimeout(((Long) connectionTimeout).intValue() * TimeUtils.TIME_FACTOR) .setSocketTimeout(((Long) socketTimeout).intValue() * TimeUtils.TIME_FACTOR) .setConnectionRequestTimeout(((Long) socketTimeout).intValue() * TimeUtils.TIME_FACTOR) .setCookieSpec(CookieSpecs.STANDARD).build(); // Create clients setOption(Option.HTTPCLIENT, HttpClientBuilder.create().setDefaultRequestConfig(clientConfig) .setDefaultCookieStore(store).build()); setOption(Option.COOKIES, store); CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig) .setDefaultCookieStore(store).build(); setOption(Option.ASYNCHTTPCLIENT, asyncClient); }
From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.utils.HttpSolrClientUtils.java
/** * Creates the {@link HttpClient} to use with the Solrj * * @param url the Solr server url// w w w .ja v a 2 s. co m * @param username the {@link RetrieveAndRank} service username * @param password the {@link RetrieveAndRank} service password * @return the {@link HttpClient} */ public static HttpClient createHttpClient(String url, String username, String password) { URI scopeUri = URI.create(url); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(scopeUri.getHost(), scopeUri.getPort()), new UsernamePasswordCredentials(username, password)); HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig( RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()) .setDefaultCredentialsProvider(credentialsProvider) .addInterceptorFirst(new PreemptiveAuthInterceptor()); return builder.build(); }
From source file:gui.WvWMatchReader.java
@Override public void run() { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10 * 1000).build(); HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); //HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("https://api.guildwars2.com/v1/wvw/matches.json"); HttpResponse response;//from w w w. j a v a 2 s . co m String line = ""; String out = ""; while (!this.isInterrupted()) { try { response = client.execute(request); if ((response.getStatusLine().toString().contains("200"))) { BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8"))); line = ""; out = ""; while ((line = rd.readLine()) != null) { out = out + line; } JSONParser parser = new JSONParser(); Object obj; this.result.clear(); try { obj = parser.parse(out); JSONObject obj2 = (JSONObject) obj; JSONArray array = (JSONArray) obj2.get("wvw_matches"); for (int i = 0; i < array.size(); i++) { obj2 = (JSONObject) array.get(i); this.result.put("" + obj2.get("wvw_match_id"), new String[] { "" + obj2.get("red_world_id"), "" + obj2.get("blue_world_id"), "" + obj2.get("green_world_id") }); } request.releaseConnection(); this.wvwCheckBox.setEnabled(true); this.interrupt(); } catch (ParseException ex) { try { Logger.getLogger(ApiManager.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex1) { Logger.getLogger(WvWMatchReader.class.getName()).log(Level.SEVERE, null, ex1); } } } else { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, "Connection error."); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex) { Logger.getLogger(HomeWorldAllReader.class.getName()).log(Level.SEVERE, null, ex); this.interrupt(); } } } catch (IOException | IllegalStateException ex) { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex1) { Logger.getLogger(HomeWorldAllReader.class.getName()).log(Level.SEVERE, null, ex1); this.interrupt(); } } } }
From source file:demo.web.giveSomeKarma.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w. jav a 2s.c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet giveSomeKarma</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet giveSomeKarma at " + request.getContextPath() + "</h1>"); String addresse = "http://localhost:8090/api"; JSONObject jsonLogin = new JSONObject(); jsonLogin.put("name", "MyTest"); jsonLogin.put("password", "password"); HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead HttpPost requestHttpPostLogin; requestHttpPostLogin = new HttpPost(addresse + "/login"); StringEntity paramsLogin = new StringEntity(jsonLogin.toString()); requestHttpPostLogin.addHeader("content-type", "application/json"); requestHttpPostLogin.setEntity(paramsLogin); HttpResponse responseHttpResponse = httpClient.execute(requestHttpPostLogin); HttpEntity entity = responseHttpResponse.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); out.print(responseString); JSONObject obj = new JSONObject(responseString); out.println("mytoken : " + obj.getString("token")); //John //getID PS /*HttpClient httpClientGet = HttpClientBuilder.create().build(); //Use this instead HttpGet requestHttpGetPSID; requestHttpGetPSID = new HttpGet(addresse+"/pointScales"); requestHttpGetPSID.addHeader("Accept", ""); requestHttpGetPSID.addHeader("token", obj.getString("token")); HttpResponse responseHttpResponseGet = httpClientGet.execute(requestHttpGetPSID); HttpEntity entityGet = responseHttpResponseGet.getEntity(); out.println("<p> entityGet.getContent() -> " + entityGet.getContent()); String json_string = EntityUtils.toString(responseHttpResponseGet.getEntity()); out.println("<p> json_string " + json_string); JSONArray temp1 = new JSONArray(json_string); JSONObject objGET = null; for(int n = 0; n < temp1.length(); n++) { objGET = (JSONObject) temp1.get(n); out.println("name " + objGET.getString("name")); //John out.println("id" + objGET.getString("id")); //John } //out.println("name :" + objGet.getString("name")); //Joh int id = Integer.parseInt(objGET.getString("id")); */ // Creation de l'event JSONObject jsonRules = new JSONObject(); jsonRules.put("awardBadgeId", 0); jsonRules.put("awardPointScaleId", 23); jsonRules.put("eventType", "player is kind"); jsonRules.put("point", 100); HttpClient httpClientRules = HttpClientBuilder.create().build(); //Use this instead HttpPost requestHttpPostRules; requestHttpPostRules = new HttpPost(addresse + "/rules"); StringEntity paramsRules = new StringEntity(jsonRules.toString()); requestHttpPostRules.addHeader("content-type", "application/json"); requestHttpPostRules.addHeader("token", obj.getString("token")); requestHttpPostRules.setEntity(paramsRules); HttpResponse responseHttpResponseRules = httpClientRules.execute(requestHttpPostRules); // Ceation de l'event JSONObject jsonPS = new JSONObject(); jsonPS.put("eventType", "player is kind"); jsonPS.put("userAppId", 5); HttpClient httpClientPS = HttpClientBuilder.create().build(); //Use this instead HttpPost requestHttpPostPS; requestHttpPostPS = new HttpPost(addresse + "/events"); StringEntity paramsPS = new StringEntity(jsonPS.toString()); requestHttpPostPS.addHeader("content-type", "application/json"); requestHttpPostPS.addHeader("token", obj.getString("token")); requestHttpPostPS.setEntity(paramsPS); HttpResponse responseHttpResponsePS = httpClientPS.execute(requestHttpPostPS); //getID PS HttpClient httpClientGet = HttpClientBuilder.create().build(); //Use this instead HttpGet requestHttpGetPSID; requestHttpGetPSID = new HttpGet(addresse + "/users/awards"); requestHttpGetPSID.addHeader("Accept", ""); requestHttpGetPSID.addHeader("token", obj.getString("token")); HttpResponse responseHttpResponseGet = httpClientGet.execute(requestHttpGetPSID); HttpEntity entityGet = responseHttpResponseGet.getEntity(); out.println("<p> entityGet.getContent() -> " + entityGet.getContent()); String json_string = EntityUtils.toString(responseHttpResponseGet.getEntity()); out.println("<p> json_string " + json_string); JSONArray temp1 = new JSONArray(json_string); JSONObject objGET = null; for (int n = 0; n < temp1.length(); n++) { objGET = (JSONObject) temp1.get(n); //out.println("name " + objGET.getString("name")); //John out.println("id" + objGET.getString("id")); //John JSONArray awardList = new JSONArray(objGET.getString("awardList")); for (int m = 0; m < awardList.length(); m++) { objGET = (JSONObject) awardList.get(m); out.println("<p> awardType" + objGET.getString("awardType")); out.println("<p>awardDate" + objGET.getString("awardDate")); out.println("<p>"); //out.println("awardType" + objGET.getString("awardType")); } out.println("<p>"); } //out.println("name :" + objGet.getString("name")); //Joh int id = Integer.parseInt(objGET.getString("id")); out.println("</body>"); out.println("</html>"); } }
From source file:tech.sirwellington.alchemy.http.AlchemyHttp.java
/** * Creates a new {@link AlchemyHttp} using the default settings for the {@linkplain HttpClient Apache HTTP Client} * and a {@linkplain Executors#newWorkStealingPool(int) Single-Threaded Executor} for Async requests. * * @return//from w w w . jav a 2 s . c om */ static AlchemyHttp newDefaultInstance() { HttpClient apacheHttpClient = HttpClientBuilder.create().build(); return newInstanceWithApacheHttpClient(apacheHttpClient); }