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

2006/unicorn/src/org/w3c/unicorn/request URIRequest.java,1.8,1.9

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 30 Sep 2009 15:22:44 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Mt10u-0007bg-BW@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv29226/src/org/w3c/unicorn/request

Modified Files:
	URIRequest.java 
Log Message:
added response code verification. If an observer respond with a 404 or 500 response code a personalized message is displayed.

Index: URIRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/URIRequest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- URIRequest.java	30 Sep 2009 13:37:15 -0000	1.8
+++ URIRequest.java	30 Sep 2009 15:22:42 -0000	1.9
@@ -8,6 +8,7 @@
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.ConnectException;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.SocketTimeoutException;
 import java.net.URL;
@@ -122,11 +123,20 @@
 			}
 			logger.debug("URL : " + aURL + " .");
 			
-			URLConnection aURLConnection = aURL.openConnection();
+			HttpURLConnection aURLConnection = (HttpURLConnection) aURL.openConnection();
 			aURLConnection.setConnectTimeout(connectTimeOut);
 			aURLConnection.setReadTimeout(readTimeOut);
 			aURLConnection.setRequestProperty("Accept-Language", this.sLang);
 			
+			aURLConnection.connect();
+			int responseCode = aURLConnection.getResponseCode();
+			switch (responseCode) {
+			case HttpURLConnection.HTTP_NOT_FOUND:
+				throw new UnicornException(Message.Level.ERROR, "$message_observer_not_found " + Framework.mapOfObserver.get(observerId).getName(sLang.split(",")[0]), null);
+			case HttpURLConnection.HTTP_INTERNAL_ERROR:
+				throw new UnicornException(Message.Level.ERROR, "$message_observer_internal_error " + Framework.mapOfObserver.get(observerId).getName(sLang.split(",")[0]), null);
+			}
+			
 			InputStream is = aURLConnection.getInputStream();
 			Response response = streamToResponse(is);
 			response.setRequestUri(aURL.toString());
@@ -144,6 +154,7 @@
 				throw new UnicornException(new Message(e));
 			}
 		} catch (IOException e) {
+			logger.error(e.getMessage(), e);
 			throw new UnicornException(new Message(e));
 		}
 	}
Received on Wednesday, 30 September 2009 15:22:45 GMT

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