How to Call a REST Service with RESTEasy ClientRequest API

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 org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;

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

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final ClientRequest clientReq = new ClientRequest("http://localhost/sample");

    final ClientResponse<String> clientResp = clientReq.get(String.class);

    resp.getWriter().println(clientResp.getEntity());
  }

}

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