List of usage examples for java.net URLConnection setUseCaches
public void setUseCaches(boolean usecaches)
From source file:util.connection.AnonymousClient.java
public String download(URL source) throws IOException { // set the request URL URL request = new URL(source, source.getFile(), handler); // send request and receive response log.info("download (start) from source=" + source); URLConnection connection = request.openConnection(); connection.setDoOutput(true);/*from w w w . ja v a2 s . c om*/ connection.setDoInput(true); connection.setUseCaches(false); connection.setAllowUserInteraction(false); connection.connect(); String responsebody = IOUtils.toString(connection.getInputStream(), "UTF-8"); // read the response netLayer.clear(); netLayer.waitUntilReady(); return responsebody; }
From source file:com.example.m.niceproject.service.YahooWeatherService.java
public void refreshWeather(String location) { new AsyncTask<String, Void, Channel>() { @Override/* w w w . j av a 2 s . c o m*/ protected Channel doInBackground(String[] locations) { String location = locations[0]; Channel channel = new Channel(); String YQL = String.format( "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"%s\")", location); String endpoint = String.format("https://query.yahooapis.com/v1/public/yql?q=%s&format=json", Uri.encode(YQL)); try { URL url = new URL(endpoint); URLConnection connection = url.openConnection(); connection.setUseCaches(false); InputStream inputStream = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line); } JSONObject data = new JSONObject(result.toString()); JSONObject queryResults = data.optJSONObject("query"); int count = queryResults.optInt("count"); if (count == 0) { error = new LocationWeatherException("No weather information found for " + location); return null; } JSONObject channelJSON = queryResults.optJSONObject("results").optJSONObject("channel"); channel.populate(channelJSON); return channel; } catch (Exception e) { error = e; } return null; } @Override protected void onPostExecute(Channel channel) { if (channel == null && error != null) { listener.serviceFailure(error); } else { listener.serviceSuccess(channel); } } }.execute(location); }
From source file:org.jahia.services.render.scripting.bundle.BundleSourceResourceResolver.java
private InputStream getInputStream(URL url) throws IOException { URLConnection con = url.openConnection(); con.setUseCaches(false); try {//from w w w.j a v a 2 s . c om return con.getInputStream(); } catch (IOException ex) { // Close the HTTP connection (if applicable). if (con instanceof HttpURLConnection) { ((HttpURLConnection) con).disconnect(); } throw ex; } }
From source file:org.fingerprintsoft.io.SingletonApplicationPropertiesLocator.java
private InputStream getInputStream(String resourceLocation) throws IOException { InputStream is = null;// w ww. j av a 2s.c om if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { is = this.getClass().getClassLoader() .getResourceAsStream(resourceLocation.substring(CLASSPATH_URL_PREFIX.length())); } if (resourceLocation.startsWith(FILE_URL_PREFIX)) { URL url = new URL(resourceLocation); URLConnection con = url.openConnection(); con.setUseCaches(false); is = con.getInputStream(); } if (is == null) { throw new FileNotFoundException(resourceLocation + " cannot be opened because it does not exist"); } return is; }
From source file:eu.europa.ec.markt.dss.applet.io.NativeHTTPDataLoader.java
@Override public InputStream post(String url, InputStream content) throws CannotFetchDataException { try {//from w w w . ja v a2s . c o m URLConnection connection = new URL(url).openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); OutputStream out = connection.getOutputStream(); IOUtils.copy(content, out); out.close(); return connection.getInputStream(); } catch (IOException ex) { throw new CannotFetchDataException(ex, url); } }
From source file:org.apache.jcs.auxiliary.lateral.http.broadcast.LateralCacheThread.java
/** Description of the Method */ public void writeObj(URLConnection connection, ICacheElement cb) { try {/*from w w w .j a v a 2 s. c o m*/ connection.setUseCaches(false); connection.setRequestProperty("CONTENT_TYPE", "application/octet-stream"); connection.setDoOutput(true); connection.setDoInput(true); ObjectOutputStream os = new ObjectOutputStream(connection.getOutputStream()); log.debug("os = " + os); // Write the ICacheItem to the ObjectOutputStream log.debug("Writing ICacheItem."); os.writeObject(cb); os.flush(); log.debug("closing output stream"); os.close(); } catch (IOException e) { log.error(e); } // end catch }
From source file:com.ocpsoft.pretty.config.PrettyConfigurator.java
/** * Opens an input stream for the given URL. * /*from w w w . j a v a2s . co m*/ * @param url * target URL. * @return Opened input stream. * @throws IOException * If connection could not be opened. */ protected InputStream openStream(final URL url) throws IOException { final URLConnection connection = url.openConnection(); connection.setUseCaches(false); return connection.getInputStream(); }
From source file:org.josso.auth.scheme.validation.CRLX509CertificateValidator.java
public void validate(X509Certificate certificate) throws X509CertificateValidationException { try {/*from ww w. j a v a2 s .com*/ URL crlUrl = null; if (_url != null) { crlUrl = new URL(_url); log.debug("Using the CRL server at: " + _url); } else { log.debug("Using the CRL server specified in the certificate."); System.setProperty("com.sun.security.enableCRLDP", "true"); } // configure the proxy if (_httpProxyHost != null && _httpProxyPort != null) { System.setProperty("http.proxyHost", _httpProxyHost); System.setProperty("http.proxyPort", _httpProxyPort); } else { System.clearProperty("http.proxyHost"); System.clearProperty("http.proxyPort"); } // get certificate path CertPath cp = generateCertificatePath(certificate); // get trust anchors Set<TrustAnchor> trustedCertsSet = generateTrustAnchors(); // init PKIX parameters PKIXParameters params = new PKIXParameters(trustedCertsSet); // activate certificate revocation checking params.setRevocationEnabled(true); // disable OCSP Security.setProperty("ocsp.enable", "false"); // get a certificate revocation list if (crlUrl != null) { URLConnection connection = crlUrl.openConnection(); connection.setDoInput(true); connection.setUseCaches(false); DataInputStream inStream = new DataInputStream(connection.getInputStream()); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509CRL crl = (X509CRL) cf.generateCRL(inStream); inStream.close(); params.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(Collections.singletonList(crl)))); } // perform validation CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); PKIXCertPathValidatorResult cpvResult = (PKIXCertPathValidatorResult) cpv.validate(cp, params); X509Certificate trustedCert = (X509Certificate) cpvResult.getTrustAnchor().getTrustedCert(); if (trustedCert == null) { log.debug("Trsuted Cert = NULL"); } else { log.debug("Trusted CA DN = " + trustedCert.getSubjectDN()); } } catch (CertPathValidatorException e) { log.error(e, e); throw new X509CertificateValidationException(e); } catch (Exception e) { log.error(e, e); throw new X509CertificateValidationException(e); } log.debug("CERTIFICATE VALIDATION SUCCEEDED"); }
From source file:com.sabre.hack.travelachievementgame.DSCommHandler.java
public String getAuthToken(String apiEndPoint, String encodedCliAndSecret) { //receives : apiEndPoint (https://api.test.sabre.com) //encodedCliAndSecret : base64Encode( base64Encode(V1:[user]:[group]:[domain]) + ":" + base64Encode([secret]) ) String strRet = null;/*from w w w. j a va 2 s.co m*/ try { URL urlConn = new URL(apiEndPoint + "/v1/auth/token"); URLConnection conn = urlConn.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Authorization", "Basic " + encodedCliAndSecret); conn.setRequestProperty("Accept", "application/json"); //send request DataOutputStream dataOut = new DataOutputStream(conn.getOutputStream()); dataOut.writeBytes("grant_type=client_credentials"); dataOut.flush(); dataOut.close(); //get response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String strChunk = ""; StringBuilder sb = new StringBuilder(); while (null != ((strChunk = rd.readLine()))) sb.append(strChunk); //parse the token JSONObject respParser = new JSONObject(sb.toString()); strRet = respParser.getString("access_token"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return strRet; }
From source file:org.openmrs.module.ModuleUtil.java
/** * Downloads the contents of a URL and copies them to a string (Borrowed from oreilly) * * @param url/*from ww w . j a v a 2s.co m*/ * @return InputStream of contents * @should return a valid input stream for old module urls */ public static InputStream getURLStream(URL url) { InputStream in = null; try { URLConnection uc = url.openConnection(); uc.setDefaultUseCaches(false); uc.setUseCaches(false); uc.setRequestProperty("Cache-Control", "max-age=0,no-cache"); uc.setRequestProperty("Pragma", "no-cache"); log.debug("Logging an attempt to connect to: " + url); in = openConnectionCheckRedirects(uc); } catch (IOException io) { log.warn("io while reading: " + url, io); } return in; }