List of usage examples for java.net URLConnection setUseCaches
public void setUseCaches(boolean usecaches)
From source file:at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl.java
private static void loadXAdES14Blacklist() { XADES_1_4_BLACKLIST_TS = System.currentTimeMillis(); XADES_1_4_BLACKLIST.clear();//w ww. j a va 2s . co m try { URLConnection blc = new URL(ConfigurationFacade.XADES_1_4_BLACKLIST_URL).openConnection(); blc.setUseCaches(false); InputStream in = blc.getInputStream(); Scanner s = new Scanner(in); while (s.hasNext()) { XADES_1_4_BLACKLIST.add(s.next()); } s.close(); } catch (Exception e) { log.error("Blacklist load error", e); } }
From source file:com.allblacks.utils.web.HttpUtil.java
private static URLConnection getConnection(URL url) throws IOException { URLConnection urlc; urlc = url.openConnection();//w w w . j a v a 2 s .c o m urlc.setUseCaches(false); urlc.setRequestProperty(HttpUtil.CONTENT_TYPE, "application/x-www-form-urlencoded"); urlc.setRequestProperty(HttpUtil.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100414 Iceweasel/3.5.9 (like Firefox/3.5.9)"); urlc.setRequestProperty(HttpUtil.ACCEPT_ENCODING, HttpUtil.GZIP); return urlc; }
From source file:org.efaps.tests.ci.AbstractCIDataProvider.java
/** * Load ci./*from ww w. j av a2s . c om*/ * * @param _context the context */ @BeforeSuite public static void loadCI(final ITestContext _context) { final File xmlFile = new File(_context.getCurrentXmlTest().getSuite().getFileName()); final String baseFolderRel = _context.getCurrentXmlTest().getParameter("baseFolder"); final String baseFolder = FilenameUtils.concat(xmlFile.getPath(), baseFolderRel); AbstractCIDataProvider.LOG.debug("basefolder: '{}'", baseFolder); final Collection<File> files = FileUtils.listFiles(new File(baseFolder), new String[] { "xml" }, true); for (final File file : files) { AbstractCIDataProvider.LOG.debug("file added: '{}'", file); final DigesterLoader loader = DigesterLoader.newLoader(new FromAnnotationsRuleModule() { @Override protected void configureRules() { bindRulesFrom(CIForm.class); bindRulesFrom(CITable.class); bindRulesFrom(CICommand.class); bindRulesFrom(CISearch.class); bindRulesFrom(CIMenu.class); bindRulesFrom(CIType.class); bindRulesFrom(CIStatusGroup.class); bindRulesFrom(CINumberGenerator.class); bindRulesFrom(CIUIImage.class); bindRulesFrom(CIJasperImage.class); bindRulesFrom(CIAccessSet.class); bindRulesFrom(CISQLTable.class); bindRulesFrom(CIMsgPhrase.class); } }); try { final Digester digester = loader.newDigester(); final URLConnection connection = file.toURI().toURL().openConnection(); connection.setUseCaches(false); final InputStream stream = connection.getInputStream(); final InputSource source = new InputSource(stream); final Object item = digester.parse(source); stream.close(); if (item instanceof ICIItem) { ((ICIItem) item).setFile(file.getPath()); } if (item instanceof CIForm) { AbstractCIDataProvider.LOG.debug("Form added: '{}'", item); AbstractCIDataProvider.FORMS.add((CIForm) item); } else if (item instanceof CITable) { AbstractCIDataProvider.LOG.debug("Table added: '{}'", item); AbstractCIDataProvider.TABLES.add((CITable) item); } else if (item instanceof CICommand) { AbstractCIDataProvider.LOG.debug("Command added: '{}'", item); AbstractCIDataProvider.COMMANDS.add((CICommand) item); } else if (item instanceof CIType) { AbstractCIDataProvider.LOG.debug("Type added: '{}'", item); AbstractCIDataProvider.TYPES.add((CIType) item); } else if (item instanceof CIStatusGroup) { AbstractCIDataProvider.LOG.debug("CIStatusGroup added: '{}'", item); AbstractCIDataProvider.STATUSGRPS.add((CIStatusGroup) item); } else if (item instanceof CIMenu) { AbstractCIDataProvider.LOG.debug("CIMenu added: '{}'", item); AbstractCIDataProvider.MENUS.add((CIMenu) item); } else if (item instanceof CINumberGenerator) { AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item); AbstractCIDataProvider.NUMGENS.add((CINumberGenerator) item); } else if (item instanceof CIJasperImage) { AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item); AbstractCIDataProvider.JASPERIMG.add((CIJasperImage) item); } else if (item instanceof CIUIImage) { AbstractCIDataProvider.LOG.debug("CINumberGenerator added: '{}'", item); AbstractCIDataProvider.UIIMG.add((CIUIImage) item); } else if (item instanceof CIAccessSet) { AbstractCIDataProvider.LOG.debug("CIAccessSet added: '{}'", item); AbstractCIDataProvider.ACCESSSET.add((CIAccessSet) item); } else if (item instanceof CISearch) { AbstractCIDataProvider.LOG.debug("CISearch added: '{}'", item); AbstractCIDataProvider.SEARCHS.add((CISearch) item); } else if (item instanceof CISQLTable) { AbstractCIDataProvider.LOG.debug("CISearch added: '{}'", item); AbstractCIDataProvider.SQLTABLES.add((CISQLTable) item); } else if (item instanceof CIMsgPhrase) { AbstractCIDataProvider.LOG.debug("CIMsgPhrase added: '{}'", item); AbstractCIDataProvider.MSGPHRASES.add((CIMsgPhrase) item); } } catch (final MalformedURLException e) { AbstractCIDataProvider.LOG.error("MalformedURLException", e); } catch (final IOException e) { AbstractCIDataProvider.LOG.error("IOException", e); } catch (final SAXException e) { AbstractCIDataProvider.LOG.error("SAXException", e); } } final Collection<File> propFiles = FileUtils.listFiles(new File(baseFolder), new String[] { "properties" }, true); for (final File file : propFiles) { final Properties props = new Properties(); try { props.load(new FileInputStream(file)); AbstractCIDataProvider.LOG.debug("properties loaded: '{}'", file); } catch (final IOException e) { AbstractCIDataProvider.LOG.error("IOException", e); } AbstractCIDataProvider.DBPROPERTIES.putAll(props); } try { final InputStream ignStream = AbstractCIDataProvider.class.getResourceAsStream("/Ignore.properties"); if (ignStream != null) { final Properties ignoreProps = new Properties(); ignoreProps.load(ignStream); AbstractCIDataProvider.DBPROPERTIES.putAll(ignoreProps); } } catch (final IOException e) { AbstractCIDataProvider.LOG.error("IOException", e); } }
From source file:org.arasthel.almeribus.utils.LoadFromWeb.java
public static String getMensajeDesarrollador() { String mensaje = null;/* ww w . j a v a2 s . co m*/ try { URL url = new URL("http://arasthel.byethost14.com/almeribus/message.html?token=" + new Random().nextInt(Integer.MAX_VALUE)); URLConnection connection = url.openConnection(); connection.setUseCaches(false); connection.setConnectTimeout(10000); connection.setReadTimeout(15000); Scanner scan = new Scanner(connection.getInputStream()); StringBuilder strBuilder = new StringBuilder(); while (scan.hasNextLine()) { strBuilder.append(scan.nextLine()); } scan.close(); mensaje = strBuilder.toString(); } catch (Exception e) { } return mensaje; }
From source file:org.arasthel.almeribus.utils.LoadFromWeb.java
public static String getUltimaVersion() { String mensaje = null;/*from w w w .j av a 2 s .c o m*/ try { URL url = new URL("http://arasthel.byethost14.com/almeribus/version.html?token=" + new Random().nextInt(Integer.MAX_VALUE)); URLConnection connection = url.openConnection(); connection.setUseCaches(false); connection.setConnectTimeout(10000); connection.setReadTimeout(15000); Scanner scan = new Scanner(connection.getInputStream()); StringBuilder strBuilder = new StringBuilder(); while (scan.hasNextLine()) { strBuilder.append(scan.nextLine()); } scan.close(); mensaje = strBuilder.toString(); } catch (Exception e) { } return mensaje; }
From source file:XmlUtils.java
public static Document parse(URL url) throws DocumentException, IOException { URLConnection urlConnection; DataInputStream inStream;// w w w .ja va 2 s .c om urlConnection = url.openConnection(); ((HttpURLConnection) urlConnection).setRequestMethod("GET"); urlConnection.setDoInput(true); urlConnection.setDoOutput(false); urlConnection.setUseCaches(false); inStream = new DataInputStream(urlConnection.getInputStream()); byte[] bytes = new byte[1024]; int read; StringBuilder builder = new StringBuilder(); while ((read = inStream.read(bytes)) >= 0) { String readed = new String(bytes, 0, read, "UTF-8"); builder.append(readed); } SAXReader reader = new SAXReader(); XmlUtils.createIgnoreErrorHandler(reader); // InputSource inputSource = new InputSource(new InputStreamReader(inStream, "UTF-8")); // inputSource.setEncoding("UTF-8"); Document dom = reader.read(new StringReader(builder.toString())); inStream.close(); // new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("retrieval.xml"), "UTF-8") return dom; }
From source file:info.magnolia.cms.exchange.simple.Transporter.java
/** * http form multipart form post/*from ww w . j av a2 s .c om*/ * @param connection * @param activationContent * @throws ExchangeException */ public static void transport(URLConnection connection, ActivationContent activationContent) throws ExchangeException { FileInputStream fis = null; DataOutputStream outStream = null; try { byte[] buffer = new byte[BUFFER_SIZE]; connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-type", "multipart/form-data; boundary=" + BOUNDARY); connection.setRequestProperty("Cache-Control", "no-cache"); outStream = new DataOutputStream(connection.getOutputStream()); outStream.writeBytes("--" + BOUNDARY + "\r\n"); // set all resources from activationContent Iterator fileNameIterator = activationContent.getFiles().keySet().iterator(); while (fileNameIterator.hasNext()) { String fileName = (String) fileNameIterator.next(); fis = new FileInputStream(activationContent.getFile(fileName)); outStream.writeBytes("content-disposition: form-data; name=\"" + fileName + "\"; filename=\"" + fileName + "\"\r\n"); outStream.writeBytes("content-type: application/octet-stream" + "\r\n\r\n"); while (true) { synchronized (buffer) { int amountRead = fis.read(buffer); if (amountRead == -1) { break; } outStream.write(buffer, 0, amountRead); } } fis.close(); outStream.writeBytes("\r\n" + "--" + BOUNDARY + "\r\n"); } outStream.flush(); outStream.close(); log.debug("Activation content sent as multipart/form-data"); } catch (Exception e) { throw new ExchangeException( "Simple exchange transport failed: " + ClassUtils.getShortClassName(e.getClass()), e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { log.error("Exception caught", e); } } if (outStream != null) { try { outStream.close(); } catch (IOException e) { log.error("Exception caught", e); } } } }
From source file:xtrememp.update.SoftwareUpdate.java
public static Version getLastVersion(URL url) throws Exception { Version result = null;/*from ww w .ja v a 2s . c o m*/ InputStream urlStream = null; try { URLConnection urlConnection = url.openConnection(); urlConnection.setAllowUserInteraction(false); urlConnection.setConnectTimeout(30000); urlConnection.setDoInput(true); urlConnection.setDoOutput(false); urlConnection.setReadTimeout(10000); urlConnection.setUseCaches(true); urlStream = urlConnection.getInputStream(); Properties properties = new Properties(); properties.load(urlStream); result = new Version(); result.setMajorNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.majorNumber"))); result.setMinorNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.minorNumber"))); result.setMicroNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.microNumber"))); result.setVersionType( Version.VersionType.valueOf(properties.getProperty("xtrememp.lastVersion.versionType"))); result.setReleaseDate(properties.getProperty("xtrememp.lastVersion.releaseDate")); result.setDownloadURL(properties.getProperty("xtrememp.lastVersion.dounloadURL")); } finally { IOUtils.closeQuietly(urlStream); } return result; }
From source file:org.seasar.mayaa.impl.util.IOUtil.java
/** * URL?InputStream??//from w w w . jav a 2 s . co m * ??URL???? * ?????jar????? * ?????? * url?null???null? * * URL????????? * "org.seasar.mayaa.useURLCache=true" ??? * * @param url ?URL * @return InputStream */ public static InputStream openStream(URL url) { if (url == null) { return null; } try { URLConnection connection = url.openConnection(); // ??jar???? // TODO useURLCache?????? connection.setUseCaches(_useURLCache); return connection.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.bstek.dorado.core.pkgs.PackageManager.java
private static void doBuildPackageInfos() throws Exception { Map<String, PackageInfo> packageMap = new HashMap<String, PackageInfo>(); Enumeration<URL> defaultContextFileResources = org.springframework.util.ClassUtils.getDefaultClassLoader() .getResources(PACKAGE_PROPERTIES_LOCATION); while (defaultContextFileResources.hasMoreElements()) { URL url = defaultContextFileResources.nextElement(); InputStream in = null;/*from w ww . j a v a 2 s. c o m*/ try { URLConnection con = url.openConnection(); con.setUseCaches(false); in = con.getInputStream(); Properties properties = new Properties(); properties.load(in); String packageName = properties.getProperty("name"); if (StringUtils.isEmpty(packageName)) { throw new IllegalArgumentException("Package name undefined."); } PackageInfo packageInfo = new PackageInfo(packageName); packageInfo.setAddonVersion(properties.getProperty("addonVersion")); packageInfo.setVersion(properties.getProperty("version")); String dependsText = properties.getProperty("depends"); if (StringUtils.isNotBlank(dependsText)) { List<Dependence> dependences = new ArrayList<Dependence>(); for (String depends : StringUtils.split(dependsText, "; ")) { if (StringUtils.isNotEmpty(depends)) { Dependence dependence = parseDependence(depends); dependences.add(dependence); } } if (!dependences.isEmpty()) { packageInfo.setDepends(dependences.toArray(new Dependence[0])); } } String license = StringUtils.trim(properties.getProperty("license")); if (StringUtils.isNotEmpty(license)) { if (INHERITED.equals(license)) { packageInfo.setLicense(LICENSE_INHERITED); } else { String[] licenses = StringUtils.split(license); licenses = StringUtils.stripAll(licenses); packageInfo.setLicense(licenses); } } packageInfo.setLoadUnlicensed(BooleanUtils.toBoolean(properties.getProperty("loadUnlicensed"))); packageInfo.setClassifier(properties.getProperty("classifier")); packageInfo.setHomePage(properties.getProperty("homePage")); packageInfo.setDescription(properties.getProperty("description")); packageInfo.setPropertiesLocations(properties.getProperty("propertiesConfigLocations")); packageInfo.setContextLocations(properties.getProperty("contextConfigLocations")); packageInfo.setComponentLocations(properties.getProperty("componentConfigLocations")); packageInfo.setServletContextLocations(properties.getProperty("servletContextConfigLocations")); String configurerClass = properties.getProperty("configurer"); if (StringUtils.isNotBlank(configurerClass)) { Class<?> type = ClassUtils.forName(configurerClass); packageInfo.setConfigurer((PackageConfigurer) type.newInstance()); } String listenerClass = properties.getProperty("listener"); if (StringUtils.isNotBlank(listenerClass)) { Class<?> type = ClassUtils.forName(listenerClass); packageInfo.setListener((PackageListener) type.newInstance()); } String servletContextListenerClass = properties.getProperty("servletContextListener"); if (StringUtils.isNotBlank(servletContextListenerClass)) { Class<?> type = ClassUtils.forName(servletContextListenerClass); packageInfo.setServletContextListener((ServletContextListener) type.newInstance()); } if (packageMap.containsKey(packageName)) { PackageInfo conflictPackageInfo = packageMap.get(packageName); StringBuffer conflictInfo = new StringBuffer(20); conflictInfo.append('[').append(conflictPackageInfo.getName()).append(" - ") .append(conflictPackageInfo.getVersion()).append(']'); conflictInfo.append(" and "); conflictInfo.append('[').append(packageInfo.getName()).append(" - ") .append(packageInfo.getVersion()).append(']'); Exception e = new IllegalArgumentException("More than one package \"" + packageName + "\" found. They are " + conflictInfo.toString()); logger.warn(e, e); } packageMap.put(packageName, packageInfo); } catch (Exception e) { throw new IllegalArgumentException("Error occured during parsing \"" + url.getPath() + "\".", e); } finally { if (in != null) { in.close(); } } } List<PackageInfo> calculatedPackages = new ArrayList<PackageInfo>(); for (PackageInfo packageInfo : packageMap.values()) { calculateDepends(packageInfo, calculatedPackages, packageMap); } packageInfosMap.clear(); for (PackageInfo packageInfo : calculatedPackages) { packageInfosMap.put(packageInfo.getName(), packageInfo); } }