The following 2 classes seem to do what I want:
public class HTTPSProxySocketFactory extends SSLSocketFactory {
private SSLSocketFactory dfactory;
private SocketFactory httpProxySocketFactory;
public HTTPSProxySocketFactory(ProxyInfo proxy) {
httpProxySocketFactory = ProxyInfo.forHttpProxy(proxy.getProxyAddress(),
proxy.getProxyPort(), proxy.getProxyUsername(),
proxy.getProxyPassword()).getSocketFactory();
dfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
@Override
public Socket createSocket(
String host, int port)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}
@Override
public Socket createSocket(
String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}
@Override
public Socket createSocket(
InetAddress host, int port)
throws IOException {
return createSocket(null, host.getHostName(), port, true);
}
@Override
public Socket createSocket(
InetAddress address, int port, InetAddress localAddress, int localPort)
throws IOException {
return createSocket(null, address.getHostName(), port, true);
}
@Override
public Socket createSocket(
Socket s, String host, int port, boolean autoClose)
throws IOException, UnknownHostException {
// First of all create a connection to the proxy.
Socket tunnel = httpProxySocketFactory.createSocket(host, port);
return dfactory.createSocket(tunnel, host, port, autoClose);
}
@Override
public String[] getDefaultCipherSuites() {
return dfactory.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return dfactory.getSupportedCipherSuites();
}
}
public class HTTPSProxyInfo extends ProxyInfo {
public HTTPSProxyInfo(String pHost, int pPort, String pUser, String pPass) {
super(null, pHost, pPort, pUser, pPass);
}
@Override
public SocketFactory getSocketFactory() {
return new HTTPSProxySocketFactory(this);
}
}
The code now becomes :
ProxyInfo proxy = new HTTPSProxyInfo(pHost, pPort, pUser, pPass);
String host = “talk.google.com”;
int port = 443;
String serviceName = “googlemail.com”;
ConnectionConfiguration cc = new ConnectionConfiguration(host, port, serviceName, proxy);
XMPPConnection connection = new XMPPConnection(cc);
connection.connect();
Is there a better way to do this using the smack libraries?