2017-05-17 14 views
1
ためjavax.net.ssl.SSLHandshakeException

Javaバージョン1.8.0_121、I see a solution for Java 9 onlyフェッチデータのテキストはSourceForge.net

Description:

を投げるよう私の目標は、総ダウンロードなどSourceForgeプロジェクトに関する情報を取得することですプロジェクトの SourceForgeにはSourceForge Downloads Stats APIというAPIがあります。

私は簡単なプログラムを生のテキストとして見て、私はJSONとしてそれを必要としません。例えば

私はgettings情報についてApache OpenOfficeダウンロードと、より多くの午前 - > Link , you can try it to see

しかし、私は以下のエラーの原因Javaを使用してデータをフェッチすることはできません。私は他のウェブサイトとのコードをテストし、それはうまく動作しますが、この1つの理由は分かりません。

Error:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal a 
lert: handshake_failure 
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) 
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023) 
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125) 
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:13 
75) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) 
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) 
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Abstra 
ctDelegateHttpsURLConnection.java:185) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnectio 
n.java:1546) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection 
.java:1474) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLCon 
nectionImpl.java:254) 
    at aaTester.URLReader.main(URLReader.java:13) 

import java.net.*; 
import java.io.*; 

public class URLReader { 
    public static void main(String[] args) throws Exception { 

     //Create HttpURLConnection 
     HttpURLConnection httpcon = (HttpURLConnection) new URL(
       "https://sourceforge.net/projects/openofficeorg.mirror/files/stats/json?start_date=2014-10-29&end_date=2014-11-04").openConnection(); 
     //In case it might to the trick... 
     httpcon.addRequestProperty("User-Agent", "Mozilla/5.0"); 
     //Read the inputstream 
     BufferedReader in = new BufferedReader(new InputStreamReader(httpcon.getInputStream())); 

     //Print everything 
     String inputLine; 
     while ((inputLine = in.readLine()) != null) 
      System.out.println(inputLine); 
     in.close(); 
    } 
} 

Java Code:

最後

上記大幅に理解されるで溶液。

アンディの答えを使用しようとすると、同じエラーが発生します。

+1

[そのサーバは明らかに256ビットAESを使用する暗号スイートしかサポートしていません](https://www.ssllabs.com/ssltest/analyze.html?d=sourceforge.net)と_Oracle_ Java(vice OpenJDK)はそのまま使用できます256ビットの対称暗号は使用できません。 j8の場合はhttp://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.htmlを参照するか、以前のバージョンのアーカイブ・セクションを試してください。 –

+0

@ dave_thompson_085 O_Oうわー、私はそれを知りませんでした...対称暗号を使って例を挙げるなら、私は受け入れボタンを15回クリックします。 – GOXR3PLUS

+0

@ dave_thompson_085私はポータブルな私のアプリケーションが必要です[ライブラリにjarファイルを追加したい]ので、私はhttp://stackoverflow.com/questions/1828775/how-to-handle-invalid-ssl-certificates-with- apache-httpclientしかし、私はそれを行うために完全なハックを参照してください...あなたが研究する正しい方法に私を指示してくれてありがとう:) – GOXR3PLUS

答えて

0

以下は、実際に必要なダウンロードを取得するためのものです。これは完全な答えではありません。

To get the downloads per week/day/year you can just change a little bit the code to remove the innapropriate text.

Check the text that is returned from the BufferedReaded as i did for total downloads.

import java.io.BufferedReader; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 
import java.util.Arrays; 


public class URLReader { 
    public static void main(String[] args) throws Exception { 

     //System.out.println(Cipher.getMaxAllowedKeyLength("AES")); 

     //Create HttpURLConnection 
     HttpURLConnection httpcon = (HttpURLConnection) new URL("https://img.shields.io/sourceforge/dt/xr3player.svg").openConnection(); 
     httpcon.addRequestProperty("User-Agent", "Mozilla/5.0"); 
     BufferedReader in = new BufferedReader(new InputStreamReader(httpcon.getInputStream())); 

     //Read line by line 
     String line = "" , inputLine; 
     while ((inputLine = in.readLine()) != null) { 
      line += "\n" + inputLine; 
      System.out.println(inputLine); 
     } 
     in.close(); 

     //Get SourceForge Downloads 
     System.out.println("Total Downlads: "+line.split("<text x=\"98.5\" y=\"14\">")[1].split("/total")[0]); 
    } 

} 
0

エンドユーザーにポリシーがインストールされていることを要求することはできませんが、ポリシーの適用に関するプログラム的な方法があります。 免責事項:これは推奨されておらず、TOSとITARの意味合いがあるかもしれません。

このコードは、TLSネゴシエーションの前にstaticブロックで実行され、JVMがAES-256暗号スイートを使用できるようにする必要があります。

if (Cipher.getMaxAllowedKeyLength("AES") < 256) { 
    try { 
    Field field = Class.forName("javax.crypto.JceSecurity"). 
    getDeclaredField("isRestricted"); 
    field.setAccessible(true); 
    field.set(null, java.lang.Boolean.FALSE); 
    } catch (Exception e) { 
    fail("Could not override JCE cryptography strength policy setting"); 
    fail(e.getMessage()); 
    } 
} 
+0

私はHttpURLConnectionの前にコード内でそれを使用していますが、再び同じエラー。 – GOXR3PLUS

+1

私は前にリンクについて間違っていたので、このリンクに基づいて - > http://stackoverflow.com/questions/1179672/how-to-avoid-installing-unlimited-strength-jce-policy-files-when-deploying-今からJava 9をプロダクションで使用しているようです:) – GOXR3PLUS

+0

Groovyを使用してオーバーライドすることはできますが、試していないと思います。 – Andy

1

は答えにGOXR3PLUS @からcommentを回す:

ここ

はSourceForgeのは、ダウンロードのために提供されていることをsvg imageを使用して累計ダウンロード数を取得するトリッキーな方法です。少なくともJava 8u161(またはJava 9)にアップグレードすると、SSLHandshakeExceptionはSourceForgeからダウンロードする必要がなくなります。

+0

テストしよう:) – GOXR3PLUS

関連する問題