List of usage examples for org.apache.http.impl.client HttpClients createDefault
public static CloseableHttpClient createDefault()
From source file:core.VirusTotalAPIHelper.java
public static CloseableHttpResponse getReport(String sha256) { try {/*from w w w . ja va2s. c om*/ CloseableHttpClient client = HttpClients.createDefault(); HttpPost httpsScanFilePost = new HttpPost(httpsPost + "file/report"); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("apikey", apiKey); builder.addTextBody("resource", sha256); HttpEntity multipart = builder.build(); httpsScanFilePost.setEntity(multipart); CloseableHttpResponse response = client.execute(httpsScanFilePost); return response; } catch (IOException ex) { Exceptions.printStackTrace(ex); } return null; }
From source file:org.cleverbus.core.common.contextcall.ContextCallHttpImpl.java
@Override protected void callTargetMethod(String callId, Class<?> targetType, String methodName) { CloseableHttpClient httpClient = HttpClients.createDefault(); try {/*from w w w .j av a 2s . c o m*/ HttpGet httpGet = new HttpGet(localhostUri + RouteConstants.HTTP_URI_PREFIX + ContextCallRoute.SERVLET_URL + "?" + ContextCallRoute.CALL_ID_HEADER + "=" + callId); httpClient.execute(httpGet); } catch (IOException ex) { throw new IllegalStateException("error occurs during calling target method '" + methodName + "' of service type '" + targetType.getSimpleName() + "'", ex); } finally { IOUtils.closeQuietly(httpClient); } }
From source file:sendsms.WebService.java
public String post(String url, NameValuePair... parametros) { String source = null;//w ww .ja va 2 s. c om HttpClient httpClient = HttpClients.createDefault(); RequestBuilder requestBuilder = RequestBuilder.post().setUri(url); for (NameValuePair parametro : parametros) { requestBuilder.addParameter(parametro); } HttpUriRequest uriRequest = requestBuilder.build(); try { HttpResponse httpResponse = httpClient.execute(uriRequest); source = EntityUtils.toString(httpResponse.getEntity()); } catch (IOException e) { e.printStackTrace(); } return source; }
From source file:org.fcrepo.camel.indexing.triplestore.integration.TestUtils.java
/** * Post data to the provided URL//from w w w . java 2 s . com */ public static void httpPost(final String url, final String content, final String mimeType) throws Exception { final CloseableHttpClient httpClient = HttpClients.createDefault(); final HttpPost post = new HttpPost(url); post.addHeader(Exchange.CONTENT_TYPE, mimeType); post.setEntity(new StringEntity(content)); httpClient.execute(post); }
From source file:com.worldsmostinterestinginfographic.util.OAuth2Utils.java
/** * Request an access token from the given token endpoint. * * The token endpoint given must contain all of the required properties necessary for the request. At a minimum, * this will include:/*w w w . j a va 2 s .c o m*/ * * grant_type * code * redirect_uri * client_id * * If the authorization code is valid and the request is successful, the access token value will be parsed from the * response and returned. If the request has failed for any reason, null will be returned. * * @param tokenEndpoint The full token endpoint, with required parameters for making the access token request * @return A valid access token if the request was successful; null otherwise. */ public static String requestAccessToken(String tokenEndpoint) { CloseableHttpClient httpClient = HttpClients.createDefault(); try { // Exchange authorization code for access token HttpPost httpPost = new HttpPost(tokenEndpoint); HttpResponse httpResponse = httpClient.execute(httpPost); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); String line = bufferedReader.readLine(); // Detect error message if (line.toLowerCase().contains("\"error\"")) { log.severe("Fatal exception occurred while making the access token request: " + line); return null; } // Extract access token String accessToken = line.split("&")[0].split("=")[1]; if (StringUtils.isEmpty(accessToken)) { log.severe( "Fatal exception occurred while making the access token request: Access token value in response is empty"); return null; } return accessToken; } catch (Exception e) { log.severe("Fatal exception occurred while making the access token request: " + e.getMessage()); e.printStackTrace(); } finally { try { httpClient.close(); } catch (IOException e) { log.severe("Fatal exception occurred while closing HTTP client connection: " + e.getMessage()); e.printStackTrace(); } } return null; }
From source file:org.fedoraproject.copr.client.impl.DefaultCoprSession.java
public DefaultCoprSession(CoprConfiguration configuration) { this.configuration = configuration; client = HttpClients.createDefault(); }
From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java
public ApacheMethodClient() { clientImpl = HttpClients.createDefault(); }
From source file:net.orzo.data.Web.java
public Web() { this.httpClient = HttpClients.createDefault(); }
From source file:thread.MyThread.java
public void run() { try {//w w w.j av a2 s .co m gate.await(); System.out.println("Run : " + obj.toString()); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Accept-Content Type", acceptType); httpPost.setHeader("Content-type", contentType); httpPost.setEntity(new StringEntity(obj.toString())); long startTime = System.currentTimeMillis(); CloseableHttpResponse httpResponse = httpClient.execute(httpPost); long endTime = System.currentTimeMillis(); time = endTime - startTime; if (httpResponse.getStatusLine().getStatusCode() == 200) { BufferedReader reader = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = reader.readLine()) != null) { response.append(inputLine); } reader.close(); JsonObject jresp = new JsonObject(); Gson gson = new Gson(); jresp = gson.fromJson(response.toString(), JsonObject.class); // JsonElement je = jresp.get("code"); code = jresp.toString(); // System.out.println("Thread - data resp: " + jresp.toString()); } else { System.out.println("API Fail status code = " + httpResponse.getStatusLine().getStatusCode()); // return new DataResponseWithdrawFunds();/ code = "-1"; } } catch (UnsupportedEncodingException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } catch (BrokenBarrierException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.msds.km.service.Impl.YunmaiAPIDrivingLicenseRecognitionServcieiImpl.java
public YunmaiAPIDrivingLicenseRecognitionServcieiImpl() { httpclient = HttpClients.createDefault(); stream = new XStream(); stream.processAnnotations(DrivingLicense.class); }