2006/unicorn/org/w3c/unicorn UnicornCall.java,1.26,1.27

Update of /sources/public/2006/unicorn/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv22810/org/w3c/unicorn

Modified Files:
	UnicornCall.java 
Log Message:
error messages are no longer written on disk and display the exception message

Index: UnicornCall.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/UnicornCall.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- UnicornCall.java	29 Jul 2009 13:23:33 -0000	1.26
+++ UnicornCall.java	29 Jul 2009 14:44:51 -0000	1.27
@@ -4,11 +4,15 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.Writer;
 
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -853,7 +857,7 @@
 		Response aResponse = null;
 		try {
 			// Uncomment/comment next lines to test io_error
-			//throw new Exception();
+			//throw new Exception("Message test de l'exception");
 			aResponse = this.aRequest.doRequest();
 		} catch (final Exception e) {
 			RequestThread.logger.error("Exception : " + e.getMessage(), e);
@@ -863,9 +867,20 @@
 				String lang = unicornCall.getMapOfStringParameter().get(Property.get("UNICORN_PARAMETER_PREFIX") + "lang")[0];
 				
 				// generateFileFromTemplate generates the error xml file if it doesn't exist already
-				String filePath = TemplateHelper.generateFileFromTemplate("io_error", lang, Property.get("PATH_TO_INDEX_OUTPUT"), "xml");
+				//String filePath = TemplateHelper.generateFileFromTemplate("io_error", lang, Property.get("PATH_TO_INDEX_OUTPUT"), "xml");
 				
-				InputStreamReader isr = new InputStreamReader(new URL("file:" + filePath).openConnection().getInputStream());
+				VelocityContext context = new VelocityContext();
+				context.put("exception", e.getMessage());
+				Template temp = TemplateHelper.getInternationalizedTemplate("io_error", lang, context);
+				
+				ByteArrayOutputStream os = new ByteArrayOutputStream();
+				OutputStreamWriter osw = new OutputStreamWriter(os);
+				temp.merge(context, osw);		
+				osw.close();
+				
+				//InputStreamReader isr = new InputStreamReader(new URL("file:" + filePath).openConnection().getInputStream());
+				
+				InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(os.toByteArray()));
 				
 				char[] chararray = new char[8192];
 				int readLength = 0;
@@ -875,8 +890,13 @@
 				aResponse = ResponseParserFactory.parse(builder.toString(), this.aRequest.getResponseType());
 				aResponse.setXml(builder);
 			} catch (MalformedURLException e1) {
+				RequestThread.logger.error("Exception : " + e1.getMessage(), e1);
 				e1.printStackTrace();
 			} catch (IOException e1) {
+				RequestThread.logger.error("Exception : " + e1.getMessage(), e1);
+				e1.printStackTrace();
+			} catch (Exception e1) {
+				RequestThread.logger.error("Exception : " + e1.getMessage(), e1);
 				e1.printStackTrace();
 			}
 		}

Received on Wednesday, 29 July 2009 14:45:04 UTC