W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2009

2006/unicorn/src/org/w3c/unicorn Test.java,1.3,1.4

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 17 Sep 2009 10:36:45 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MoEM1-0004Vt-81@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv17322/src/org/w3c/unicorn

Modified Files:
	Test.java 
Log Message:
test connection exceptions

Index: Test.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Test.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Test.java	28 Aug 2009 16:11:41 -0000	1.3
+++ Test.java	17 Sep 2009 10:36:43 -0000	1.4
@@ -1,11 +1,26 @@
 package org.w3c.unicorn;
 
-import java.util.Locale;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.UnknownHostException;
+
+import javax.net.ssl.SSLException;
+
+//import sun.net.www.protocol.http.HttpURLConnection;
+
+
 
 public class Test {
 
 	/**
 	 * @param args
+	 * @throws MalformedURLException 
 	 */
 	public static void main(String[] args) {
 		// TODO Auto-generated method stub
@@ -26,9 +41,52 @@
 		System.out.println(matcher.group());
 	     //replaceAll(repl)*/
 		
-		Locale loc = new Locale("sssqn");
-		
-		System.out.println("z" + loc.getLanguage());
+		URL docUrl = null;
+		try {
+			docUrl = new URL("http://www.w3.org:9788");
+			//docUrl = new URL("http://qa-dev.w3.org/app");
+			//docUrl = new URL("http://www.w3.org/Team");
+			//docUrl = new URL("http://snowball.w3.org/unicorn/observe?ucn_uri=beta.w3.org&ucn_task=conformance");
+			//System.out.println(docUrl.getContent().toString());
+			//System.out.println(docUrl2.getContent().toString().length());
+			URLConnection con = docUrl.openConnection();
+			System.out.println(con.getConnectTimeout());
+			con.setConnectTimeout(1000);
+			con.setReadTimeout(1000);
+			con.getContent();
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (ConnectException e) {
+			e.printStackTrace();
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (UnknownHostException e) { 
+			e.printStackTrace();
+		} catch (SSLException e) {
+			e.printStackTrace();
+		} catch (SocketTimeoutException e) {
+			e.printStackTrace();
+			if (e.getMessage().contains("Read timed out"))
+				System.out.println("a");
+			if (e.getMessage().contains("connect timed out"))
+				System.out.println("b");
+		} catch (IOException e) {
+			try {
+				int responseCode;
+				if (docUrl != null) {
+					responseCode = ((HttpURLConnection) docUrl.openConnection()).getResponseCode();
+					switch (responseCode) {
+					case HttpURLConnection.HTTP_UNAUTHORIZED:
+						System.out.println("HTTP_UNAUTHORIZED");
+						break;
+					}
+				}
+			} catch (Exception e2) {
+				System.out.println("e2");
+				e2.printStackTrace();
+			}
+			e.printStackTrace();
+		}
 	}
 
 }
Received on Thursday, 17 September 2009 10:36:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:14 GMT