Changeset 769
- Timestamp:
- 03/14/05 17:56:22 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/external-tools/indexer-backends/lucene/org/midgardproject/lucene/HandlerThread.java
r718 r769 36 36 37 37 /** 38 * Logging daemon 39 */ 40 private Logger myLogger; 41 42 /** 38 43 * Create a new instance of the handler thread. 39 44 * … … 46 51 requestID = new Long(maxRequestID); 47 52 maxRequestID++; 53 myLogger = Logger.getLogger("org.midgardproject.lucene.HandlerThread." + requestID.toString()); 48 54 } 49 55 … … 54 60 public void run() 55 61 { 56 Logger myLogger = Logger.getLogger("org.midgardproject.lucene.HandlerThread." + requestID.toString());57 62 try 58 63 { … … 66 71 { 67 72 myLogger.log(Level.WARNING, "Uncaught Exception while processing the request, aborting.", ex); 68 } 69 finally 70 { 73 myLogger.warning(ex.toString()); 71 74 try 72 75 { 73 socket.close(); 74 myLogger.fine("Finished."); 76 PrintExceptionToClient(socket.getOutputStream(), ex); 75 77 } 76 catch (IOException ex )78 catch (IOException ex2) 77 79 { 78 myLogger. log(Level.WARNING, "Failed to close socket after processing.", ex);80 myLogger.warning("Failed to write Exception to the client: " + ex2.toString()); 79 81 } 80 82 } 81 83 try 84 { 85 socket.close(); 86 } 87 catch (IOException ex) 88 { 89 myLogger.log(Level.WARNING, "Failed to close socket after processing.", ex); 90 } 91 myLogger.fine("Finished."); 82 92 } 93 94 95 /** 96 * Prints an Exception to the XML Stream to the client, this is used for 97 * uncaught exceptions during processing. It assumes an empty output stream, 98 * you cannot really determine anything else. 99 * 100 * @param out OutputStream 101 * @param ex Exception thrown. 102 */ 103 private void PrintExceptionToClient (OutputStream out, Exception exception) 104 { 105 PrintStream outputStream; 106 try 107 { 108 outputStream = new PrintStream(out, true, "UTF-8"); 109 } 110 catch (Exception ex) 111 { 112 myLogger.log(Level.WARNING, "Failed to write an Uncaught Exception Message to the client: " + ex.toString()); 113 return; 114 } 115 outputStream.println("<?xml version='1.0' encoding='UTF-8' ?>"); 116 outputStream.println("<!DOCTYPE request SYSTEM 'xml-communication-response.dtd'>"); 117 outputStream.println("<response>"); 118 outputStream.print("<error id='UNCAUGHT_EXCEPTION'><![CDATA["); 119 outputStream.print(exception.toString().replaceAll("]]>", "]]>")); 120 exception.printStackTrace(outputStream); 121 outputStream.println("]]></error>"); 122 outputStream.println("</response>"); 123 } 124 125 /** 126 * Encodes an XML Textfor use in CDATA sections. The result is not surrounded by 127 * CDATA Tags. 128 * 129 * @param arg The argument string to encode. 130 * @return The encoded argument. 131 */ 132 public String EncodeCData(String arg) 133 { 134 return arg.replaceAll("]]>", "]]>"); 135 } 136 83 137 }
