How to Receive a Message from OpenStack Zaqar with JAX-RS

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
 
@SuppressWarnings("serial")
@WebServlet(name = "SampleZaqarServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final Client client = ClientBuilder.newClient();

    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();

    headers.putSingle("Client-ID", ...);

    headers.putSingle("X-Auth-Token", ...);

    headers.putSingle("X-Project-Id", ...);

    final Response res = client.target("http://host:8888/v1.1/queues/SampleQueue/claims").request().headers(headers).post(Entity.json(""));

    resp.getWriter().println(res.readEntity(String.class));
 
    client.close();
  }
 
}

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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