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

2006/unicorn/src/org/w3c/unicorn/request UploadRequest.java,1.6,1.7 Request.java,1.9,1.10 DirectRequestGET.java,1.7,1.8 DirectRequestPOST.java,1.6,1.7

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 23 Sep 2009 13:55:21 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MqSJV-0002NG-Pa@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv9049/src/org/w3c/unicorn/request

Modified Files:
	UploadRequest.java Request.java DirectRequestGET.java 
	DirectRequestPOST.java 
Log Message:
doRequest Method only allowed to throw UnicornException 
+ added Exception catching for each Request class

Index: DirectRequestPOST.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestPOST.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- DirectRequestPOST.java	22 Sep 2009 12:37:57 -0000	1.6
+++ DirectRequestPOST.java	23 Sep 2009 13:55:19 -0000	1.7
@@ -4,6 +4,7 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.request;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Hashtable;
 import java.util.Map;
@@ -12,6 +13,8 @@
 import org.w3c.unicorn.input.DirectInputModule;
 import org.w3c.unicorn.response.Response;
 import org.w3c.unicorn.util.ClientHttpRequest;
+import org.w3c.unicorn.util.Message;
+import org.w3c.unicorn.exceptions.UnicornException;
 
 /**
  * Class to make a request directly using POST method
@@ -68,15 +71,18 @@
 	}
 
 	@Override
-	public Response doRequest() throws Exception {
+	public Response doRequest() throws UnicornException {
 		logger.trace("doRequest");
-		
-		ClientHttpRequest request = new ClientHttpRequest(sURL);
-		request.setLang(sLang);
-		request.setParameters(mapOfParameter);
-
-		InputStream is = request.post();
-		return streamToResponse(is);
+		try {
+			ClientHttpRequest request = new ClientHttpRequest(sURL);
+			request.setLang(sLang);
+			request.setParameters(mapOfParameter);
+	
+			InputStream is = request.post();
+			return streamToResponse(is);
+		} catch (IOException e) {
+			throw new UnicornException(new Message(e));
+		}
 	}
 
 	@Override

Index: DirectRequestGET.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestGET.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- DirectRequestGET.java	21 Sep 2009 16:28:33 -0000	1.7
+++ DirectRequestGET.java	23 Sep 2009 13:55:19 -0000	1.8
@@ -14,6 +14,8 @@
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.DirectInputModule;
 import org.w3c.unicorn.response.Response;
+import org.w3c.unicorn.util.Message;
+import org.w3c.unicorn.exceptions.UnicornException;
 
 /**
  * Class to make a request directly using GET method
@@ -79,21 +81,25 @@
 	}
 
 	@Override
-	public Response doRequest() throws Exception {
-		logger.trace("doRequest");
-		final URL aURL;
-		if (null == this.sParameter) {
-			aURL = new URL(this.sURL);
-		} else {
-			logger.debug(this.sParameter);
-			aURL = new URL(this.sURL + "?" + this.sParameter);
+	public Response doRequest() throws UnicornException {
+		try {
+			logger.trace("doRequest");
+			final URL aURL;
+			if (null == this.sParameter) {
+				aURL = new URL(this.sURL);
+			} else {
+				logger.debug(this.sParameter);
+				aURL = new URL(this.sURL + "?" + this.sParameter);
+			}
+			final URLConnection aURLConnection = aURL.openConnection();
+			aURLConnection.setRequestProperty("Accept-Language", this.sLang);
+	
+			InputStream is = aURLConnection.getInputStream();
+	
+			return streamToResponse(is);
+		} catch (IOException e) {
+			throw new UnicornException(new Message(e));
 		}
-		final URLConnection aURLConnection = aURL.openConnection();
-		aURLConnection.setRequestProperty("Accept-Language", this.sLang);
-
-		InputStream is = aURLConnection.getInputStream();
-
-		return streamToResponse(is);
 	}
 
 	@Override

Index: UploadRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/UploadRequest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- UploadRequest.java	21 Sep 2009 16:28:33 -0000	1.6
+++ UploadRequest.java	23 Sep 2009 13:55:19 -0000	1.7
@@ -14,6 +14,8 @@
 import org.w3c.unicorn.input.UploadInputModule;
 import org.w3c.unicorn.response.Response;
 import org.w3c.unicorn.util.ClientHttpRequest;
+import org.w3c.unicorn.util.Message;
+import org.w3c.unicorn.exceptions.UnicornException;
 
 /**
  * Class to deal with the upload request
@@ -88,25 +90,31 @@
 	}
 
 	@Override
-	public Response doRequest() throws Exception {
+	public Response doRequest() throws UnicornException {
 		logger.trace("doRequest");
-		this.aClientHttpRequest = new ClientHttpRequest(sURL);
-		logger.debug("Lang : " + this.sLang + ".");
-		this.aClientHttpRequest.setLang(sLang);
-		this.aClientHttpRequest.setParameter(this.sInputParameterName,
-				this.aUploadInputModule.getFileName(), 
-				this.aUploadInputModule.getInputStream(),
-				this.aUploadInputModule.getMimeType());
-		for (final String sName : this.mapOfParameter.keySet()) {
-			final String sValue = this.mapOfParameter.get(sName);
-			logger.trace("addParameter");
-			logger.debug("Name :" + sName + ".");
-			logger.debug("Value :" + sValue + ".");
-			this.aClientHttpRequest.setParameter(sName, sValue);
-		}
-		InputStream is = this.aClientHttpRequest.post();
+		try {
+			aClientHttpRequest = new ClientHttpRequest(sURL);
+			logger.debug("Lang : " + this.sLang + ".");
+			aClientHttpRequest.setLang(sLang);
+			aClientHttpRequest.setParameter(this.sInputParameterName,
+					aUploadInputModule.getFileName(), 
+					aUploadInputModule.getInputStream(),
+					aUploadInputModule.getMimeType());
+			for (final String sName : mapOfParameter.keySet()) {
+				final String sValue = mapOfParameter.get(sName);
+				logger.trace("addParameter");
+				logger.debug("Name :" + sName + ".");
+				logger.debug("Value :" + sValue + ".");
+				aClientHttpRequest.setParameter(sName, sValue);
+			}
+			InputStream is = this.aClientHttpRequest.post();
 
-		return streamToResponse(is);
+			return streamToResponse(is);
+		} catch (MalformedURLException e) {
+			throw new UnicornException(new Message(e));
+		} catch (IOException e) {
+			throw new UnicornException(new Message(e));
+		}
 	}
 
 	@Override

Index: Request.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/Request.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Request.java	21 Sep 2009 16:35:50 -0000	1.9
+++ Request.java	23 Sep 2009 13:55:19 -0000	1.10
@@ -18,6 +18,7 @@
 import org.w3c.unicorn.input.UploadInputModule;
 import org.w3c.unicorn.response.Response;
 import org.w3c.unicorn.response.parser.ResponseParserFactory;
+import org.w3c.unicorn.exceptions.UnicornException;
 
 /**
  * 
@@ -74,8 +75,7 @@
 	 *             odd error occured
 	 * @throws Exception 
 	 */
-	public abstract org.w3c.unicorn.response.Response doRequest()
-			throws IOException, Exception;
+	public abstract org.w3c.unicorn.response.Response doRequest() throws UnicornException;
 
 	public abstract EnumInputMethod getInputMethod();
 
Received on Wednesday, 23 September 2009 13:55:31 GMT

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