4
votes

Getting exception whilst using Google Pubsub to list topics, my web application is running on tomcat.

public static List<String> listTopics(GcpCredentials gcCredentials, String project) throws GCPException, IOException
{
    List<String> topics = new ArrayList<>();
    TopicAdminClient client = getTopicClient(gcCredentials);
    ProjectName projectName = ProjectName.create(project);
    ListTopicsPagedResponse response = client.listTopics(projectName);
    for (Topic topic :response.iterateAll())
    {
        topics.add(topic.getNameAsTopicName().getTopic());
    }
    return topics;
}`

Exception:

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)

2
I am facing the same issue with Google Cloud Spanner, could anyone please share anything that can help me.Vaijnath Polsane
The issue is an incompatibility between Tomcat and GRPC and will be fixed in future versions. The workaround detailed in this other question is to use grpc-java 1.4.0 which is compatible with netty-tcnative v2.0.5.Yannick MG

2 Answers

2
votes

I have observed this problem with Netty version 4.1.15.Final but not with 4.1.13.Final. Check your transitive dependencies. I.e Spring Boot references Netty.

What I added to POM to make it work with Spanner API version 0.22.0-beta:

<properties> <v.netty>4.1.13.Final</v.netty> </properties> ... <dependencyManagement> <dependencies> <dependency> <groupId>io.netty</groupId> <artifactId>netty-codec</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-codec-http</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-codec-http2</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-handler</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-common</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-handler-proxy</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-transport</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-resolver</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-codec-socks</artifactId> <version>${v.netty}</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-buffer</artifactId> <version>${v.netty}</version> </dependency> </dependencies> </dependencyManagement>

If the problem persists, or if it is not an option, plase run your JVM with appropriate bootclasspath entry, like:

java -Xbootclasspath/p:/tmp/alpn-boot-8.1.11.v20170118.jar -cp ...

Make sure to replace /tmp/alpn-boot-8.1.11.v20170118.jar with location of alpn jar that matches your JVM version as listed on this page: https://www.eclipse.org/jetty/documentation/9.4.x/alpn-chapter.html

-1
votes

There is a possible solution on github: "Exception when configuring SSL: "Jetty ALPN/NPN has not been properly configured."

The recommended steps, quoting from the above document:

1) Edit catalina.sh /usr/local/Cellar/tomcat/8.5.3/libexec/bin/catalina.sh

2) At line 103, add the following CATALINA_OPTS="-javaagent:/Library/Tomcat/lib/jetty-alpn-agent-2.0.6.jar"

3) Restart tomcat ../bin/shutdown.sh ../bin/startup.sh