List of usage examples for org.apache.http.impl.client SystemDefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:org.cloudifysource.quality.iTests.test.cli.cloudify.util.NewRestTestUtils.java
public static HttpResponse sendGetRequest(final String uri) throws IOException { final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient(); final HttpGet request = new HttpGet(uri); return httpClient.execute(request); }
From source file:de.badw.strauss.glyphpicker.controller.bitmap.BitmapUrlLoader.java
/** * Gets an image from a URL.//from w ww.j a v a2 s . c o m * * @param url the url * @return the image from the url */ public BufferedImage getImageFromUrl(String url) { SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient(); try { HttpGet httpGet = new HttpGet(url); HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); byte[] bytes = EntityUtils.toByteArray(entity); return ImageIO.read(new ByteArrayInputStream(bytes)); } else { throw new IOException( "Download failed, HTTP response code " + statusCode + " - " + statusLine.getReasonPhrase()); } } catch (IOException e) { LOGGER.warn("Error loading image from \"" + url + "\". " + e.getMessage()); } finally { httpClient.getConnectionManager().shutdown(); } return null; }
From source file:org.geomajas.layer.common.proxy.LayerHttpServiceImpl.java
public InputStream getStream(final String baseUrl, final LayerAuthentication authentication, final String layerId) throws IOException { // Create a HTTP client object, which will initiate the connection: final HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT); SystemDefaultHttpClient client = new SystemDefaultHttpClient(httpParams); String url = addCredentialsToUrl(baseUrl, authentication); // -- add basic authentication if (null != authentication && (LayerAuthenticationMethod.BASIC.equals(authentication.getAuthenticationMethod()) || LayerAuthenticationMethod.DIGEST.equals(authentication.getAuthenticationMethod()))) { // Set up the credentials: Credentials creds = new UsernamePasswordCredentials(authentication.getUser(), authentication.getPassword()); AuthScope scope = new AuthScope(parseDomain(url), parsePort(url), authentication.getRealm()); client.getCredentialsProvider().setCredentials(scope, creds); }//from w w w.ja va 2 s .c o m // -- add interceptors if any -- addInterceptors(client, baseUrl, layerId); // Create the GET method with the correct URL: HttpGet get = new HttpGet(url); // Execute the GET: HttpResponse response = client.execute(get); log.debug("Response: {} - {}", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); return new LayerHttpServiceStream(response, client); }