airlift / drift

An annotation-based Java library for creating Thrift serializable types and services.
Apache License 2.0
242 stars 92 forks source link

python server throw "No protocol version header" #90

Closed naah69 closed 5 years ago

naah69 commented 5 years ago

i use java client and python server. when i use drift,it throw error. but when i use thrift-api,it work.

the following code is mine. can u help me? thanks

Interface NLU

@ThriftService
public interface NLU {

    @ThriftMethod("parse")
    String parse(String scene, String version, String text);

    @ThriftMethod("status")
    String status();
}

Main

DriftClientFactory clientFactory = new DriftClientFactory(
        new ThriftCodecManager(),
        createStaticDriftNettyMethodInvokerFactory(new DriftNettyClientConfig()),
        new SimpleAddressSelector(ImmutableList.<HostAndPort>of(HostAndPort.fromParts("10.250.250.240", 6000))),
        ExceptionClassifier.NORMAL_RESULT);
DriftClient<NLU> driftClient = clientFactory.createDriftClient(NLU.class);
NLU nlu = driftClient.get();
System.out.println(nlu.status());

Exception

/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=52074:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/lib/tools.jar:/Users/naah/Documents/projects/thrift-demo/drift-demo/target/classes:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-server/1.8/drift-server-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-api/1.8/drift-api-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-codec/1.8/drift-codec-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/parameternames/1.3/parameternames-1.3.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-transport-spi/1.8/drift-transport-spi-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/com/google/guava/guava/21.0/guava-21.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/configuration/0.159/configuration-0.159.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/bval/bval-jsr/1.1.1/bval-jsr-1.1.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/bval/bval-core/1.1.1/bval-core-1.1.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/commons-beanutils/commons-beanutils-core/1.8.3/commons-beanutils-core-1.8.3.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar:/Users/naah/software/apache-maven-3.5.3/repository/javax/xml/bind/jaxb-api/2.2.6/jaxb-api-2.2.6.jar:/Users/naah/software/apache-maven-3.5.3/repository/com/sun/xml/bind/jaxb-impl/2.2.6/jaxb-impl-2.2.6.jar:/Users/naah/software/apache-maven-3.5.3/repository/javax/inject/javax.inject/1/javax.inject-1.jar:/Users/naah/software/apache-maven-3.5.3/repository/com/google/inject/guice/4.0/guice-4.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/com/google/inject/extensions/guice-multibindings/4.0/guice-multibindings-4.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/cglib/cglib-nodep/2.2.2/cglib-nodep-2.2.2.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/stats/0.159/stats-0.159.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/hdrhistogram/HdrHistogram/2.1.9/HdrHistogram-2.1.9.jar:/Users/naah/software/apache-maven-3.5.3/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.1/jackson-annotations-2.8.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/slice/0.10/slice-0.10.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/openjdk/jol/jol-core/0.1/jol-core-0.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/units/1.0/units-1.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/javax/annotation/javax.annotation-api/1.3.1/javax.annotation-api-1.3.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/weakref/jmxutils/1.19/jmxutils-1.19.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-client/1.8/drift-client-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-protocol/1.8/drift-protocol-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/log/0.159/log-0.159.jar:/Users/naah/software/apache-maven-3.5.3/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/drift/drift-transport-netty/1.8/drift-transport-netty-1.8.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/airlift/concurrent/0.159/concurrent-0.159.jar:/Users/naah/software/apache-maven-3.5.3/repository/io/netty/netty-all/4.1.8.Final/netty-all-4.1.8.Final.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/thrift/libthrift/0.11.0/libthrift-0.11.0.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/httpcomponents/httpclient/4.4.1/httpclient-4.4.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/naah/software/apache-maven-3.5.3/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/apache/httpcomponents/httpcore/4.4.1/httpcore-4.4.1.jar:/Users/naah/software/apache-maven-3.5.3/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar com.example.Main
[main] INFO com.example.Main - Running server on port 52077
Exception in thread "main" io.airlift.drift.client.UncheckedTTransportException: Client was disconnected by server
    at io.airlift.drift.client.DriftInvocationHandler.invoke(DriftInvocationHandler.java:125)
    at com.sun.proxy.$Proxy7.status(Unknown Source)
    at com.example.Main.main(Main.java:26)
