Essentially, I wish to produce a test client that will send Publish and obtain demands to some server using HTTPS protocol.
I'm using apache HttpClient 4.1
Sample of test client is really as below.
class A extends Runnable
{
HttpClient httpClient;
A()
{
createHttpClient(443);
}
private void createHttpClient(int port) {
try {
java.lang.System.setProperty(
"sun.security.ssl.allowUnsafeRenegotiation", "true");
// First create a trust manager that won't care.
X509TrustManager trustManager = new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
// Don't do anything.
return null;
}
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] chain,
String authType)
throws java.security.cert.CertificateException {
// TODO Auto-generated method stub
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] chain,
String authType)
throws java.security.cert.CertificateException {
// TODO Auto-generated method stub
}
};
// Now put the trust manager into an SSLContext.
// Supported: SSL, SSLv2, SSLv3, TLS, TLSv1, TLSv1.1
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[] { trustManager },
new SecureRandom());
// Use the above SSLContext to create your socket factory
// Accept any hostname, so the self-signed certificates don't fail
SSLSocketFactory sf = new SSLSocketFactory(sslContext,
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// Register our new socket factory with the typical SSL port and the
// correct protocol name.
Scheme httpsScheme = new Scheme("https", port, sf);
this.httpclient = new DefaultHttpClient();
this.httpclient.getConnectionManager().getSchemeRegistry()
.register(httpsScheme);
} catch (Exception ex) {
System.out.println("=== Error Creating SSL Connection: "
+ ex.getMessage());
this.httpclient = null;
}
}
public void run()
{
if(this.login())
{
this.getStartPage();
this.sendPageRequests();
}
}
}
Above code works fine however it spawns up-to simply 60-70 threads though I'm breeding a lot more than 1000 threads. With HTTP it had been breeding a lot more than 1000 threads but after adding support for HTTPS, when i stated earlier only 60-70 synchronised threads were seen i.e. after createHttpClient(int port). I just read about ThreadSafeClientConnManager()
and each other things associated with it. But could not get much from it.
Could anybody please guide me why this really is happening? What must i do?