我是Java开发的新手,尝试通过 getParameterMap()方法获取查询字符串变量时遇到此错误:
Found class org.eclipse.jetty.websocket.api.UpgradeRequest, but interface was expected
我使用的代码是这样:
public class TranscribeSocket extends WebSocketAdapter implements ApiStreamObserver<StreamingRecognizeResponse> {
private String speechLanguage = "en-US";
@Override
public void onWebSocketConnect(Session sess) {
UpgradeRequest request = sess.getUpgradeRequest();
Map<String, List<String>> params = request.getParameterMap();
List<String> language = params.get("lang");
if (language != null && language.size() > 0) {
String lang = language.get(0);
switch (lang) {
case "en":
speechLanguage = "en-US";
break;
case "fr":
speechLanguage = "fr-FR";
break;
default:
speechLanguage = "en-US";
}
}
}
}
更新
在这里您可以找到依赖树
[INFO] be.smartconcept.speech:speaking-with-a-page:war:1.0-SNAPSHOT
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- org.eclipse.jetty.websocket:websocket-servlet:jar:9.4.1.v20170120:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-api:jar:9.4.1.v20170120:compile
[INFO] +- com.google.cloud:google-cloud-speech:jar:0.49.0-alpha:compile
[INFO] | +- com.google.cloud:google-cloud-core:jar:1.31.0:compile
[INFO] | | +- com.google.guava:guava:jar:20.0:compile
[INFO] | | +- joda-time:joda-time:jar:2.9.2:compile
[INFO] | | +- com.google.http-client:google-http-client:jar:1.23.0:compile
[INFO] | | | \- org.apache.httpcomponents:httpclient:jar:4.0.1:compile
[INFO] | | | +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
[INFO] | | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | | \- commons-codec:commons-codec:jar:1.3:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile
[INFO] | | +- com.google.api:api-common:jar:1.5.0:compile
[INFO] | | +- com.google.api:gax:jar:1.25.0:compile
[INFO] | | | \- org.threeten:threetenbp:jar:1.3.3:compile
[INFO] | | +- com.google.protobuf:protobuf-java-util:jar:3.5.1:compile
[INFO] | | +- com.google.api.grpc:proto-google-common-protos:jar:1.11.0:compile
[INFO] | | \- com.google.api.grpc:proto-google-iam-v1:jar:0.12.0:compile
[INFO] | +- com.google.cloud:google-cloud-core-grpc:jar:1.31.0:compile
[INFO] | | +- com.google.auth:google-auth-library-credentials:jar:0.9.1:compile
[INFO] | | +- com.google.protobuf:protobuf-java:jar:3.5.1:compile
[INFO] | | +- io.grpc:grpc-protobuf:jar:1.10.1:compile
[INFO] | | | \- io.grpc:grpc-protobuf-lite:jar:1.10.1:compile
[INFO] | | +- io.grpc:grpc-context:jar:1.10.1:compile
[INFO] | | \- com.google.api:gax-grpc:jar:1.25.0:compile
[INFO] | +- com.google.api.grpc:proto-google-cloud-speech-v1beta1:jar:0.14.0:compile
[INFO] | +- com.google.api.grpc:proto-google-cloud-speech-v1p1beta1:jar:0.14.0:compile
[INFO] | +- com.google.api.grpc:proto-google-cloud-speech-v1:jar:0.14.0:compile
[INFO] | +- io.grpc:grpc-netty-shaded:jar:1.10.1:compile
[INFO] | | \- io.grpc:grpc-core:jar:1.10.1:compile (version selected from constraint [1.10.1,1.10.1])
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.1.2:compile
[INFO] | | \- io.opencensus:opencensus-contrib-grpc-metrics:jar:0.11.0:compile
[INFO] | +- io.grpc:grpc-stub:jar:1.10.1:compile
[INFO] | \- io.grpc:grpc-auth:jar:1.10.1:compile
[INFO] +- com.google.cloud:google-cloud-storage:jar:1.37.1:compile
[INFO] | +- com.google.cloud:google-cloud-core-http:jar:1.37.1:compile
[INFO] | | +- com.google.auth:google-auth-library-oauth2-http:jar:0.9.1:compile
[INFO] | | +- com.google.oauth-client:google-oauth-client:jar:1.23.0:compile
[INFO] | | +- com.google.api-client:google-api-client:jar:1.23.0:compile
[INFO] | | +- com.google.http-client:google-http-client-appengine:jar:1.23.0:compile
[INFO] | | +- com.google.http-client:google-http-client-jackson:jar:1.23.0:compile
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.11:compile
[INFO] | | +- com.google.http-client:google-http-client-jackson2:jar:1.23.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.1.3:compile
[INFO] | | +- com.google.api:gax-httpjson:jar:0.46.0:compile
[INFO] | | +- io.opencensus:opencensus-api:jar:0.12.3:compile
[INFO] | | \- io.opencensus:opencensus-contrib-http-util:jar:0.12.3:compile
[INFO] | \- com.google.apis:google-api-services-storage:jar:v1-rev131-1.23.0:compile
[INFO] \- com.google.code.gson:gson:jar:2.8.0:compile
事实上,此代码是从Google语音中提取到文本示例,该示例提供了流式语音的转录。我需要将语音语言传递给gcloud,而前端是用PHP构建的,所以我看到的唯一方法是通过querystring将适当的值传递给websocket。