Web services call for Secure sites like Https:\\ | Selenium Forum
M
Posted on 30/03/2016
Hello,
Can some one help me on this:
I need to login into secured site and use Get method to login the site. But not allowiing as it has SSL exception
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.


Code snippet is below:


public int StartAppInTomcat(String UserName, String Password)throws Exception {


HttpClient httpClient = new SigniantPage().getHttpClient();
httpClient.getCredentialsProvider().setCredentials(new AuthScope("sig-mgt-owm.pii.pxl.int", Integer.valueOf(80)),new UsernamePasswordCredentials(UserName, Password));
/*HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 2000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 2000);*/
HttpResponse response = null;
try {
HttpGet httpGetRequest = new HttpGet("https://xx.com");
HttpResponse Response = httpClient.execute(httpGetRequest);
} catch (ClientProtocolException e) {

} catch (IOException e) {
// TODO Auto-generated catch block
}
return response.getStatusLine().getStatusCode();
}





public CloseableHttpClient getHttpClient()
{
HttpClientBuilder httpclicnt= HttpClientBuilder.create() ;
RequestConfig requestConfig = RequestConfig.custom()
/* .setSocketTimeout("",2000)
.setConnectTimeout(3000)
*/ .build();

SSLContextBuilder builder = new SSLContextBuilder();
SSLConnectionSocketFactory sslsf = null;
try {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
sslsf = new SSLConnectionSocketFactory(builder.build());
} catch (Exception e) {
System.out.println(e.toString());
}
return httpclicnt.setDefaultRequestConfig(requestConfig).setSSLSocketFactory(sslsf).build();
}

Thanks

M
Replied on 30/03/2016

you have to use post request for login. you're using get.