Jetty ALPN / NPN未正确配置。尝试使用google cloud speech api时

时间:2017-05-24 12:39:08

标签: spring-mvc tomcat google-cloud-platform grpc google-cloud-speech

在系统环境变量中设置GOOGLE_APPLICATION_CREDENTIALS后,我尝试使用Google云语音API。无法找出任何问题或解决超过2天。

这是我得到的错误

24-May-2017 17:58:22.287 WARNING [grpc-default-executor-0] io.grpc.internal.ChannelExecutor.drain Runnable threw exception in ChannelExecutor
 java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
    at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:174)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:151)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:139)
    at io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:109)
    at io.grpc.netty.NettyChannelBuilder.createProtocolNegotiatorByType(NettyChannelBuilder.java:335)
    at io.grpc.netty.NettyChannelBuilder.createProtocolNegotiator(NettyChannelBuilder.java:308)
    at io.grpc.netty.NettyChannelBuilder$NettyTransportFactory$DynamicNettyTransportParams.getProtocolNegotiator(NettyChannelBuilder.java:499)
    at io.grpc.netty.NettyChannelBuilder$NettyTransportFactory.newClientTransport(NettyChannelBuilder.java:448)
    at io.grpc.internal.CallCredentialsApplyingTransportFactory.newClientTransport(CallCredentialsApplyingTransportFactory.java:61)
    at io.grpc.internal.InternalSubchannel.startNewTransport(InternalSubchannel.java:209)
    at io.grpc.internal.InternalSubchannel.obtainActiveTransport(InternalSubchannel.java:186)
    at io.grpc.internal.ManagedChannelImpl$SubchannelImplImpl.obtainActiveTransport(ManagedChannelImpl.java:806)
    at io.grpc.internal.GrpcUtil.getTransportFromPickResult(GrpcUtil.java:568)
    at io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:296)
    at io.grpc.internal.ManagedChannelImpl$LbHelperImpl$5.run(ManagedChannelImpl.java:724)
    at io.grpc.internal.ChannelExecutor.drain(ChannelExecutor.java:87)
    at io.grpc.internal.ManagedChannelImpl$LbHelperImpl.runSerialized(ManagedChannelImpl.java:715)
    at io.grpc.internal.ManagedChannelImpl$NameResolverListenerImpl.onUpdate(ManagedChannelImpl.java:752)
    at io.grpc.internal.DnsNameResolver$1.run(DnsNameResolver.java:174)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

这是我的POM文件

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.raghu</groupId>
    <artifactId>raghu</artifactId>
    <packaging>war</packaging>
    <version>1.0.0</version>
    <name>raghu</name>

    <properties>
        <springframework.version>4.0.6.RELEASE</springframework.version>
        <hibernate.version>4.3.6.Final</hibernate.version>
        <mysql.version>5.1.31</mysql.version>
        <joda-time.version>2.3</joda-time.version>
    </properties>

    <dependencies>
         <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-speech</artifactId>
            <version>0.17.1-alpha</version>
        </dependency>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- jsr303 validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.2.Final</version>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <!-- JSON -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.2</version>
        </dependency>
        <!-- Joda-Time -->      
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${joda-time.version}</version>
        </dependency>

        <!-- To map JodaTime with database type -->         
        <dependency>
            <groupId>org.jadira.usertype</groupId>
            <artifactId>usertype.core</artifactId>
            <version>3.0.0.CR1</version>
        </dependency>

        <!-- Servlet+JSP+JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency> <!-- security-core for core authentication and access-control classes-->  
            <groupId>org.springframework.security</groupId>  
            <artifactId>spring-security-core</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency>  
        <dependency> <!-- security-web for web-security infrastructure code -->  
            <groupId>org.springframework.security</groupId>  
            <artifactId>spring-security-web</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency>  
        <dependency> <!-- security-config contains the security namespace parsing code -->  
            <groupId>org.springframework.security</groupId>  
            <artifactId>spring-security-config</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency>
        <dependency>
            <groupId>com.twilio.sdk</groupId>
            <artifactId>twilio-java-sdk</artifactId>
            <version>3.4.5</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.9.30</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.4</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <warSourceDirectory>src/main/webapp</warSourceDirectory>
                        <warName>raghu</warName>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>2.1</version>
                  <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                  </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <finalName>raghu</finalName>
    </build>
</project>

我试过的JAVA实现

public String convertToText(MultipartFile file) throws Exception {

        SpeechClient speech = SpeechClient.create();

        byte[] data = file.getBytes();

        ByteString audioBytes = ByteString.copyFrom(data);
        System.out.println("1**********");
        // Builds the sync recognize request
        RecognitionConfig config = RecognitionConfig.newBuilder()
            .setEncoding(AudioEncoding.LINEAR16)
            .setSampleRateHertz(16000)
            .setLanguageCode("en-US")
            .build();
        RecognitionAudio audio = RecognitionAudio.newBuilder()
            .setContent(audioBytes)
            .build();

        // Performs speech recognition on the audio file
        RecognizeResponse response = speech.recognize(config, audio);
        List<SpeechRecognitionResult> results = response.getResultsList();

        String recText = "";


        for (SpeechRecognitionResult result: results) {
          List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList();
          for (SpeechRecognitionAlternative alternative: alternatives) {
            System.out.printf("Transcription: %s%n", alternative.getTranscript());
            recText+= " "+alternative.getTranscript();
          }
        }
        speech.close();

        return recText;
    }

我正在使用Tomcat(我不想使用Jetty)来部署我的.war文件。

互联网上有很多问题似乎没有人回答这个问题!任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

Tomcat使用的Netty-tcnative 1.x是incompatible with tcnative。使用netty-tcantive 2.x解决不兼容问题。使用新的netty-tcnative required updates到grpc-java,它将包含在下一个版本1.4.0中,计划于6月6日发布。