Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/transport/SocketConnector.java @ 8:3b760b39962a tn5250
adding tn5250 files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 15:41:35 -0700 |
parents | e8d2a24e85c6 |
children | e773d0952613 |
comparison
equal
deleted
inserted
replaced
7:3248b46f3973 | 8:3b760b39962a |
---|---|
23 */ | 23 */ |
24 package org.tn5250j.framework.transport; | 24 package org.tn5250j.framework.transport; |
25 | 25 |
26 import java.net.Socket; | 26 import java.net.Socket; |
27 | 27 |
28 import org.tn5250j.framework.transport.SSL.SSLImplementation; | |
28 import org.tn5250j.TN5250jConstants; | 29 import org.tn5250j.TN5250jConstants; |
29 import org.tn5250j.tools.logging.TN5250jLogFactory; | 30 import org.tn5250j.tools.logging.TN5250jLogFactory; |
30 import org.tn5250j.tools.logging.TN5250jLogger; | 31 import org.tn5250j.tools.logging.TN5250jLogger; |
31 | 32 |
32 public class SocketConnector { | 33 public class SocketConnector { |
42 logger = TN5250jLogFactory.getLogger(getClass()); | 43 logger = TN5250jLogFactory.getLogger(getClass()); |
43 } | 44 } |
44 | 45 |
45 /** | 46 /** |
46 * Set the type of SSL connection to use. Specify null or an empty string | 47 * Set the type of SSL connection to use. Specify null or an empty string |
47 * to use a plain socket. | 48 * to use a plain socket. |
48 * @param type The SSL connection type | 49 * @param type The SSL connection type |
49 * @see org.tn5250j.framework.transport.SSLConstants | 50 * @see org.tn5250j.framework.transport.SSLConstants |
50 */ | 51 */ |
51 public void setSSLType(String type) { | 52 public void setSSLType(String type) { |
52 sslType = type; | 53 sslType = type; |
53 } | 54 } |
54 | 55 |
55 /** | 56 /** |
56 * Create a new client Socket to the given destination and port. If an SSL | 57 * Create a new client Socket to the given destination and port. If an SSL |
57 * socket type has not been specified <i>(by setSSLType(String))</i>, then | 58 * socket type has not been specified <i>(by setSSLType(String))</i>, then |
58 * a plain socket will be created. Otherwise, a new SSL socket of the | 59 * a plain socket will be created. Otherwise, a new SSL socket of the |
59 * specified type will be created. | 60 * specified type will be created. |
60 * @param destination | 61 * @param destination |
61 * @param port | 62 * @param port |
62 * @return a new client socket, or null if | 63 * @return a new client socket, or null if |
63 */ | 64 */ |
64 public Socket createSocket(String destination, int port) { | 65 public Socket createSocket(String destination, int port) { |
65 | 66 |
66 Socket socket = null; | 67 Socket socket = null; |
67 Exception ex = null; | 68 Exception ex = null; |
68 | 69 |
69 if (sslType == null || sslType.trim().length() == 0 || | 70 if (sslType == null || sslType.trim().length() == 0 || |
70 sslType.toUpperCase().equals(TN5250jConstants.SSL_TYPE_NONE)) { | 71 sslType.toUpperCase().equals(TN5250jConstants.SSL_TYPE_NONE)) { |
71 logger.info("Creating Plain Socket"); | 72 logger.info("Creating Plain Socket"); |
72 try { | 73 try { |
73 // Use Socket Constructor!!! SocketFactory for jdk 1.4 | 74 // Use Socket Constructor!!! SocketFactory for jdk 1.4 |
74 socket = new Socket(destination,port); | 75 socket = new Socket(destination,port); |
75 } catch (Exception e) { | 76 } catch (Exception e) { |
76 ex = e; | 77 ex = e; |
77 } | 78 } |
78 } else { //SSL SOCKET | 79 } else { //SSL SOCKET |
79 | 80 |
80 logger.info("Creating SSL ["+sslType+"] Socket"); | 81 logger.info("Creating SSL ["+sslType+"] Socket"); |
81 | 82 |
82 SSLInterface sslIf = null; | 83 SSLInterface sslIf = null; |
83 | 84 |
84 String sslImplClassName = | |
85 "org.tn5250j.framework.transport.SSL.SSLImplementation"; | |
86 try { | 85 try { |
87 Class<?> c = Class.forName(sslImplClassName); | 86 sslIf = (SSLInterface) new SSLImplementation(); |
88 sslIf = (SSLInterface)c.newInstance(); | |
89 } catch (Exception e) { | 87 } catch (Exception e) { |
90 ex = new Exception("Failed to create SSLInterface Instance. " + | 88 ex = new Exception("Failed to create SSLInterface Instance. " + |
91 "Message is ["+e.getMessage()+"]"); | 89 "Message is ["+e.getMessage()+"]"); |
92 } | 90 } |
93 | 91 |
94 if (sslIf != null) { | 92 if (sslIf != null) { |
95 sslIf.init(sslType); | 93 sslIf.init(sslType); |
96 socket = sslIf.createSSLSocket(destination,port); | 94 socket = sslIf.createSSLSocket(destination,port); |
97 } | 95 } |
98 } | 96 } |
103 if (socket == null) { | 101 if (socket == null) { |
104 logger.warn("No socket was created"); | 102 logger.warn("No socket was created"); |
105 } | 103 } |
106 return socket; | 104 return socket; |
107 } | 105 } |
108 | 106 |
109 | 107 |
110 } | 108 } |