List of usage examples for java.net URLConnection getExpiration
public long getExpiration()
From source file:MainClass.java
public static void main(String args[]) throws Exception { int c;/*from w w w . j av a2 s . c om*/ URL hp = new URL("http", "www.java2s.com", 80, "/"); URLConnection hpCon = hp.openConnection(); System.out.println("Date: " + hpCon.getDate()); System.out.println("Type: " + hpCon.getContentType()); System.out.println("Exp: " + hpCon.getExpiration()); System.out.println("Last M: " + hpCon.getLastModified()); System.out.println("Length: " + hpCon.getContentLength()); }
From source file:Main.java
public static void main(String args[]) throws Exception { int c;//ww w .ja v a 2 s . co m URL hp = new URL("http://www.internic.net"); URLConnection hpCon = hp.openConnection(); long d = hpCon.getDate(); if (d == 0) System.out.println("No date information."); else System.out.println("Date: " + new Date(d)); System.out.println("Content-Type: " + hpCon.getContentType()); d = hpCon.getExpiration(); if (d == 0) System.out.println("No expiration information."); else System.out.println("Expires: " + new Date(d)); d = hpCon.getLastModified(); if (d == 0) System.out.println("No last-modified information."); else System.out.println("Last-Modified: " + new Date(d)); int len = hpCon.getContentLength(); if (len == -1) System.out.println("Content length unavailable."); else System.out.println("Content-Length: " + len); if (len != 0) { InputStream input = hpCon.getInputStream(); int i = len; while (((c = input.read()) != -1)) { // && (--i > 0)) { System.out.print((char) c); } input.close(); } else { System.out.println("No content available."); } }
From source file:Main.java
public static void main(String args[]) throws Exception { URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); System.out.println("Content-type: " + uc.getContentType()); System.out.println("Content-encoding: " + uc.getContentEncoding()); System.out.println("Date: " + new Date(uc.getDate())); System.out.println("Last modified: " + new Date(uc.getLastModified())); System.out.println("Expiration date: " + new Date(uc.getExpiration())); System.out.println("Content-length: " + uc.getContentLength()); }
From source file:Main.java
public static void main(String args[]) throws Exception { URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); uc.connect();// ww w . j av a 2 s. c o m System.out.println("Content-type: " + uc.getContentType()); System.out.println("Content-encoding: " + uc.getContentEncoding()); System.out.println("Date: " + new Date(uc.getDate())); System.out.println("Last modified: " + new Date(uc.getLastModified())); System.out.println("Expiration date: " + new Date(uc.getExpiration())); System.out.println("Content-length: " + uc.getContentLength()); }
From source file:URLConnectionTest.java
public static void main(String[] args) { try {// ww w.java2 s . c om String urlName; if (args.length > 0) urlName = args[0]; else urlName = "http://java.sun.com"; URL url = new URL(urlName); URLConnection connection = url.openConnection(); // set username, password if specified on command line if (args.length > 2) { String username = args[1]; String password = args[2]; String input = username + ":" + password; String encoding = base64Encode(input); connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.connect(); // print header fields Map<String, List<String>> headers = connection.getHeaderFields(); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String key = entry.getKey(); for (String value : entry.getValue()) System.out.println(key + ": " + value); } // print convenience functions System.out.println("----------"); System.out.println("getContentType: " + connection.getContentType()); System.out.println("getContentLength: " + connection.getContentLength()); System.out.println("getContentEncoding: " + connection.getContentEncoding()); System.out.println("getDate: " + connection.getDate()); System.out.println("getExpiration: " + connection.getExpiration()); System.out.println("getLastModifed: " + connection.getLastModified()); System.out.println("----------"); Scanner in = new Scanner(connection.getInputStream()); // print first ten lines of contents for (int n = 1; in.hasNextLine() && n <= 10; n++) System.out.println(in.nextLine()); if (in.hasNextLine()) System.out.println(". . ."); } catch (IOException e) { e.printStackTrace(); } }
From source file:GetURLInfo.java
/** Use the URLConnection class to get info about the URL */ public static void printinfo(URL url) throws IOException { URLConnection c = url.openConnection(); // Get URLConnection from URL c.connect(); // Open a connection to URL // Display some information about the URL contents System.out.println(" Content Type: " + c.getContentType()); System.out.println(" Content Encoding: " + c.getContentEncoding()); System.out.println(" Content Length: " + c.getContentLength()); System.out.println(" Date: " + new Date(c.getDate())); System.out.println(" Last Modified: " + new Date(c.getLastModified())); System.out.println(" Expiration: " + new Date(c.getExpiration())); // If it is an HTTP connection, display some additional information. if (c instanceof HttpURLConnection) { HttpURLConnection h = (HttpURLConnection) c; System.out.println(" Request Method: " + h.getRequestMethod()); System.out.println(" Response Message: " + h.getResponseMessage()); System.out.println(" Response Code: " + h.getResponseCode()); }/* www .j a v a 2 s. c o m*/ }
From source file:org.apache.synapse.registry.url.SimpleURLRegistry.java
public RegistryEntry getRegistryEntry(String key) { if (log.isDebugEnabled()) { log.debug("Perform RegistryEntry lookup for key : " + key); }//from w w w . jav a2s . c o m URL url = SynapseConfigUtils.getURLFromPath(root + key, properties.get(SynapseConstants.SYNAPSE_HOME) != null ? properties.get(SynapseConstants.SYNAPSE_HOME).toString() : ""); if (url == null) { return null; } URLConnection connection = SynapseConfigUtils.getURLConnection(url); if (connection == null) { if (log.isDebugEnabled()) { log.debug("Cannot create a URLConnection for given URL : " + url); } return null; } RegistryEntryImpl wre = new RegistryEntryImpl(); wre.setKey(key); wre.setName(url.getFile()); wre.setType(connection.getContentType()); wre.setDescription("Resource at : " + url.toString()); wre.setLastModified(connection.getLastModified()); wre.setVersion(connection.getLastModified()); if (connection.getExpiration() > 0) { wre.setCachableDuration(connection.getExpiration() - System.currentTimeMillis()); } else { wre.setCachableDuration(getCachableDuration()); } return wre; }
From source file:org.rhq.plugins.apache_bmx.ApacheDiscovery.java
/** * Run the discovery//from w w w . j a va 2 s .c om */ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext discoveryContext) throws Exception { Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(); /** * Discover apache with mod_bmx by pinging ist bmx-handler * * A discovered resource must have a unique key, that must * stay the same when the resource is discovered the next * time */ Configuration config = discoveryContext.getDefaultPluginConfiguration(); String host = config.getSimpleValue("host", "localhost"); String portS = config.getSimpleValue("port", "80"); int port = Integer.valueOf(portS); String handler = config.getSimpleValue("bmxHandler", "/bmx"); URL url = new URL("http", host, port, handler); URLConnection conn = url.openConnection(); conn.getExpiration(); String urlString = url.toString(); config.put(new PropertySimple("bmxUrl", urlString)); config.put(new PropertySimple("vhost", "_GLOBAL_")); DiscoveredResourceDetails detail = new DiscoveredResourceDetails(discoveryContext.getResourceType(), // ResourceType urlString, // Resource key "Apache server at " + urlString, // Resource Name null, // Version - TODO: get from mod_bmx "Apache httpd with mod_bmx", // Description config, // COnfiguration null // process scans ); // Add to return values discoveredResources.add(detail); log.info("Discovered new ... httpd at " + urlString); return discoveredResources; }
From source file:org.theospi.portfolio.presentation.export.StreamedPage.java
public InputStream getStream() throws IOException { URLConnection conn = Access.getAccess().openConnection(link); // fetch and store final redirected URL and response headers InputStream returned = conn.getInputStream(); this.setContentEncoding(conn.getContentEncoding()); this.setContentType(conn.getContentType()); this.setExpiration(conn.getExpiration()); this.setLastModified(conn.getLastModified()); return returned; }
From source file:org.wso2.carbon.mediation.registry.ESBRegistry.java
public RegistryEntry getRegistryEntry(String key) { // get information from the actual resource MediationRegistryEntryImpl entryEmbedded = new MediationRegistryEntryImpl(); try {/* w ww . j ava 2 s. c o m*/ URL url = new URL(getRoot() + key); if ("file".equals(url.getProtocol())) { try { url.openStream(); } catch (IOException ignored) { if (!localRegistry.endsWith(URL_SEPARATOR)) { localRegistry = localRegistry + URL_SEPARATOR; } url = new URL(url.getProtocol() + ":" + localRegistry + key); try { url.openStream(); } catch (IOException e) { return null; } } } URLConnection urlc = url.openConnection(); entryEmbedded.setKey(key); entryEmbedded.setName(url.getFile()); entryEmbedded.setType(ESBRegistryConstants.FILE); entryEmbedded.setDescription("Resource at : " + url.toString()); entryEmbedded.setLastModified(urlc.getLastModified()); entryEmbedded.setVersion(urlc.getLastModified()); if (urlc.getExpiration() > 0) { entryEmbedded.setCachableDuration(urlc.getExpiration() - System.currentTimeMillis()); } else { entryEmbedded.setCachableDuration(getCachableDuration()); } } catch (MalformedURLException e) { handleException("Invalid URL reference " + getRoot() + key, e); } catch (IOException e) { handleException("IO Error reading from URL " + getRoot() + key, e); } // get information from the database PersistenceManager persistenceManager = PersistenceManager.getInstance(); RegistryEntryDO registryEntryDO = persistenceManager.getRegistryEntry(key); if (registryEntryDO != null) { if (registryEntryDO.getExpiryTime() != null) { entryEmbedded.setCachableDuration(registryEntryDO.getExpiryTime()); } else { entryEmbedded.setCachableDuration(0); } } return entryEmbedded; }