I got the following exception when try to post a request to a http server:
Here is the code I used
URL url = new URL(
\"https://www.abc.com\"
Set validateTLSCertificates
property to false
for your JSoup command.
Jsoup.connect("https://google.com/").validateTLSCertificates(false).get();
If you want to ignore the certificate all together then take a look at the answer here: Ignore self-signed ssl cert using Jersey Client
Although this will make your app vulnerable to man-in-the-middle attacks.
Or, try adding the cert to your java store as a trusted cert. This site may be helpful. http://blog.icodejava.com/tag/get-public-key-of-ssl-certificate-in-java/
Here's another thread showing how to add a cert to your store. Java SSL connect, add server cert to keystore programmatically
The key is:
KeyStore.Entry newEntry = new KeyStore.TrustedCertificateEntry(someCert);
ks.setEntry("someAlias", newEntry, null);
If you're using CloudFoundry then you'd have to explicitly push the jar along with the keystore having the certificate.
I also faced this issue. I was having JDK 1.8.0_121
. I upgraded JDK to 1.8.0_181
and it worked like a charm.
FWIW, on Ubuntu 10.04.2 LTS installing the ca-certificates-java and the ca-certificates packages fixed this problem for me.
I got the same error while executing the below spring-boot + RestAssured simple test.
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static com.jayway.restassured.RestAssured.when;
import static org.apache.http.HttpStatus.SC_OK;
@RunWith(SpringJUnit4ClassRunner.class)
public class GeneratorTest {
@Test
public void generatorEndPoint() {
when().get("https://bal-bla-bla-bla.com/generators")
.then().statusCode(SC_OK);
}
}
The simple fix in my case is to add 'useRelaxedHTTPSValidations()'
RestAssured.useRelaxedHTTPSValidation();
Then the test looks like
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static com.jayway.restassured.RestAssured.when;
import static org.apache.http.HttpStatus.SC_OK;
@RunWith(SpringJUnit4ClassRunner.class)
public class GeneratorTest {
@Before
public void setUp() {
RestAssured.useRelaxedHTTPSValidation();
}
@Test
public void generatorEndPoint() {
when().get("https://bal-bla-bla-bla.com/generators")
.then().statusCode(SC_OK);
}
}