Search in sources :

Example 1 with SocketConnection

use of org.jsmpp.session.connection.socket.SocketConnection in project camel by apache.

the class SmppConnectionFactory method createConnection.

public Connection createConnection(String host, int port) throws IOException {
    try {
        Socket socket;
        SocketFactory socketFactory;
        socketFactory = config.getUsingSSL() && config.getHttpProxyHost() == null ? SSLSocketFactory.getDefault() : SocketFactory.getDefault();
        if (config.getHttpProxyHost() != null) {
            // setup the proxy tunnel
            socket = socketFactory.createSocket(config.getHttpProxyHost(), config.getHttpProxyPort());
            connectProxy(host, port, socket);
        } else {
            socket = socketFactory.createSocket(host, port);
        }
        if (config.getUsingSSL() && config.getHttpProxyHost() != null) {
            // Init the SSL socket which is based on the proxy socket
            SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);
            sslSocket.startHandshake();
            socket = sslSocket;
        }
        return new SocketConnection(socket);
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}
Also used : SocketConnection(org.jsmpp.session.connection.socket.SocketConnection) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SocketFactory(javax.net.SocketFactory) SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Socket (java.net.Socket)1 SocketFactory (javax.net.SocketFactory)1 SSLSocket (javax.net.ssl.SSLSocket)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 SocketConnection (org.jsmpp.session.connection.socket.SocketConnection)1