List of usage examples for org.apache.http.protocol BasicHttpContext BasicHttpContext
public BasicHttpContext()
From source file:hu.sztaki.lpds.portal.util.stream.HttpClient.java
/** * Opening the connection/*from w w w . j ava 2s. co m*/ * @param pURL resource URL */ public void open(String pURL) { httpclient = new DefaultHttpClient(); cookieStore = new BasicCookieStore(); localContext = new BasicHttpContext(); httpPost = new HttpPost(pURL); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:org.deegree.maven.utils.HttpUtils.java
public static HttpClient getAuthenticatedHttpClient(ServiceIntegrationTestHelper helper) { DefaultHttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 30000); HttpConnectionParams.setSoTimeout(client.getParams(), 1200000); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("deegree", "deegree")); // preemptive authentication used to be easier in pre-4.x httpclient AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); HttpHost host = new HttpHost("localhost", Integer.parseInt(helper.getPort())); authCache.put(host, basicAuth);/*www . jav a 2s . c o m*/ BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(AUTH_CACHE, authCache); return client; }
From source file:tk.jomp16.plugin.cyanogenmod.download.Download.java
public void download(CommandEvent commandEvent) throws IOException { if (commandEvent.getArgs().size() >= 1) { System.out.println(commandEvent.getArgs()); DeviceInfo deviceInfo = Device.getDevices().get(commandEvent.getArgs().get(0)); if (deviceInfo != null) { HttpPost httpPost = new HttpPost(CM_DOWNLOAD_API); StringEntity json = new StringEntity(gson.toJson(new CMApiRequest(deviceInfo.getCodename()))); json.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPost.setEntity(json);/*from ww w . ja va 2 s . c om*/ CloseableHttpClient httpClient = HttpClients.createDefault(); HttpContext context = new BasicHttpContext(); HttpResponse response = httpClient.execute(httpPost, context); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { return; } DownloadInfo downloadInfo; try (BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent()))) { downloadInfo = gson.fromJson(reader, DownloadInfo.class); } if (downloadInfo.result.size() > 0) { DownloadInfo.Result latest = downloadInfo.result.get(0); commandEvent.respond("Latest build (" + latest.channel + ") for " + deviceInfo.getCodename() + ": " + latest.url + " [md5sum: " + latest.md5sum + "]"); } else { commandEvent.respond("No builds for " + deviceInfo.getCodename()); } } } }
From source file:com.strato.hidrive.api.HttpClientManager.java
public HttpContext getLocalHttpContext() { if (localHttpContext == null) { CookieStore cookieStore = new BasicCookieStore(); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }/*from ww w. j a va2 s . c o m*/ return localHttpContext; }
From source file:com.nebkat.plugin.xkcd.XKCDPlugin.java
@EventHandler @CommandFilter("xkcd") public void onCommand(CommandEvent e) { String url = String.format(XKCD_API_URL, Utils.indexOrDefault(e.getParams(), 0, "")); HttpGet get = new HttpGet(url); // Execute the request HttpContext context = new BasicHttpContext(); HttpResponse response;/*from w ww . j a v a 2 s.co m*/ try { response = ConnectionManager.getHttpClient().execute(get, context); } catch (IOException ex) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error fetching comic info"); return; } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error fetching comic info"); return; } XKCDResult result; try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) { result = mGson.fromJson(reader, XKCDResult.class); } catch (Exception ex) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error parsing comic info"); return; } Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + result.title + " [" + result.day + "/" + result.month + "/" + result.year + "]: " + result.img + " (" + result.alt + ")"); }
From source file:com.pansapiens.occyd.UrlFetch.java
public void fetch() { String response = ""; Message msg = Message.obtain();/* w ww. j a va2 s.co m*/ msg.what = 0; msg.obj = "empty"; try { // create an http client with a get request // for our url HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(url.toString()); // set the User-Agent List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("User-Agent", USER_AGENT)); httpClient.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, headers); // execute the request HttpResponse resp = httpClient.execute(httpGet, localContext); BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); String inputLine; response = ""; while ((inputLine = in.readLine()) != null) response += inputLine; in.close(); msg.what = 1; msg.obj = response; } catch (IOException e) { msg.what = 0; msg.obj = "io exception : " + url.toString(); } finally { handler.sendMessage(msg); } }
From source file:com.aikidonord.utils.HttpRequest.java
public HttpRequest() { HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, 10000); HttpConnectionParams.setSoTimeout(myParams, 10000); httpClient = new DefaultHttpClient(myParams); localContext = new BasicHttpContext(); }
From source file:org.semanticscience.PDBAptamerRetriever.shared.URLReader.java
public URLReader(String scheme, String host, String path, String query) { cookieStore = new BasicCookieStore(); localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); contents = this.getStringFromURLGET(scheme, host, path, query); }
From source file:org.tinymediamanager.scraper.util.StreamingUrl.java
/** * get the InputStream of the content. Be aware: using this class needs you to close the connection per hand calling the method closeConnection() * // w w w.jav a 2s. c o m * @return the InputStream of the content */ @Override public InputStream getInputStream() throws IOException { // workaround for local files if (url.startsWith("file:")) { String newUrl = url.replace("file:", ""); File file = new File(newUrl); return new FileInputStream(file); } BasicHttpContext localContext = new BasicHttpContext(); // replace our API keys for logging... String logUrl = url.replaceAll("api_key=\\w+", "api_key=<API_KEY>").replaceAll("api/\\d+\\w+", "api/<API_KEY>"); LOGGER.debug("getting " + logUrl); HttpGet httpget = new HttpGet(url); RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000) .build(); httpget.setConfig(requestConfig); // set custom headers for (Header header : headersRequest) { httpget.addHeader(header); } try { response = client.execute(httpget, localContext); headersResponse = response.getAllHeaders(); entity = response.getEntity(); responseStatus = response.getStatusLine(); if (entity != null) { return entity.getContent(); } } catch (UnknownHostException e) { LOGGER.error("proxy or host not found/reachable", e); } catch (Exception e) { LOGGER.error("Exception getting url " + logUrl, e); } return new ByteArrayInputStream("".getBytes()); }