- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 04 Sep 2009 13:51:08 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn In directory hutz:/tmp/cvs-serv14816/src/org/w3c/unicorn Modified Files: UnicornCall.java Added Files: RequestThread.java Log Message: separated UnicornCall and RequestThread classes --- NEW FILE: RequestThread.java --- package org.w3c.unicorn; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.event.EventCartridge; import org.w3c.unicorn.request.Request; import org.w3c.unicorn.response.Response; import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.util.EscapeXMLEntities; import org.w3c.unicorn.util.Templates; /** * Thread executing a request * * @author Damien Leroy * */ class RequestThread extends Thread { /** * Used for complex logging purpose */ private static final Log logger = LogFactory.getLog(RequestThread.class);; /** * Data Structure for the responses */ private Map<String, Response> mapOfResponse; /** * The request to make */ private Request aRequest; /** * ID of the Observer */ private String obsID; /** * The call to perform */ private UnicornCall unicornCall; /** * Initialize the thread by filling the properties * * @param mapOfResponse * the map of the responses * @param aRequest * the request to make * @param obsID * the ID of the observer * @param unicorn * the unicorn call to make */ public RequestThread(Map<String, Response> mapOfResponse, Request aRequest, String obsID, UnicornCall unicorn) { this.mapOfResponse = mapOfResponse; this.aRequest = aRequest; this.obsID = obsID; this.unicornCall = unicorn; } /** * Allow to launch the thread */ @Override public void run() { this.unicornCall.incCounter(); Response aResponse = null; try { // Uncomment/comment next lines to test io_error //throw new Exception("Message test de l'exception"); aResponse = this.aRequest.doRequest(); } catch (final Exception e) { RequestThread.logger.error("Exception : " + e.getMessage(), e); try { StringBuilder builder = new StringBuilder(); //String lang[] = unicornCall.getMapOfStringParameter().get( // Property.get("UNICORN_PARAMETER_PREFIX") + "lang"); String lang = unicornCall.getLang(); VelocityContext context = new VelocityContext(Framework.getLanguageContexts().get(lang)); EventCartridge aEventCartridge = new EventCartridge(); aEventCartridge.addEventHandler(new EscapeXMLEntities()); aEventCartridge.attachToContext(context); if (e.getMessage() != null) context.put("exception", e.getMessage()); else context.put("exception", ""); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os); Templates.write("io_error.vm", context, osw); osw.close(); InputStreamReader isr = new InputStreamReader( new ByteArrayInputStream(os.toByteArray())); char[] chararray = new char[8192]; int readLength = 0; while ((readLength = isr.read(chararray, 0, 8192)) > -1) { builder.append(chararray, 0, readLength); } aResponse = ResponseParserFactory.parse(builder.toString(), "default"); 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(); } } synchronized (mapOfResponse) { mapOfResponse.put(obsID, aResponse); } if (!aResponse.isPassed() && this.unicornCall.getBPassed()) { this.unicornCall.setbPassed(false); } this.unicornCall.decCounter(); } } Index: UnicornCall.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/UnicornCall.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- UnicornCall.java 4 Sep 2009 13:45:13 -0000 1.7 +++ UnicornCall.java 4 Sep 2009 13:51:06 -0000 1.8 @@ -4,12 +4,7 @@ // 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.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -27,8 +22,6 @@ import org.apache.commons.fileupload.FileItem; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.event.EventCartridge; import org.w3c.dom.Document; import org.w3c.unicorn.contract.CallParameter; import org.w3c.unicorn.contract.EnumInputMethod; @@ -41,7 +34,6 @@ import org.w3c.unicorn.request.Request; import org.w3c.unicorn.request.RequestList; import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.tasklist.Group; import org.w3c.unicorn.tasklist.Task; import org.w3c.unicorn.tasklist.parameters.Mapping; @@ -52,9 +44,7 @@ import org.w3c.unicorn.tasklisttree.TLTExec; import org.w3c.unicorn.tasklisttree.TLTIf; import org.w3c.unicorn.tasklisttree.TLTNode; -import org.w3c.unicorn.util.EscapeXMLEntities; import org.w3c.unicorn.util.Property; -import org.w3c.unicorn.util.Templates; import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; @@ -838,127 +828,4 @@ } -} - -/** - * Thread executing a request - * - * @author Damien Leroy - * - */ -class RequestThread extends Thread { - /** - * Used for complex logging purpose - */ - private static final Log logger = LogFactory.getLog(RequestThread.class);; - - /** - * Data Structure for the responses - */ - private Map<String, Response> mapOfResponse; - - /** - * The request to make - */ - private Request aRequest; - - /** - * ID of the Observer - */ - private String obsID; - - /** - * The call to perform - */ - private UnicornCall unicornCall; - - /** - * Initialize the thread by filling the properties - * - * @param mapOfResponse - * the map of the responses - * @param aRequest - * the request to make - * @param obsID - * the ID of the observer - * @param unicorn - * the unicorn call to make - */ - public RequestThread(Map<String, Response> mapOfResponse, Request aRequest, - String obsID, UnicornCall unicorn) { - this.mapOfResponse = mapOfResponse; - this.aRequest = aRequest; - this.obsID = obsID; - this.unicornCall = unicorn; - - } - - /** - * Allow to launch the thread - */ - @Override - public void run() { - this.unicornCall.incCounter(); - Response aResponse = null; - try { - // Uncomment/comment next lines to test io_error - //throw new Exception("Message test de l'exception"); - aResponse = this.aRequest.doRequest(); - } catch (final Exception e) { - RequestThread.logger.error("Exception : " + e.getMessage(), e); - try { - StringBuilder builder = new StringBuilder(); - //String lang[] = unicornCall.getMapOfStringParameter().get( - // Property.get("UNICORN_PARAMETER_PREFIX") + "lang"); - String lang = unicornCall.getLang(); - - VelocityContext context = new VelocityContext(Framework.getLanguageContexts().get(lang)); - EventCartridge aEventCartridge = new EventCartridge(); - aEventCartridge.addEventHandler(new EscapeXMLEntities()); - aEventCartridge.attachToContext(context); - - if (e.getMessage() != null) - context.put("exception", e.getMessage()); - else - context.put("exception", ""); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - Templates.write("io_error.vm", context, osw); - osw.close(); - InputStreamReader isr = new InputStreamReader( - new ByteArrayInputStream(os.toByteArray())); - char[] chararray = new char[8192]; - int readLength = 0; - while ((readLength = isr.read(chararray, 0, 8192)) > -1) { - builder.append(chararray, 0, readLength); - } - aResponse = ResponseParserFactory.parse(builder.toString(), "default"); - 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(); - } - } - - synchronized (mapOfResponse) { - mapOfResponse.put(obsID, aResponse); - } - - if (!aResponse.isPassed() && this.unicornCall.getBPassed()) { - this.unicornCall.setbPassed(false); - } - - this.unicornCall.decCounter(); - - } - -} +} \ No newline at end of file
Received on Friday, 4 September 2009 13:51:20 UTC