tn5250j/src/org/tn5250j/framework/transport SocketConnector.java,1.2,1.3
Steve Kennedy <[email protected]> Fri, 25 Feb 2005 09:12:06 +0000
| Newsgroups | gmane.comp.java.tn5250j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/transport
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6828/src/org/tn5250j/framework/transport
Modified Files:
SocketConnector.java
Log Message:
SSL Updates
Index: SocketConnector.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/transport/SocketConnector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SocketConnector.java 24 Feb 2005 06:16:09 -0000 1.2
--- SocketConnector.java 25 Feb 2005 09:12:03 -0000 1.3
***************
*** 1,6 ****
! /*
* @(#)SocketConnector.java
! * @author Steve Kennedy
*
* Copyright: Copyright (c) 2001
--- 1,6 ----
! /**
* @(#)SocketConnector.java
! * @author Stephen M. Kennedy
*
* Copyright: Copyright (c) 2001
***************
*** 26,69 ****
import java.net.Socket;
public class SocketConnector {
String sslType = null;
public SocketConnector() {
!
! sslType = System.getProperty(SSLConstants.SSL_TYPE,SSLConstants.SSL_TYPE_NONE);
}
public void setSSLType(String type) {
sslType = type;
}
public Socket createSocket(String destination, int port) {
- try {
! if (sslType.equals(SSLConstants.SSL_TYPE_NONE)) {
! System.out.println("Creating Socket");
! // for jdk 1.4
! // return SocketFactory.getDefault().createSocket(destination,port);
! return new Socket(destination,port);
}
! //Using SSL Socket
! SSLInterface o = null;
! try {
! Class c = Class.forName("org.tn5250j.framework.transport.SSL.SSLImplementation");
! o = (SSLInterface)c.newInstance();
! o.setSSLType(sslType);
! return o.createSSLSocket(destination,port);
}
! catch (Exception e) {
! System.err.println(e);
}
! }
! catch (Exception e) {
! System.err.println("SocketConnector: createSocket: " + e.getMessage());
! }
! return null;
}
}
\ No newline at end of file
--- 26,109 ----
import java.net.Socket;
+ import org.tn5250j.tools.logging.TN5250jLogger;
+
public class SocketConnector {
String sslType = null;
+ TN5250jLogger logger;
+ /**
+ * Creates a new instance that creates a plain socket by default.
+ */
public SocketConnector() {
! logger = TN5250jLogger.getLogger(getClass());
! setSSLType(System.getProperty(SSLConstants.SSL_TYPE,SSLConstants.SSL_TYPE_NONE));
}
+ /**
+ * Set the type of SSL connection to use. Specify null or an empty string
+ * to use a plain socket.
+ * @param type The SSL connection type
+ * @see org.tn5250j.framework.transport.SSLConstants
+ */
public void setSSLType(String type) {
sslType = type;
}
+ /**
+ * Create a new client Socket to the given destination and port. If an SSL
+ * socket type has not been specified <i>(by setSSLType(String))</i>, then
+ * a plain socket will be created. Otherwise, a new SSL socket of the
+ * specified type will be created.
+ * @param destination
+ * @param port
+ * @return a new client socket, or null if
+ */
public Socket createSocket(String destination, int port) {
! Socket socket = null;
! Exception ex = null;
!
! if (sslType == null || sslType.trim().length() == 0 ||
! sslType.toUpperCase().equals(SSLConstants.SSL_TYPE_NONE)) {
! logger.info("Creating Plain Socket");
! try {
! // Use Socket Constructor!!! SocketFactory for jdk 1.4
! socket = new Socket(destination,port);
! } catch (Exception e) {
! ex = e;
! }
! } else { //SSL SOCKET
!
! logger.info("Creating SSL ["+sslType+"] Socket");
!
! SSLInterface sslIf = null;
!
! String sslImplClassName =
! "org.tn5250j.framework.transport.SSL.SSLImplementation";
! try {
! Class c = Class.forName(sslImplClassName);
! sslIf = (SSLInterface)c.newInstance();
! } catch (Exception e) {
! ex = new Exception("Failed to create SSLInterface Instance. " +
! "Message is ["+e.getMessage()+"]");
! }
!
! if (sslIf != null) {
! sslIf.setSSLType(sslType);
! socket = sslIf.createSSLSocket(destination,port);
! }
}
! if (ex != null) {
! logger.error(ex);
}
! if (socket == null) {
! logger.info("No socket was created");
}
! return socket;
}
+
+
}
\ No newline at end of file
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click