Guest User

Jersey Example

a guest
Jun 5th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package com.metricstream.rnd.dashboard.jira;
  2.  
  3. import javax.ws.rs.client.Client;
  4. import javax.ws.rs.client.ClientBuilder;
  5. import javax.ws.rs.client.Invocation;
  6. import javax.ws.rs.client.WebTarget;
  7. import javax.ws.rs.core.MediaType;
  8. import javax.ws.rs.core.Response;
  9.  
  10. import org.glassfish.jersey.client.ClientConfig;
  11. import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
  12. import org.glassfish.jersey.jackson.JacksonFeature;
  13.  
  14.  
  15. //https://metricstreampm.atlassian.net/rest/api/latest/issue/RCM-538.json
  16. public class JerseClientGet {
  17.  
  18. private static final String JIRA_ADMIN_USERNAME = "vivek.agrawal@metricstream.com";
  19. private static final String JIRA_ADMIN_PASSWORD = "India@05";
  20.  
  21. public static void main(String[] args) {
  22. try {
  23.  
  24. ClientConfig clientConfig = new ClientConfig();
  25.  
  26. HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
  27. clientConfig.register( feature) ;
  28.  
  29. clientConfig.register(JacksonFeature.class);
  30.  
  31. Client client = ClientBuilder.newClient( clientConfig );
  32. WebTarget webTarget = client.target("https://metricstreampm.atlassian.net/rest/api/latest/issue/RCM-538.json");
  33.  
  34. Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
  35. Response response = invocationBuilder.get();
  36.  
  37. System.out.println(response.getStatus());
  38. System.out.println(response.getStatusInfo());
  39.  
  40. if(response.getStatus() == 200)
  41. {
  42. String respons = response.readEntity(String.class);
  43. System.out.println(respons);
  44. }
  45.  
  46. } catch (Exception e) {
  47.  
  48. e.printStackTrace();
  49.  
  50. }
  51.  
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment