Groovy cometd客户端LongPollingTransport.create()抛出MissingMethodException

时间:2018-02-08 12:49:47

标签: groovy httpclient cometd

我的常规代码:

import org.cometd.client.BayeuxClient;
import org.cometd.client.transport.ClientTransport;
import org.cometd.client.transport.LongPollingTransport;
import org.eclipse.jetty.client.HttpClient as MyHttpClient    

def myurl = "http://192.168.11.170:8080/"

MyHttpClient httpClient = new MyHttpClient()

httpClient.start()

println (httpClient.GET(myurl).getStatus())

BayeuxClient client = new BayeuxClient(myurl, LongPollingTransport.create(null))
client.handshake()
client.waitFor(1000, BayeuxClient.State.CONNECTED)

我在这里尝试制作handshake。它只是这里显示的文档示例代码https://docs.cometd.org/current/apidocs/org/cometd/client/BayeuxClient.html。但我得到的错误如下所示。不知道我做错了什么?

输出:

200
groovy.lang.MissingMethodException: No signature of method: static org.cometd.client.transport.LongPollingTransport.create() is applicable for argument types: (null) values: [null]
Possible solutions: grep(), terminate(), iterator(), accept(java.lang.String), accept(java.lang.String), print(java.lang.Object)

1 个答案:

答案 0 :(得分:1)

BayeuxClient的Javadoc与LongPollingTransport类完全不同步 - there is no such method as LongPollingTransport.create(arg)

相反,您可以尝试使用此类的常规构造函数,例如

BayeuxClient client = new BayeuxClient(myurl, new LongPollingTransport([:], httpClient))
  

参考:https://docs.cometd.org/current/apidocs/org/cometd/client/transport/LongPollingTransport.html#LongPollingTransport-java.util.Map-org.eclipse.jetty.client.HttpClient-

第一个参数是选项的映射(在此示例中为空),第二个参数是您导入为HttpClient的Jetty的MyHttpClient实例。