0

I'm trying to connect to a web service that uses the client/server mutual connection, it throws me a NoSuchAlgorithmException, when i run the same code as an standard java application it works great but when i try to run as a web application i get the exception, any idea to solve this issue?

The Code:

try {

        System.setProperty("javax.net.debug", "ssl,handshake");
        System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
        System.setProperty("javax.net.ssl.keyStore", "c:\\Sifen\\F1T_5159.p12");
        System.setProperty("javax.net.ssl.keyStorePassword", "password");
        
        String soapRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsd=\"http://ekuatia.set.gov.py/sifen/xsd\">\n"
                + "<soap:Header/>\n"
                + "<soap:Body>\n"
                + "<xsd:rEnviConsRUC xmlns=\"http://ekuatia.set.gov.py/sifen/xsd\"\n"
                + "                xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
                + "                xsi:schemaLocation=\"http://ekuatia.set.gov.py/sifen/xsd/ siConsRUC_v150.xsd\">\n"
                + "    <xsd:dId>1</xsd:dId>\n"
                + "    <xsd:dRUCCons>80033703</xsd:dRUCCons>\n"
                + "</xsd:rEnviConsRUC>\n"
                + "</soap:Body>\n"
                + "</soap:Envelope>";

        String url = "https://sifen-test.set.gov.py/de/ws/consultas/consulta-ruc.wsdl";

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        con.setDoOutput(true);
        
        try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
            wr.writeBytes(soapRequest);
            wr.flush();
        }
        
        String responseStatus = con.getResponseMessage();
        System.out.println(responseStatus);
        BufferedReader in = new BufferedReader(new InputStreamReader(
                con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        String finalvalue = response.toString();
        System.out.println(finalvalue);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

The Result java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)

Again: when i run it as a java standard aplication works fine, i only get the exception if i run as a web application

Any ideas? Please help, thanks.

5
  • stackoverflow.com/q/9761575/14056755 Commented Mar 18, 2023 at 19:49
  • Hi Marcin, thanks for your reply, i had seen this post but it did not help me because its relative to bad password, in my case i think that is not the problem because the code works fine with that password in a standard java application but fails when i run the same code in java web application Commented Mar 18, 2023 at 20:15
  • what does it mean in a standard java application? Pls describe more specifically how you invoke it on these two approaches Commented Mar 20, 2023 at 9:15
  • I have to connect to a web service that requires the mutual authentication (it is not my server, it is a government server), to connect with it i made a web service on my client side (with java web application and Restful Web Service [A Web Service that connects to another Web Service]), when i try to connect using that application (with the above code) the server return me that exception but when i put the same code in a java standard application (a java desk application - Not a web application) it returns the expected result, Thanks Marcin Commented Mar 20, 2023 at 11:34
  • Hi Marcin, after a couple of days around this issue i finally solve it, it was the certificate, after import my .cer certificate at C:\Program Files\Java\jdk1.8.0_202\jre\lib\security\cacerts (with KeyStore Explorer tool) it works like a swiss clock, thank you very much Commented Mar 21, 2023 at 14:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.