How to Send a Message to OpenStack Zaqar with the Java API for WebSocket


import javax.websocket.ClientEndpoint;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;

public final class SampleZaqarEndpoint {

  public void onOpen(final Session sess) throws IOException {
    final RemoteEndpoint.Basic remote = sess.getBasicRemote();

    remote.sendText("{\"action\":\"authenticate\",\"headers\":{\"X-Auth-Token\":...,\"X-Project-ID\":...}}"); // refer to bug #1553398

    remote.sendText("{\"action\":\"message_post\",\"body\":{\"messages\":[{\"body\":\"Simples Assim\"}],\"queue_name\":\"SampleQueue\"},\"headers\":{\"Client-ID\":...,\"X-Project-ID\":...}}");



import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.ContainerProvider;
import javax.websocket.WebSocketContainer;

@WebServlet(name = "SampleZaqarServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {

  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
    final WebSocketContainer container = ContainerProvider.getWebSocketContainer();

    container.connectToServer(SampleZaqarEndpoint.class, new URI("ws://host:9090"));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s