Skip to Content
0
Former Member
Jul 25, 2016 at 08:22 PM

Build a Get Request with httpClient

57 Views

I want to make a REST get-call to a remote service via my HCP application. First I had to download the certificate from that site and added destination in my application which I called "Backend", there I uploaded those SSL certificates and now I want to call to that remote service to that API which ends with the path "/clients" but it's not working as I want....

Any ideas what I do wrong?

@Path("/")

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PaymentServiceTest {
@GET
@Path("/clientList")
public Response clientList() throws ServletException, NamingException, DestinationException, ClientProtocolException, IOException, URISyntaxException {

Context ctx = null;
int status = 200;

ctx = new InitialContext();
HttpDestination destination = (HttpDestination) ctx.lookup("java:comp/env/Backend");
HttpClient createHttpClient = destination.createHttpClient();
URI uri = destination.getURI();
String host = uri.getHost();
String path = uri.getPath();
String url = "https://" + host + path + "/clients";
HttpGet get = new HttpGet(url);
HttpResponse resp = createHttpClient.execute(get);

return Response.status(status).entity(resp).build();