unicorn commit: implemented error messages observer_not_found and observer_internal_error

changeset:   1277:461b8da4b5fc
tag:         tip
user:        Thomas Gambet <tgambet@w3.org>
date:        Fri Jun 18 17:15:41 2010 -0400
files:       src/org/w3c/unicorn/request/UploadRequest.java
description:
implemented error messages observer_not_found and observer_internal_error


diff -r bf2b09a47566 -r 461b8da4b5fc src/org/w3c/unicorn/request/UploadRequest.java
--- a/src/org/w3c/unicorn/request/UploadRequest.java	Fri Jun 18 16:51:10 2010 -0400
+++ b/src/org/w3c/unicorn/request/UploadRequest.java	Fri Jun 18 17:15:41 2010 -0400
@@ -3,11 +3,14 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.request;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.Hashtable;
 import java.util.Map;
 
+import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.UploadInputModule;
 import org.w3c.unicorn.response.Response;
@@ -91,6 +94,7 @@
 	@Override
 	public Response doRequest() throws UnicornException {
 		logger.trace("doRequest");
+		String observerName = Framework.mapOfObserver.get(observerId).getName(sLang.split(",")[0]);
 		try {
 			aClientHttpRequest = new ClientHttpRequest(sURL);
 			logger.debug("Lang : " + this.sLang + ".");
@@ -107,8 +111,19 @@
 				aClientHttpRequest.setParameter(sName, sValue);
 			}
 			
-			// TODO How to find the response content encoding here ?
-			return ResponseFactory.getResponse(aClientHttpRequest.post(), responseType, sURL.toString(), null, observerId);
+			InputStream stream = null;
+			try {
+				stream = aClientHttpRequest.post();
+				// TODO How to find the response content encoding here ?
+				return ResponseFactory.getResponse(stream, responseType, sURL.toString(), null, observerId);
+			} catch (FileNotFoundException e) {
+				throw new UnicornException(Message.ERROR, "$message_observer_not_found", null, observerName);
+			} catch (IOException e) {
+				if (e.getMessage().contains("Server returned HTTP response code: 500"))
+					throw new UnicornException(Message.ERROR, "$message_observer_internal_error", null, observerName);
+				else
+					throw e;
+			}			
 
 		} catch (MalformedURLException e) {
 			throw new UnicornException(new Message(e));

Received on Friday, 18 June 2010 21:16:21 UTC