2017-01-13 1 views
1

J'essaie d'utiliser un UrlConnection pour envoyer de l'audio (représenté comme un tableau d'octets de base64 - comme demandé par l'API Google Cloud Speech). Je le fais sur un Raspberry Pi avec ubuntu. La connexion fonctionne si je l'utilise sur mon ordinateur portable (également avec ubuntu). J'utilise Java avec un URLConnection. L'incident se produit sur OutputStream out = urlConnection.getOutputStream();urlconnection javax.net.ssl.SSLException: java.lang.IllegalStateException

code Java:

// URL to google + parameter with the API key. 
    URL googleUrl = new URL(GOOGLE_RECOGNIZER_URL + "?key=" + APIKEY); 

    // Open New URL connection channel. 
    URLConnection urlConnection; 

    urlConnection = googleUrl.openConnection(); 

    // we want to do output. (input is automaticly set on true). 
    urlConnection.setDoOutput(true); 

    // No caching. 
    urlConnection.setUseCaches(false); 

    // Add headers. 
    urlConnection.setRequestProperty("Content-Type", "application/json"); 

// For sending the recorded data to google it needs to be first 
    // converted to a byte array. 
    byte[] array1 = AudioToByteArray.readAudioFileData(file); 

    // And next convert the byte array to a base64 string. 
    String audioString = Base64.getEncoder().encodeToString(array1); 

    // Make (JSON) Strings for configuration and location of audio file. 
    String testConfig = "\"config\": { \"encoding\":\"LINEAR16\", \"sampleRate\": 16000, \"languageCode\": \"nl-NL\"}"; 
    String testAudioLoc = "\"audio\": { \"content\": \"" + audioString + "\" }"; 
    String together = "{ " + testConfig + "," + testAudioLoc + " }"; 

    // Send the string to google. 
    OutputStream out = urlConnection.getOutputStream(); 

    OutputStreamWriter wr = new OutputStreamWriter(out); 
    wr.write(together); 
    wr.flush(); 
    wr.close(); 
    out.close(); 

Erreur:

javax.net.ssl.SSLException: java.lang.IllegalStateException 
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) 
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) 
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1906) 
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1889) 
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1410) 
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(AbstractDelegateHttpsURLConnection.java:185) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316) 
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291) 
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) 
at main.ContactGoogleCloudSpeechAPI.writeOut(ContactGoogleCloudSpeechAPI.java:98) 
at main.ContactGoogleCloudSpeechAPI.contactGoogleUrlCon(ContactGoogleCloudSpeechAPI.java:41) 
at main.SpeechRecognition.contactAPI(SpeechRecognition.java:184) 
at main.SpeechRecognition.mainLoop(SpeechRecognition.java:104) 
at main.SpeechRecognition.run(SpeechRecognition.java:81) 
at main.SpeechRecognition.main(SpeechRecognition.java:62) 
+0

http://stackoverflow.com/questions/37167189/illegalstateexception-thrown-by-maven-ssl-related-when-downloading-project-de résolu pour moi –

Répondre

0

Je recevais la même exception, et réalisé que j'utilisais OpenJDK

Donc, la solution consiste à désinstaller OpenJDK et installer Oracle JDK

Vous pouvez vérifier quelle version de JDK utilisez-vous le fol? commande mugissement:

java -version