我的常规代码:
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)
答案 0 :(得分:1)
BayeuxClient
的Javadoc与LongPollingTransport
类完全不同步 - there is no such method as LongPollingTransport.create(arg)
。
相反,您可以尝试使用此类的常规构造函数,例如
BayeuxClient client = new BayeuxClient(myurl, new LongPollingTransport([:], httpClient))
第一个参数是选项的映射(在此示例中为空),第二个参数是您导入为HttpClient
的Jetty的MyHttpClient
实例。