Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpGet.addHeader()


  public static Map<String, Object> get(String url, Integer connectionTimeout, Integer soTimeout, Map<String, Object> authMap) throws Exception
  {
    HttpClient client = getHttpClient(url, connectionTimeout, soTimeout);
    HttpGet httpclient = new HttpGet(url);
    if (authMap != null)
      httpclient.addHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials((String) authMap.get("user"), (String) authMap.get("password")), httpclient));
    HttpResponse response = client.execute(httpclient);
    HttpEntity resEntity = response.getEntity();
    String contentCharSet = EntityUtils.getContentCharSet(resEntity);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("status", response.getStatusLine().getStatusCode());
View Full Code Here


    }
   
    @Test
    public void testGetCustomer() throws Exception {     
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/123");
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

   

    @Test
    public void testGetCustomerWithQuery() throws Exception {     
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers?id=123");
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

    }
   
    @Test
    public void testGetCustomers() throws Exception {
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/");
        get.addHeader("Accept" , "application/xml");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

    }
   
    @Test
    public void testGetSubResource() throws Exception {
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/orders/223/products/323");
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        try {
            HttpGet request = new HttpGet(baseRestUrl + "/status");
            request.setHeader("Accept", "application/json");
            request.addHeader("content-type", "application/json");
            String token = session("userToken");
            request.addHeader("rest-dspace-token", token);

            HttpResponse response = httpClient.execute(request);
            String responseBody = EntityUtils.toString(response.getEntity());
View Full Code Here

        try {
            HttpGet request = new HttpGet(baseRestUrl + "/status");
            request.setHeader("Accept", "application/json");
            request.addHeader("content-type", "application/json");
            String token = session("userToken");
            request.addHeader("rest-dspace-token", token);

            HttpResponse response = httpClient.execute(request);
            String responseBody = EntityUtils.toString(response.getEntity());
            User user = new User();
            user = user.parseUserFromJSON(Json.parse(responseBody));
View Full Code Here

                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        HttpGet request = new HttpGet(Application.baseRestUrl + "/collections/" + id + "?expand=all");
        request.setHeader("Accept", "application/json");
        request.addHeader("Content-Type", "application/json");
        request.addHeader("rest-dspace-token", token);
        HttpResponse httpResponse = httpClient.execute(request);

        JsonNode collNode = Json.parse(httpResponse.getEntity().getContent());
View Full Code Here

        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        HttpGet request = new HttpGet(Application.baseRestUrl + "/collections/" + id + "?expand=all");
        request.setHeader("Accept", "application/json");
        request.addHeader("Content-Type", "application/json");
        request.addHeader("rest-dspace-token", token);
        HttpResponse httpResponse = httpClient.execute(request);

        JsonNode collNode = Json.parse(httpResponse.getEntity().getContent());

        Collection collection = new Collection();
View Full Code Here

      String paramsStr = "";
      if (params != null) {
        paramsStr = "?" + URLEncodedUtils.format(params, "UTF-8");
      }
      HttpGet get = new HttpGet(url + paramsStr);
      get.addHeader("Content-Type", "application/json; charset=utf-8");

      return httpClient.execute(get, new BasicResponseHandler());
    } catch (IOException e) {
      throw new LogCommunicationException("Error making GET request to " + url, e);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.