urlconnection javax.net.ssl.SSLException:java.lang.IllegalStateException

时间:2017-01-13 15:20:59

标签: java ubuntu outputstream urlconnection

我尝试使用UrlConnection发送音频(表示为base64字节数组 - 根据Google Cloud Speech API的要求)。我在使用ubuntu的Raspberry Pi上做这个。如果我在笔记本电脑上使用它(也使用ubuntu),连接确实有效。我正在使用带有URLConnection的java。崩溃发生在OutputStream out = urlConnection.getOutputStream();

Java代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^subdirectory/?$ http://newurl.com [L,R=301,NC]

错误:

// 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();

1 个答案:

答案 0 :(得分:0)

我得到了同样的例外,并意识到我正在使用openJDK

所以解决方案是卸载openJDK并安装oracle JDK

您可以使用以下命令检查您使用的JDK版本:

order by abs(sortcolumn - 3) asc