System.setProperty("javax.net.ssl.trustStore", "C:\Program Files\Java\jdk-18.0.2.1\lib\security\cacerts"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); i added these lines in my method it is now working fine