Package org.apache.http.client

Examples of org.apache.http.client.HttpClient


    public List<Community> parentCommunities = new ArrayList<Community>();

    public static RestResponse findByID(Long id, String token) throws IOException {
        RestResponse restResponse = new RestResponse();
        //TODO insecure ssl hack
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .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());

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


        return restResponse;
    }

    public RestResponse update(String token) throws IOException {
        //TODO insecure ssl hack
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        HttpPut request = new HttpPut(Application.baseRestUrl + "/communities/" + this.id);
        request.setHeader("Accept", "application/json");
        request.addHeader("Content-Type", "application/json");
        request.addHeader("rest-dspace-token", token);

        //Only allow certain attributes... "name", "copyrightText", "introductoryText", "shortDescription", "sidebarText"
        Logger.info("EditCommunity json: " + Json.toJson(this).toString());
        ObjectNode jsonObjectNode = Json.newObject().put("name", this.name).put("copyrightText", this.copyrightText)
                .put("introductoryText", this.introductoryText)
                .put("shortDescription", this.shortDescription)
                .put("sidebarText", this.sidebarText);
        StringEntity stringEntity = new StringEntity(jsonObjectNode.toString());
        Logger.info("EditCommunity certain attributes: " + jsonObjectNode.toString());

        request.setEntity(stringEntity);
        HttpResponse httpResponse = httpClient.execute(request);
        RestResponse restResponse = new RestResponse();
        restResponse.httpResponse = httpResponse;
        restResponse.endpoint = request.getURI().toString();
        return restResponse;
    }
View Full Code Here

  }
 
  private TestMusicBrainzClient getClient() {
    WebserviceInvocation invocation = Mockito.mock(WebserviceInvocation.class);
    TestMusicBrainzClient client = new TestMusicBrainzClient(invocation);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    client.setHttpClient(httpClient);

    WebserviceHistoryService webserviceHistoryService =
        Mockito.mock(WebserviceHistoryService.class);
    client.setWebserviceHistoryService(webserviceHistoryService);
View Full Code Here

        argument.getValue().getURI().toString().contains(expectedUrl));
  }
 
  private ArtistQueryClient getArtistQueryClient() {
    ArtistQueryClient artistQueryClient = new ArtistQueryClient();
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    artistQueryClient.setHttpClient(httpClient);

    WebserviceHistoryService webserviceHistoryService =
        Mockito.mock(WebserviceHistoryService.class);
    artistQueryClient.setWebserviceHistoryService(webserviceHistoryService);
View Full Code Here

    assertEquals(EXPECTED_URI, argument.getValue().getURI().toASCIIString());
  }
 
  private ReleaseGroupsClient getReleaseGroupsClient() {
    ReleaseGroupsClient releaseGroupsClient = new ReleaseGroupsClient();
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    releaseGroupsClient.setHttpClient(httpClient);

    WebserviceHistoryService webserviceHistoryService =
        Mockito.mock(WebserviceHistoryService.class);
    releaseGroupsClient.setWebserviceHistoryService(webserviceHistoryService);
View Full Code Here

  /*
   * Help method to create a base TestWSClient.
   */
  private TestWSPostAuthenticatedClient getTestWSClient(List<NameValuePair> params,
      String responseURI) throws IOException {
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    ClientConnectionManager connectionManager = Mockito.mock(
        ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);

    StatusLine statusLine = Mockito.mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(200);
   
    HttpEntity httpEntity = Mockito.mock(HttpEntity.class);
    when(httpEntity.getContent()).thenReturn(new ResourceUtil(responseURI).getInputStream());
   
    HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(httpResponse.getEntity()).thenReturn(httpEntity);
   
    when(httpClient.execute(Mockito.any(HttpUriRequest.class))).thenReturn(httpResponse);
   
    TestWSPostAuthenticatedClient testClient = new TestWSPostAuthenticatedClient(params);
    testClient.setHttpClient(httpClient);

    return testClient;
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  private ArtistTopTagsClient getArtistTopTagsClient(WebserviceHistoryService historyService) throws IOException {
    // create a HTTP client that always returns Cher top tracks
    HttpClient httpClient = mock(HttpClient.class);
    ClientConnectionManager connectionManager = mock(ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
    String httpResponse = new ResourceUtil(CHER_TOP_TAGS).getContent();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class),
        Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);

    // create a throttling service that allows calls at any rate
    ThrottleService throttleService = mock(ThrottleService.class);
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  private TestWSGetClient getTestWSClient(
      boolean allowCalls, String responseURI) throws IOException {
    TestWSGetClient testWSClient = getTestWSClient(allowCalls);
    HttpClient httpClient = testWSClient.getHttpClient();
    String httpResponse = new ResourceUtil(responseURI).getContent();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class),
        Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);
    return testWSClient;
  }
View Full Code Here

   * Creates and returns a TestWSClient that throws an exception on invocation.
   */
  @SuppressWarnings("unchecked")
  private TestWSGetClient getTestWSClient(Exception e) throws IOException {
    TestWSGetClient testWSClient = getTestWSClient(true);
    HttpClient httpClient = testWSClient.getHttpClient();
    when(httpClient.execute(Mockito.any(HttpUriRequest.class),
        Mockito.any(ResponseHandler.class))).thenThrow(e);
    return testWSClient;
  }
View Full Code Here

 
  /*
   * Help method to create a base TestWSClient.
   */
  private TestWSGetClient getTestWSClient(boolean allowCalls) {
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    ClientConnectionManager connectionManager = Mockito.mock(
        ClientConnectionManager.class);
    when(httpClient.getConnectionManager()).thenReturn(connectionManager);
   
    WebserviceHistoryService historyService = mock(WebserviceHistoryService.class);
    when(historyService.isWebserviceInvocationAllowed(
        Mockito.any(WebserviceInvocation.class))).thenReturn(allowCalls);
   
View Full Code Here

TOP

Related Classes of org.apache.http.client.HttpClient

Copyright © 2018 www.massapicom. 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.