Caused by: io.airlift.drift.protocol.TTransportException: Client was disconnected by server
    at io.airlift.drift.transport.netty.client.ThriftClientHandler.channelInactive(ThriftClientHandler.java:203)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:232)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:225)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:232)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:225)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:360)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:325)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:232)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:225)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1329)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:232)
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:908)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:744)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    at java.lang.Thread.run(Thread.java:748)
    Suppressed: io.airlift.drift.client.RetriesFailedException: Invocation retries failed (invocationAttempts: 1, duration: 70.27ms, connectionAttempts: 1, overloadedRejects: 0)
        at io.airlift.drift.client.DriftMethodInvocation.fail(DriftMethodInvocation.java:265)
        at io.airlift.drift.client.DriftMethodInvocation.handleFailure(DriftMethodInvocation.java:205)
        at io.airlift.drift.client.DriftMethodInvocation.access$100(DriftMethodInvocation.java:51)
        at io.airlift.drift.client.DriftMethodInvocation$1.onFailure(DriftMethodInvocation.java:171)
        at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
        at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
        at com.google.common.util.concurrent.AbstractCatchingFuture.run(AbstractCatchingFuture.java:123)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
        at com.google.common.util.concurrent.AbstractFuture.setFuture(AbstractFuture.java:713)
        at com.google.common.util.concurrent.TimeoutFuture$Fire.run(TimeoutFuture.java:115)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
        at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
        at io.airlift.drift.transport.netty.client.InvocationResponseFuture.fatalError(InvocationResponseFuture.java:153)
        at io.airlift.drift.transport.netty.client.InvocationResponseFuture.access$200(InvocationResponseFuture.java:33)
        at io.airlift.drift.transport.netty.client.InvocationResponseFuture$1.onFailure(InvocationResponseFuture.java:122)
        at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
        at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
        at io.airlift.drift.transport.netty.client.ThriftClientHandler$ThriftRequest.failed(ThriftClientHandler.java:282)
        at io.airlift.drift.transport.netty.client.ThriftClientHandler$RequestHandler.onChannelError(ThriftClientHandler.java:470)
        at io.airlift.drift.transport.netty.client.ThriftClientHandler.lambda$onError$2(ThriftClientHandler.java:233)
        at java.util.Collection.removeIf(Collection.java:414)
        at io.airlift.drift.transport.netty.client.ThriftClientHandler.onError(ThriftClientHandler.java:232)
        ... 23 more
electrum commented 5 years ago

The problem could be that the server is expecting the compact protocol, but the client defaults to binary. Try calling setProtocol(COMPACT) on DriftNettyClientConfig.

If that doesn’t work, please show the code for a sample Python server that reproduces the issue.

naah69 commented 5 years ago

i try Protocol.COMPACT ,Protocol.BINARY and Protocol.FB_COMPACT. python always show the following error:

2018-11-03 11:39:22 ERROR    thriftpy.server  - No protocol version header
Traceback (most recent call last):
  File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/thriftpy/server.py", line 95, in handle
    self.processor.process(iprot, oprot)
  File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/thriftpy/thrift.py", line 294, in process
    api, seqid, result, call = self.process_in(iprot)
  File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/thriftpy/thrift.py", line 250, in process_in
    api, type, seqid = iprot.read_message_begin()
  File "thriftpy/protocol/cybin/cybin.pyx", line 439, in cybin.TCyBinaryProtocol.read_message_begin
cybin.ProtocolError: No protocol version header
naah69 commented 5 years ago

i find the cause. the python use BIO.so we can not use NIO. can u tell me how to set the parameter

dain commented 5 years ago

As @electrum mentioned, Thrift server implementations other than Drift require that clients have prior knowledge of the exact transport and protocol. In your case I'm pretty sure your server is using an the unframed transport, and the binary protocol. The preferred transport is framed, which if at all possible you should switch your server to use as it is much more efficient. That said, you can change the Drift client to use unframed by calling setTransport(UNFRAMED on DriftNettyClientConfig.

naah69 commented 5 years ago

thank you,and i had resolved that problem. it indeed caused by transport.when i use un transport.it works