背景
笔者最近在项目中使用websocket,通过nginx进行代理,配置如下
server { listen 443 ssl; server_name www.example.com; ssl on; ssl_certificate www.example.com+5.pem; ssl_certificate_key www.example.com+5-key.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; #charset koi8-r; access_log logs/aiPlatform/access_log; error_log logs/aiPlatform/error_log error; location /wsapi/asr { proxy_pass http://127.0.0.1:81/api/asr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location /wsapi/asrv2 { proxy_pass http://127.0.0.1:81/api/asrv2; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location /wsapi/tts { proxy_pass http://127.0.0.1:81/wsapi/tts; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } }
本地Host文件配置如下
172.112.35.5 www.example.com
一开始在java中通过SDK方式调用,可以运行的。
关键代码
public static void main(String[] args) throws URISyntaxException, InterruptedException, IOException { String WS_URL = "ws://127.0.0.1:81/api/asrv2"; WS_URL="wss://www.example.com/wsapi/asrv2"; URI uri = new URI(WS_URL); CountDownLatch connectClose = new CountDownLatch(1); TestASRByChunkClient client = new TestASRByChunkClient(uri, connectClose); client.sendByStep(); client.sendEOS(); connectClose.await(); }
错误信息:
"D:\Program Files\Java\jdk1.8.0_111\bin\java.exe" "-javaagent:D:\develop\IntelliJ IDEA 2018.3.4.2\lib\idea_rt.jar=43128:D:\develop\IntelliJ IDEA 2018.3.4.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;F:\ai开放平台\SRC\web\target\test-classes;F:\ai开放平台\SRC\web\target\classes;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-spring-boot-starter\2.1.3\mapper-spring-boot-starter-2.1.3.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-jdbc\2.0.2.RELEASE\spring-boot-starter-jdbc-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\com\zaxxer\HikariCP\2.7.9\HikariCP-2.7.9.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-jdbc\5.0.6.RELEASE\spring-jdbc-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;D:\develop\apache-maven-3.5.4\repo\org\mybatis\mybatis-spring\1.3.2\mybatis-spring-1.3.2.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-core\1.1.3\mapper-core-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\javax\persistence\persistence-api\1.0\persistence-api-1.0.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-base\1.1.3\mapper-base-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-weekend\1.1.4.5\mapper-weekend-1.1.4.5.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-spring\1.1.3\mapper-spring-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-extra\1.1.3\mapper-extra-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\tk\mybatis\mapper-spring-boot-autoconfigure\2.1.3\mapper-spring-boot-autoconfigure-2.1.3.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-thymeleaf\2.0.2.RELEASE\spring-boot-starter-thymeleaf-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\thymeleaf\thymeleaf-spring5\3.0.9.RELEASE\thymeleaf-spring5-3.0.9.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.1.RELEASE\thymeleaf-extras-java8time-3.0.1.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\thymeleaf\thymeleaf\3.0.9.RELEASE\thymeleaf-3.0.9.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\ognl\ognl\3.1.12\ognl-3.1.12.jar;D:\develop\apache-maven-3.5.4\repo\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\develop\apache-maven-3.5.4\repo\org\attoparser\attoparser\2.0.4.RELEASE\attoparser-2.0.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\unbescape\unbescape\1.1.5.RELEASE\unbescape-1.1.5.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\develop\apache-maven-3.5.4\repo\nz\net\ultraq\thymeleaf\thymeleaf-layout-dialect\2.4.1\thymeleaf-layout-dialect-2.4.1.jar;D:\develop\apache-maven-3.5.4\repo\nz\net\ultraq\thymeleaf\thymeleaf-expression-processor\1.1.3\thymeleaf-expression-processor-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\org\codehaus\groovy\groovy\2.4.15\groovy-2.4.15.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-mail\2.0.2.RELEASE\spring-boot-starter-mail-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-context\5.0.6.RELEASE\spring-context-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-context-support\5.0.6.RELEASE\spring-context-support-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\com\sun\mail\javax.mail\1.6.1\javax.mail-1.6.1.jar;D:\develop\apache-maven-3.5.4\repo\javax\activation\activation\1.1\activation-1.1.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-web\2.0.2.RELEASE\spring-boot-starter-web-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-json\2.0.2.RELEASE\spring-boot-starter-json-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.5\jackson-module-parameter-names-2.9.5.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-tomcat\2.0.2.RELEASE\spring-boot-starter-tomcat-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\tomcat\embed\tomcat-embed-core\8.5.31\tomcat-embed-core-8.5.31.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\tomcat\embed\tomcat-embed-el\8.5.31\tomcat-embed-el-8.5.31.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.31\tomcat-embed-websocket-8.5.31.jar;D:\develop\apache-maven-3.5.4\repo\org\hibernate\validator\hibernate-validator\6.0.9.Final\hibernate-validator-6.0.9.Final.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-web\5.0.6.RELEASE\spring-web-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-webmvc\5.0.6.RELEASE\spring-webmvc-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-log4j\1.3.8.RELEASE\spring-boot-starter-log4j-1.3.8.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;D:\develop\apache-maven-3.5.4\repo\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-configuration-processor\2.0.2.RELEASE\spring-boot-configuration-processor-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-websocket\5.0.6.RELEASE\spring-websocket-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-all\4.1.24.Final\netty-all-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar;D:\develop\apache-maven-3.5.4\repo\com\alibaba\druid\1.0.25\druid-1.0.25.jar;D:\Program Files\Java\jdk1.8.0_111\lib\jconsole.jar;D:\Program Files\Java\jdk1.8.0_111\lib\tools.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-test\2.0.2.RELEASE\spring-boot-starter-test-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-test\2.0.2.RELEASE\spring-boot-test-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-test-autoconfigure\2.0.2.RELEASE\spring-boot-test-autoconfigure-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\assertj\assertj-core\3.9.1\assertj-core-3.9.1.jar;D:\develop\apache-maven-3.5.4\repo\org\mockito\mockito-core\2.15.0\mockito-core-2.15.0.jar;D:\develop\apache-maven-3.5.4\repo\net\bytebuddy\byte-buddy\1.7.11\byte-buddy-1.7.11.jar;D:\develop\apache-maven-3.5.4\repo\net\bytebuddy\byte-buddy-agent\1.7.11\byte-buddy-agent-1.7.11.jar;D:\develop\apache-maven-3.5.4\repo\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\develop\apache-maven-3.5.4\repo\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\develop\apache-maven-3.5.4\repo\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;D:\develop\apache-maven-3.5.4\repo\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\develop\apache-maven-3.5.4\repo\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-test\5.0.6.RELEASE\spring-test-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\xmlunit\xmlunit-core\2.5.1\xmlunit-core-2.5.1.jar;D:\develop\apache-maven-3.5.4\repo\org\hamcrest\hamcrest-all\1.3\hamcrest-all-1.3.jar;D:\develop\apache-maven-3.5.4\repo\com\jayway\jsonpath\json-path\0.8.1\json-path-0.8.1.jar;D:\develop\apache-maven-3.5.4\repo\net\minidev\json-smart\1.1.1\json-smart-1.1.1.jar;D:\develop\apache-maven-3.5.4\repo\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\develop\apache-maven-3.5.4\repo\com\jayway\jsonpath\json-path-assert\0.8.1\json-path-assert-0.8.1.jar;D:\develop\apache-maven-3.5.4\repo\junit\junit\4.12\junit-4.12.jar;D:\develop\apache-maven-3.5.4\repo\com\belerweb\pinyin4j\2.5.0\pinyin4j-2.5.0.jar;D:\develop\apache-maven-3.5.4\repo\com\github\pagehelper\pagehelper-spring-boot-starter\1.2.10\pagehelper-spring-boot-starter-1.2.10.jar;D:\develop\apache-maven-3.5.4\repo\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.2\mybatis-spring-boot-starter-1.3.2.jar;D:\develop\apache-maven-3.5.4\repo\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.2\mybatis-spring-boot-autoconfigure-1.3.2.jar;D:\develop\apache-maven-3.5.4\repo\com\github\pagehelper\pagehelper-spring-boot-autoconfigure\1.2.10\pagehelper-spring-boot-autoconfigure-1.2.10.jar;D:\develop\apache-maven-3.5.4\repo\com\github\pagehelper\pagehelper\5.1.8\pagehelper-5.1.8.jar;D:\develop\apache-maven-3.5.4\repo\com\github\jsqlparser\jsqlparser\1.2\jsqlparser-1.2.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\slf4j-log4j12\1.8.0-beta2\slf4j-log4j12-1.8.0-beta2.jar;D:\develop\apache-maven-3.5.4\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\develop\apache-maven-3.5.4\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\develop\apache-maven-3.5.4\repo\org\slf4j\log4j-over-slf4j\1.7.25\log4j-over-slf4j-1.7.25.jar;D:\develop\apache-maven-3.5.4\repo\com\alibaba\fastjson\1.2.56\fastjson-1.2.56.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-text\1.7\commons-text-1.7.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\security\spring-security-core\4.2.12.RELEASE\spring-security-core-4.2.12.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-aop\5.0.6.RELEASE\spring-aop-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-beans\5.0.6.RELEASE\spring-beans-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-expression\5.0.6.RELEASE\spring-expression-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-redis\1.4.7.RELEASE\spring-boot-starter-redis-1.4.7.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-redis\2.0.7.RELEASE\spring-data-redis-2.0.7.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-keyvalue\2.0.7.RELEASE\spring-data-keyvalue-2.0.7.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\data\spring-data-commons\2.0.7.RELEASE\spring-data-commons-2.0.7.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-tx\5.0.6.RELEASE\spring-tx-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-oxm\5.0.6.RELEASE\spring-oxm-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\redis\clients\jedis\2.9.0\jedis-2.9.0.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-cache\2.0.2.RELEASE\spring-boot-starter-cache-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-data-redis\2.0.2.RELEASE\spring-boot-starter-data-redis-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\io\lettuce\lettuce-core\5.0.4.RELEASE\lettuce-core-5.0.4.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\io\projectreactor\reactor-core\3.1.7.RELEASE\reactor-core-3.1.7.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-common\4.1.24.Final\netty-common-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-transport\4.1.24.Final\netty-transport-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-resolver\4.1.24.Final\netty-resolver-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-pool2\2.5.0\commons-pool2-2.5.0.jar;D:\develop\apache-maven-3.5.4\repo\net\bramp\ffmpeg\ffmpeg\0.6.2\ffmpeg-0.6.2.jar;D:\develop\apache-maven-3.5.4\repo\com\google\guava\guava\20.0\guava-20.0.jar;D:\develop\apache-maven-3.5.4\repo\commons-io\commons-io\2.5\commons-io-2.5.jar;D:\develop\apache-maven-3.5.4\repo\org\modelmapper\modelmapper\0.7.7\modelmapper-0.7.7.jar;D:\develop\apache-maven-3.5.4\repo\org\openjdk\jmh\jmh-core\1.21\jmh-core-1.21.jar;D:\develop\apache-maven-3.5.4\repo\net\sf\jopt-simple\jopt-simple\4.6\jopt-simple-4.6.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-math3\3.2\commons-math3-3.2.jar;D:\develop\apache-maven-3.5.4\repo\org\openjdk\jmh\jmh-generator-annprocess\1.21\jmh-generator-annprocess-1.21.jar;D:\develop\apache-maven-3.5.4\repo\org\projectlombok\lombok\1.18.8\lombok-1.18.8.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-devtools\2.0.2.RELEASE\spring-boot-devtools-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot\2.0.2.RELEASE\spring-boot-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-autoconfigure\2.0.2.RELEASE\spring-boot-autoconfigure-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-aop\2.0.2.RELEASE\spring-boot-starter-aop-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\aspectj\aspectjweaver\1.8.13\aspectjweaver-1.8.13.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.9.9\jackson-module-jaxb-annotations-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\core\jackson-annotations\2.9.9\jackson-annotations-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\develop\apache-maven-3.5.4\repo\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\develop\apache-maven-3.5.4\repo\org\hibernate\hibernate-validator\5.4.0.Final\hibernate-validator-5.4.0.Final.jar;D:\develop\apache-maven-3.5.4\repo\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\develop\apache-maven-3.5.4\repo\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-actuator\2.0.2.RELEASE\spring-boot-starter-actuator-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-actuator-autoconfigure\2.0.2.RELEASE\spring-boot-actuator-autoconfigure-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-actuator\2.0.2.RELEASE\spring-boot-actuator-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\io\micrometer\micrometer-core\1.0.4\micrometer-core-1.0.4.jar;D:\develop\apache-maven-3.5.4\repo\org\hdrhistogram\HdrHistogram\2.1.10\HdrHistogram-2.1.10.jar;D:\develop\apache-maven-3.5.4\repo\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter\2.0.2.RELEASE\spring-boot-starter-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-logging\2.0.2.RELEASE\spring-boot-starter-logging-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;D:\develop\apache-maven-3.5.4\repo\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\develop\apache-maven-3.5.4\repo\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-runtime\1.1.3\protostuff-runtime-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-collectionschema\1.1.3\protostuff-collectionschema-1.1.3.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-api\1.0.8\protostuff-api-1.0.8.jar;D:\develop\apache-maven-3.5.4\repo\com\dyuproject\protostuff\protostuff-core\1.0.8\protostuff-core-1.0.8.jar;D:\develop\apache-maven-3.5.4\repo\org\java-websocket\Java-WebSocket\1.4.0\Java-WebSocket-1.4.0.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\boot\spring-boot-starter-websocket\2.0.2.RELEASE\spring-boot-starter-websocket-2.0.2.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-messaging\5.0.6.RELEASE\spring-messaging-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\yeauty\netty-websocket-spring-boot-starter\0.8.0\netty-websocket-spring-boot-starter-0.8.0.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-codec-http\4.1.24.Final\netty-codec-http-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-codec\4.1.24.Final\netty-codec-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-handler\4.1.24.Final\netty-handler-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\io\netty\netty-buffer\4.1.24.Final\netty-buffer-4.1.24.Final.jar;D:\develop\apache-maven-3.5.4\repo\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-core\5.0.6.RELEASE\spring-core-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\org\springframework\spring-jcl\5.0.6.RELEASE\spring-jcl-5.0.6.RELEASE.jar;D:\develop\apache-maven-3.5.4\repo\com\opencsv\opencsv\4.5\opencsv-4.5.jar;D:\develop\apache-maven-3.5.4\repo\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;D:\develop\apache-maven-3.5.4\repo\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\develop\apache-maven-3.5.4\repo\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\commons\commons-collections4\4.2\commons-collections4-4.2.jar;D:\develop\apache-maven-3.5.4\repo\com\coreoz\windmill\1.2.0\windmill-1.2.0.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\poi\poi-ooxml\3.17\poi-ooxml-3.17.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\poi\poi\3.17\poi-3.17.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\poi\poi-ooxml-schemas\3.17\poi-ooxml-schemas-3.17.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\xmlbeans\xmlbeans\2.6.0\xmlbeans-2.6.0.jar;D:\develop\apache-maven-3.5.4\repo\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\develop\apache-maven-3.5.4\repo\com\github\virtuald\curvesapi\1.04\curvesapi-1.04.jar;D:\develop\apache-maven-3.5.4\repo\com\tdunning\json\1.8\json-1.8.jar;D:\develop\apache-maven-3.5.4\repo\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar;D:\develop\apache-maven-3.5.4\repo\io\humble\humble-video-all\0.3.0\humble-video-all-0.3.0.jar;D:\develop\apache-maven-3.5.4\repo\io\humble\humble-video-noarch\0.3.0\humble-video-noarch-0.3.0.jar;D:\develop\apache-maven-3.5.4\repo\io\humble\humble-video-arch-x86_64-w64-mingw32\0.3.0\humble-video-arch-x86_64-w64-mingw32-0.3.0.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;D:\develop\apache-maven-3.5.4\repo\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\httpcomponents\httpcore\4.4.3\httpcore-4.4.3.jar;D:\develop\apache-maven-3.5.4\repo\org\apache\httpcomponents\httpmime\4.5.6\httpmime-4.5.6.jar;D:\develop\apache-maven-3.5.4\repo\urbanophile\java-getopt\1.0.9\java-getopt-1.0.9.jar;D:\develop\apache-maven-3.5.4\repo\com\googlecode\soundlibs\tritonus-share\0.3.7.4\tritonus-share-0.3.7.4.jar;D:\develop\apache-maven-3.5.4\repo\com\googlecode\soundlibs\tritonus-all\0.3.7.2\tritonus-all-0.3.7.2.jar;D:\develop\apache-maven-3.5.4\repo\com\googlecode\soundlibs\jorbis\0.0.17-2\jorbis-0.0.17-2.jar" com.example.web.open.controller.TestASRByChunkClient 14:48:41.515 [WebSocketWriteThread-12] ERROR com.example.web.open.controller.TestASRByChunkClient - 出错了:{} 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 at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:928) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) at java.io.InputStream.read(InputStream.java:101) at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:424) at java.lang.Thread.run(Thread.java:745) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) at sun.security.validator.Validator.validate(Validator.java:260) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) ... 10 common frames omitted Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) ... 16 common frames omitted 14:48:41.519 [WebSocketWriteThread-12] INFO com.example.web.open.controller.TestASRByChunkClient - 已经断开与服务器端连接。 14:48:41.514 [WebSocketConnectReadThread-11] ERROR com.example.web.open.controller.TestASRByChunkClient - 出错了:{} 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 at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:928) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) at java.io.InputStream.read(InputStream.java:101) at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:424) at java.lang.Thread.run(Thread.java:745) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) at sun.security.validator.Validator.validate(Validator.java:260) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) ... 10 common frames omitted Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) ... 16 common frames omitted Exception in thread "main" org.java_websocket.exceptions.WebsocketNotConnectedException at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:630) at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:607) at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:344) at com.example.web.open.controller.TestASRByChunkClient.init(TestASRByChunkClient.java:74) at com.example.web.open.controller.TestASRByChunkClient.sendByStep(TestASRByChunkClient.java:105) at com.example.web.open.controller.TestASRByChunkClient.main(TestASRByChunkClient.java:58) Process finished with exit code 1
笔者本地调试,使用自签名证书:https本地自签名证书添加到信任证书访问
后来忽然不能运行了。也不知道为什么。后来查找到原因如下:
将cer证书转换成jks证书,并在ssl通信代码之前指定证书密码
转换命令:
jdk1.8.0_181\jre\bin>keytool -importcert -file "D:\develop\nginx-1.14.2\conf\www.example.com+5.pem" -keystore "D:\develop\nginx-1.14.2\conf\www.example.com+5.jks" -alias "example"
输入密码changeit
然后在使用ssl通信代码之前加以下代码
public static void main(String[] args) throws URISyntaxException, InterruptedException, IOException { System.setProperty("javax.net.ssl.trustStore","D:\\develop\\nginx-1.14.2\\conf\\www.example.com+5.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); String WS_URL = "ws://127.0.0.1:81/api/asrv2"; WS_URL="wss://www.example.com/wsapi/asrv2"; URI uri = new URI(WS_URL); CountDownLatch connectClose = new CountDownLatch(1); TestASRByChunkClient client = new TestASRByChunkClient(uri, connectClose); client.sendByStep(); client.sendEOS(); connectClose.await(); }
随后代码正常工作
参考来源:https://stackoverflow.com/questions/38353944/keep-getting-no-x509trustmanager-implementation-available-error-when-trying-to-c