开发者

Using Axis2 to login to SharePoint via Java using HTTPS

开发者 https://www.devze.com 2022-12-20 02:19 出处:网络
I\'m trying to access a SharePoint server using Java (and Axis2 as the mechanism for creating classes from the WSDL). I can login and do some operation if the site is hosted through HTTP but through H

I'm trying to access a SharePoint server using Java (and Axis2 as the mechanism for creating classes from the WSDL). I can login and do some operation if the site is hosted through HTTP but through HTTPS it's failing.开发者_StackOverflow Does anyone have any experience doing this or know of a good resource for getting help with this?

Thanks.


The safe bet is that your connection to a secure site is failing because your connection isn't accepting the SSL cert being provided. To test this, run the following code before connecting:

public static void trustAllSSL() {

    TrustManager[] trustAllCerts = new TrustManager[] {
            new X509TrustManager() {
                public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
                public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
                public X509Certificate[] getAcceptedIssuers() { return null; }
            }
    };
    HostnameVerifier hostVerify = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(hostVerify);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

If you can then connect using Axis2 after running the above code, then that's the reason. You can then either continue to use the above code, or go and get the actual cert from the site (use IE or Firefox to access the site, then get the cert from it's cache) and add it to your keystore for Java.

0

精彩评论

暂无评论...
验证码 换一张
取 消