我基于java HttpServlet创建了Atmosphere Meteor Pubsub。我在特定服务器上发布了它。 然后,我想要调用Meteor pubsub的post方法。 这该怎么做? 例如:我在地址:192.168.x.xx:Port / meteor-pubsub上发布了meteor pubsub。保留代码java来调用post方法,我在客户端上写
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
// Create a Meteor
Meteor m = Meteor.build(req);
// Log all events on the console, including WebSocket events.
m.addListener(new WebSocketEventListenerAdapter());
res.setContentType("text/html;charset=ISO-8859-1");
Broadcaster b = lookupBroadcaster(req.getPathInfo());
m.setBroadcaster(b);
m.suspend(-1);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
Broadcaster b = lookupBroadcaster(req.getPathInfo());
String message = req.getReader().readLine();
if (message != null && message.indexOf("message") != -1) {
b.broadcast(message.substring("message=".length()));
}
}
Broadcaster lookupBroadcaster(String pathInfo) {
String[] decodedPath = pathInfo.split("/");
Broadcaster b;
if (decodedPath.length > 0) {
b = BroadcasterFactory.getDefault().lookup(decodedPath[decodedPath.length - 1], true);
} else {
b = BroadcasterFactory.getDefault().lookup("/", true);
}
return b;
}
答案 0 :(得分:0)
您可以使用RESTClient之类的东西:
只需在方法下拉列表中选择POST,然后编写要使用的正文。对于Atmosphere,您可以发送JSON格式的消息。