Error in consuming https web service even after disabling trust manager

pise

I am getting below error even after disabling the TrustManager

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

Below is the code I am using to consumer web service.

public class HttpsDisable {


public static void disableCertificateValidation() {
      TrustManager[] trustAllCerts = new TrustManager[]{
        new X509TrustManager() {
          public X509Certificate[] getAcceptedIssuers() { return null; }
          public void checkClientTrusted(X509Certificate[] certs, String authType) { }
          public void checkServerTrusted(X509Certificate[] certs, String authType) { }
        }
      };
      try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      } catch (Exception e) {
          e.printStackTrace();
      }
    }


public static void main(String[] args)  {


                //Now you can access an https URL without having the certificate in the truststore
                try {
                 disableCertificateValidation();
                 URL url = new URL("https://162.19.122.114/service.asmx?wsdl");
                 System.out.println("url ================ "+url);

                 String sWebserviceurl = "https://172.17.134.214/service.asmx?wsdl";
                 String sXMLInput = "<KeedAn><PrAge>26</PrAge></KeedAn>";
                    AnalysisServiceService sl = new AnalysisServiceServiceLocator();
                    AnalysisService service =  sl.getAnalysisService(new URL(sWebserviceurl));
                    String in = service.getNeedProdRes(sXMLInput);
                    System.out.println("web service output ----------\n" + in);

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                catch (Exception e) {
                    e.printStackTrace();
                }

}   
}

Can you please tell me where am I going wrong, since the above code is not working and throws above exception. And I have also save the .cert file in jre/lib/.cert path.

Selvaraj

Try this code, It will disable and print response in console,

String send = "https://www.example.com";
        URL url = new URL(send);
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
        {
            public java.security.cert.X509Certificate[] getAcceptedIssuers()
            {
                return null;
            }

            public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
            {
            }

            public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
            {
            }
        } };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        IOUtils.copy(url.openStream(), System.out);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Role Manager not enabled. Even after changing web.config

분류에서Dev

Trust Manager를 비활성화 한 후에도 https 웹 서비스 사용 오류

분류에서Dev

Invoke a web service on HTTPS from a worklight adapter

분류에서Dev

Disabling Web camera

분류에서Dev

Angular $http.get always get ERROR consuming local Restful Service

분류에서Dev

Web Service Endpoint identity error

분류에서Dev

Consuming Web API and class information

분류에서Dev

Why does consuming a RESTful web service (using javax.ws.rs.* and Jsersey) work in unit test but not when submitted to Spark?

분류에서Dev

App works on Simulator but not on device.Https web service issue

분류에서Dev

Amazon Web Service ECS (SSL / HTTPS) 문제

분류에서Dev

Consuming REST service with basic authentication from MULE

분류에서Dev

virt-manager PCI passthrough gives error "No IOMMU Found" even w/ Intel IOMMU enabled

분류에서Dev

Aw snap Chromium error even after clearing cache Ubuntu

분류에서Dev

IndexError : list index out of range : error even after the list is not

분류에서Dev

JAVA Runtime error in uva online judge even after formatting input

분류에서Dev

"Maximum request length exceeded" error even after setting maxAllowedContentLength

분류에서Dev

Why is a link removed when disabling a service? (a file is not)

분류에서Dev

Xcode: Enable Create Git Repository after disabling it

분류에서Dev

Azure Service Fabric-Owin의 Web Api-https 문제

분류에서Dev

PHP output JSON Web Service charset UTF-8 error

분류에서Dev

HTTP Post Request to web service . ERROR : Index was outside the bounds of the array

분류에서Dev

Disabling ntp.service for the boot, since it takes a long time

분류에서Dev

Cannot use fgets() to read file after "consuming it up"?

분류에서Dev

Error when importing jar file in Eclipse (even after adding it to the build path)

분류에서Dev

SVN + Nginx + HTTPS 용 SCM-Manager

분류에서Dev

After disabling Vertex Attribute Array how glDrawArrays() works?

분류에서Dev

Repeating Alarm Manager After reboot

분류에서Dev

Wildfly Web Service JAXB Unmarshall Error when coming from .net client

분류에서Dev

403 error page is not working in my web service which is running on a Tomcat 7

Related 관련 기사

  1. 1

    Role Manager not enabled. Even after changing web.config

  2. 2

    Trust Manager를 비활성화 한 후에도 https 웹 서비스 사용 오류

  3. 3

    Invoke a web service on HTTPS from a worklight adapter

  4. 4

    Disabling Web camera

  5. 5

    Angular $http.get always get ERROR consuming local Restful Service

  6. 6

    Web Service Endpoint identity error

  7. 7

    Consuming Web API and class information

  8. 8

    Why does consuming a RESTful web service (using javax.ws.rs.* and Jsersey) work in unit test but not when submitted to Spark?

  9. 9

    App works on Simulator but not on device.Https web service issue

  10. 10

    Amazon Web Service ECS (SSL / HTTPS) 문제

  11. 11

    Consuming REST service with basic authentication from MULE

  12. 12

    virt-manager PCI passthrough gives error "No IOMMU Found" even w/ Intel IOMMU enabled

  13. 13

    Aw snap Chromium error even after clearing cache Ubuntu

  14. 14

    IndexError : list index out of range : error even after the list is not

  15. 15

    JAVA Runtime error in uva online judge even after formatting input

  16. 16

    "Maximum request length exceeded" error even after setting maxAllowedContentLength

  17. 17

    Why is a link removed when disabling a service? (a file is not)

  18. 18

    Xcode: Enable Create Git Repository after disabling it

  19. 19

    Azure Service Fabric-Owin의 Web Api-https 문제

  20. 20

    PHP output JSON Web Service charset UTF-8 error

  21. 21

    HTTP Post Request to web service . ERROR : Index was outside the bounds of the array

  22. 22

    Disabling ntp.service for the boot, since it takes a long time

  23. 23

    Cannot use fgets() to read file after "consuming it up"?

  24. 24

    Error when importing jar file in Eclipse (even after adding it to the build path)

  25. 25

    SVN + Nginx + HTTPS 용 SCM-Manager

  26. 26

    After disabling Vertex Attribute Array how glDrawArrays() works?

  27. 27

    Repeating Alarm Manager After reboot

  28. 28

    Wildfly Web Service JAXB Unmarshall Error when coming from .net client

  29. 29

    403 error page is not working in my web service which is running on a Tomcat 7

뜨겁다태그

보관