- Timestamp:
- 08/01/09 11:09:20 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java
r471 r477 60 60 package org.logicprobe.LogicMail.util; 61 61 62 import net.rim.device.api.crypto.tls.tls10.TLS10Connection; 62 63 import net.rim.device.api.system.EventLogger; 63 64 import net.rim.device.api.ui.UiApplication; 64 65 import net.rim.device.api.ui.component.Dialog; 65 66 import net.rim.device.api.util.DataBuffer; 67 import net.rim.device.cldc.io.ssl.TLSException; 66 68 67 69 import org.logicprobe.LogicMail.AppInfo; … … 69 71 import org.logicprobe.LogicMail.conf.MailSettings; 70 72 73 import java.io.DataInputStream; 74 import java.io.DataOutputStream; 71 75 import java.io.IOException; 72 76 import java.io.InputStream; … … 614 618 return result; 615 619 } 620 621 /** 622 * Switches the underlying connection to SSL mode, as commonly done after 623 * sending a <tt>STARTTLS</tt> command to the server. 624 * 625 * @throws IOException Signals that an I/O exception has occurred. 626 */ 627 public void startTLS() throws IOException { 628 // Shortcut the method if we're already in SSL mode 629 if(socket instanceof TLS10Connection) { return; } 630 631 try { 632 TLS10Connection tlsSocket = new TLS10Connection( 633 new StreamConnectionWrapper( 634 socket, 635 (DataInputStream)input, 636 (DataOutputStream)output), 637 serverName + ':' + serverPort, 638 true); 639 640 socket = tlsSocket; 641 input = socket.openDataInputStream(); 642 output = socket.openDataOutputStream(); 643 } catch (IOException e) { 644 EventLogger.logEvent(AppInfo.GUID, 645 ("Unable to switch to TLS mode: " + e.getMessage()).getBytes(), EventLogger.ERROR); 646 throw new IOException("Unable to switch to TLS mode"); 647 } catch (TLSException e) { 648 EventLogger.logEvent(AppInfo.GUID, 649 ("Unable to switch to TLS mode: " + e.getMessage()).getBytes(), EventLogger.ERROR); 650 throw new IOException("Unable to switch to TLS mode"); 651 } 652 } 653 654 /** 655 * Decorator to wrap an existing stream connection so its I/O streams 656 * can be reopened without throwing exceptions. 657 */ 658 private static class StreamConnectionWrapper implements StreamConnection { 659 private StreamConnection stream; 660 private DataInputStream dataInputStream; 661 private DataOutputStream dataOutputStream; 662 663 public StreamConnectionWrapper(StreamConnection stream, DataInputStream dataInputStream, DataOutputStream dataOutputStream) { 664 this.stream = stream; 665 this.dataInputStream = dataInputStream; 666 this.dataOutputStream = dataOutputStream; 667 } 668 669 public DataInputStream openDataInputStream() throws IOException { 670 return dataInputStream; 671 } 672 public InputStream openInputStream() throws IOException { 673 return dataInputStream; 674 } 675 public void close() throws IOException { 676 stream.close(); 677 } 678 public DataOutputStream openDataOutputStream() throws IOException { 679 return dataOutputStream; 680 } 681 public OutputStream openOutputStream() throws IOException { 682 return dataOutputStream; 683 } 684 } 616 685 }
Note: See TracChangeset
for help on using the changeset viewer.
