List of usage examples for java.net URLConnection toString
public String toString()
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(uc.toString()); }
From source file:com.xeiam.xchange.streaming.socketio.IOConnection.java
/** * Handshake.//from w w w . j av a 2 s. co m */ private void handshake() { URL url; String response; URLConnection connection; try { setState(STATE_HANDSHAKE); url = new URL(this.url.getProtocol() + "://" + this.url.getAuthority() + SOCKET_IO_1 + (this.url.getQuery() == null ? "" : "?" + this.url.getQuery())); connection = url.openConnection(); if (connection instanceof HttpsURLConnection) { ((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory); } connection.setConnectTimeout(connectTimeout); connection.setReadTimeout(connectTimeout); /* Setting the request headers */ for (Entry<Object, Object> entry : headers.entrySet()) { connection.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); } log.debug("> " + connection.toString()); InputStream stream = connection.getInputStream(); Scanner in = new Scanner(stream); response = in.nextLine(); log.debug("< " + response); String[] data = response.split(":"); sessionId = data[0]; heartbeatTimeout = Long.parseLong(data[1]) * 1000; closingTimeout = Long.parseLong(data[2]) * 1000; protocols = Arrays.asList(data[3].split(",")); } catch (Exception e) { error(new SocketIOException("Error while handshaking", e)); } }
From source file:com.dragonflow.StandardMonitor.URLOriginalMonitor.java
private static long getURLStatus_ForBackupToRegularMeansOnly(SocketSession socketsession, long l, String s, int i, int j) { if (i >= j) { System.out.println("URLOriginalMonitor KEEPTRYING!!! - URL: " + s + "FAILED THIS MANY TIMES: " + i); return l; }/*from w w w . j a v a 2 s .c o m*/ if (l != 200L && l != 302L && l != 301L) { System.out.println( "URLOriginalMonitor KEEPTRYING!!! - URL: " + s + " status: " + l + " times attempted: " + i); int k = 0; if (socketsession.context.getSetting("_timeout").length() > 0) { k = TextUtils.toInt(socketsession.context.getSetting("_timeout")) * 1000; } else { k = 60000; } Platform.sleep(k); StringBuffer stringbuffer = new StringBuffer(); try { URL url = new URL(s); URLConnection urlconnection = url.openConnection(); System.out.println( "URLOriginalMonitor KEEPTRYING Received a : " + urlconnection.getClass().getName()); System.out.println( "URLOriginalMonitor KEEPTRYING Received connection string : " + urlconnection.toString()); urlconnection.setDoInput(true); urlconnection.setUseCaches(false); System.out.println("URLOriginalMonitor KEEPTRYING Getting an input stream..."); java.io.InputStream inputstream = urlconnection.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); for (String s5 = null; (s5 = bufferedreader.readLine()) != null;) { stringbuffer.append(s5); } System.out.println("URLOriginalMonitor KEEPTRYING CONTENTS: " + stringbuffer.toString()); } catch (MalformedURLException malformedurlexception) { String s1 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + malformedurlexception.toString(); LogManager.log("Error", s1); LogManager.log("Error", FileUtils.stackTraceText(malformedurlexception)); System.out.println(s1); malformedurlexception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (IOException ioexception) { String s2 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + ioexception.toString(); LogManager.log("Error", s2); LogManager.log("Error", FileUtils.stackTraceText(ioexception)); System.out.println(s2); ioexception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (Exception exception) { String s3 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + exception.toString(); LogManager.log("Error", s3); LogManager.log("Error", FileUtils.stackTraceText(exception)); System.out.println(s3); exception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (Throwable throwable) { String s4 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + throwable.toString(); LogManager.log("Error", s4); LogManager.log("Error", FileUtils.stackTraceText(throwable)); System.out.println(s4); throwable.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } return 200L; } else { return l; } }
From source file:org.apache.cocoon.components.search.SimpleLuceneXMLIndexerImpl.java
/** * return a unique uid of a url connection * * @param urlConnection Description of Parameter * @return String unique uid of a urlConnection * @since// w w w . jav a 2 s. c o m */ private String uid(URLConnection urlConnection) { // Append path and date into a string in such a way that lexicographic // sorting gives the same results as a walk of the file hierarchy. Thus // null (\u0000) is used both to separate directory components and to // separate the path from the date. return urlConnection.toString().replace('/', '\u0000') + "\u0000" + DateField.timeToString(urlConnection.getLastModified()); }