- Timestamp:
- 07/18/07 08:25:45 PM (18 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java
r130 r134 43 43 * receiving Internet mail messages using the SMTP and POP3 protocols. 44 44 * 45 * Copyright (c) 2000-2002 J rg Pleumann <joerg@pleumann.de>45 * Copyright (c) 2000-2002 Jorg Pleumann <joerg@pleumann.de> 46 46 * 47 47 * Mail4ME is part of the EnhydraME family of projects. See the following web … … 67 67 import javax.microedition.io.StreamConnection; 68 68 import javax.microedition.io.Connector; 69 import net.rim.device.api.system.EventLogger; 70 import org.logicprobe.LogicMail.AppInfo; 69 71 70 72 /** … … 102 104 103 105 /** 104 * If true, protocol debugging information is written to standard output.105 */106 private boolean debug;107 108 /**109 106 * Provides a buffer used for incoming data. 110 107 */ … … 126 123 this.useSSL = useSSL; 127 124 this.deviceSide = deviceSide; 128 this.debug = false;129 125 this.input = null; 130 126 this.output = null; … … 136 132 */ 137 133 public void open() throws IOException { 138 close(); 134 if(input != null || output != null || socket != null) { 135 close(); 136 } 139 137 140 138 synchronized(openConnections) { … … 150 148 String connectStr = protocolStr + "://" + serverName + 151 149 ":" + serverPort + paramStr; 152 if (debug) { 153 System.out.println("[OPEN] " + connectStr); 154 } 150 151 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 152 String msg = "Opening connection:\r\n"+connectStr+"\r\n"; 153 EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), EventLogger.DEBUG_INFO); 154 } 155 155 156 socket = (StreamConnection)Connector.open(connectStr, Connector.READ_WRITE, true); 156 157 input = socket.openDataInputStream(); 157 158 output = socket.openDataOutputStream(); 158 159 localAddress = ((SocketConnection)socket).getLocalAddress(); 160 161 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 162 String msg = 163 "Connection established:\r\n"+ 164 "Input: "+input.getClass().toString()+"\r\n"+ 165 "Output: "+input.getClass().toString()+"\r\n"+ 166 "Local address: "+localAddress+"\r\n"; 167 EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), EventLogger.DEBUG_INFO); 168 } 159 169 } 160 170 … … 181 191 } 182 192 } 193 194 EventLogger.logEvent(AppInfo.GUID, "Connection closed".getBytes(), EventLogger.DEBUG_INFO); 183 195 } 184 196 … … 255 267 */ 256 268 if (s.length() == 0) { 257 if (debug) { 258 System.out.println("[SEND]"); 259 } 269 EventLogger.logEvent(AppInfo.GUID, "[SEND]".getBytes(), EventLogger.DEBUG_INFO); 260 270 261 271 output.write(CRLF, 0, 2); … … 277 287 } 278 288 279 if (debug) { 280 System.out.println("[SEND] " + s.substring(i, j)); 281 } 289 EventLogger.logEvent(AppInfo.GUID, ("[SEND] " + s.substring(i, j)).getBytes(), EventLogger.DEBUG_INFO); 282 290 283 291 /** … … 297 305 } 298 306 } 299 output.flush(); // I can't believe this wasn't here before (DK)307 output.flush(); 300 308 } 301 309 … … 312 320 int length = bytes.length; 313 321 314 if (debug) { 315 System.out.println("[SEND] " + s); 316 } 322 EventLogger.logEvent(AppInfo.GUID, ("[SEND RAW]\r\n" + s).getBytes(), EventLogger.DEBUG_INFO); 317 323 318 324 output.write(bytes, 0, bytes.length); … … 386 392 try { 387 393 close(); 388 } catch (IOException ignored) { 389 } 394 } catch (IOException e) { } 390 395 391 396 throw new IOException("Connection closed"); … … 399 404 try { 400 405 Thread.yield(); 401 } catch (Exception ignored) { 402 } 406 } catch (Exception e) { } 403 407 } 404 408 … … 439 443 } 440 444 441 if (debug) { 442 System.out.println("[RECV] " + resultBuffer.toString()); 443 } 445 EventLogger.logEvent(AppInfo.GUID, ("[RECV] " + resultBuffer.toString()).getBytes(), EventLogger.DEBUG_INFO); 444 446 445 447 return resultBuffer.toString(); 446 448 } 447 448 /**449 * Controls the output of debugging information to standard output. Set it to450 * true to see all protocol information exchanged.451 *452 * @see #getDebug453 */454 public void setDebug(boolean debug) {455 this.debug = debug;456 }457 458 /**459 * Queries the current value of the debugging flag.460 *461 * @see #setDebug462 */463 public boolean getDebug() {464 return debug;465 }466 449 } 467 450
