Search in sources :

Example 46 with HttpClient

use of org.apache.http.client.HttpClient in project intellij-community by JetBrains.

the class RedmineRepository method fetchProjects.

public List<RedmineProject> fetchProjects() throws Exception {
    HttpClient client = getHttpClient();
    // Download projects with pagination (IDEA-125056, IDEA-125157)
    List<RedmineProject> allProjects = new ArrayList<>();
    int offset = 0;
    ProjectsWrapper wrapper;
    do {
        HttpGet method = new HttpGet(getProjectsUrl(offset, 50));
        wrapper = client.execute(method, new GsonSingleObjectDeserializer<>(GSON, ProjectsWrapper.class));
        offset += wrapper.getProjects().size();
        allProjects.addAll(wrapper.getProjects());
    } while (wrapper.getTotalCount() > allProjects.size() || wrapper.getProjects().isEmpty());
    myProjects = allProjects;
    return Collections.unmodifiableList(myProjects);
}
Also used : GsonSingleObjectDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonSingleObjectDeserializer) RedmineProject(com.intellij.tasks.redmine.model.RedmineProject) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList)

Example 47 with HttpClient

use of org.apache.http.client.HttpClient in project nhin-d by DirectProject.

the class HttpClientFactory method createHttpClient.

/**
	 * Creates an HttpClient with the default connection timeout and SO timeout.
	 * @return The HTTP client.
	 */
public static HttpClient createHttpClient() {
    final HttpClient client = new DefaultHttpClient(conMgr);
    final HttpParams httpParams = client.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_CON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SO_TIMEOUT);
    return client;
}
Also used : HttpParams(org.apache.http.params.HttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 48 with HttpClient

use of org.apache.http.client.HttpClient in project nhin-d by DirectProject.

the class HttpClientFactory method createHttpClient.

/**
	 * Creates an HttpClient with a specific connection timeout and SO timeout.
	 * @return The HTTP client.
	 */
public static HttpClient createHttpClient(int conTimeOut, int soTimeout) {
    final HttpClient client = new DefaultHttpClient(conMgr);
    final HttpParams httpParams = client.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, conTimeOut);
    HttpConnectionParams.setSoTimeout(httpParams, soTimeout);
    return client;
}
Also used : HttpParams(org.apache.http.params.HttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 49 with HttpClient

use of org.apache.http.client.HttpClient in project nhin-d by DirectProject.

the class UsecuredServiceRequestBase_constructTest method testConstruct_validConstruction.

@Test
public void testConstruct_validConstruction() throws Exception {
    HttpClient client = mock(HttpClient.class);
    MockServiceRequest req = new MockServiceRequest(client, "http://service/svc", "Test");
    assertNotNull(req);
    assertEquals(client, req.httpClient);
    assertEquals("Test", req.msg);
    assertEquals("http://service/svc", req.serviceUrl);
}
Also used : HttpClient(org.apache.http.client.HttpClient) Test(org.junit.Test)

Example 50 with HttpClient

use of org.apache.http.client.HttpClient in project nhin-d by DirectProject.

the class UnsecureServiceRequestBase_callTest method testCall_callWithNoReturnValue.

@Test
public void testCall_callWithNoReturnValue() throws Exception {
    HttpClient mockClient = mock(HttpClient.class);
    StatusLine statLine = mock(StatusLine.class);
    when(statLine.getStatusCode()).thenReturn(204);
    HttpResponse resp = mock(HttpResponse.class);
    when(resp.getStatusLine()).thenReturn(statLine);
    when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
    MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "Test");
    assertNull(req.call());
}
Also used : StatusLine(org.apache.http.StatusLine) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpClient (org.apache.http.client.HttpClient)878 HttpResponse (org.apache.http.HttpResponse)548 HttpGet (org.apache.http.client.methods.HttpGet)394 Test (org.junit.Test)273 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)264 IOException (java.io.IOException)258 HttpPost (org.apache.http.client.methods.HttpPost)197 HttpEntity (org.apache.http.HttpEntity)118 URI (java.net.URI)87 InputStream (java.io.InputStream)81 ArrayList (java.util.ArrayList)64 ClientProtocolException (org.apache.http.client.ClientProtocolException)61 InputStreamReader (java.io.InputStreamReader)59 StringEntity (org.apache.http.entity.StringEntity)58 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)58 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)56 MockResponse (com.google.mockwebserver.MockResponse)48 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)48 BufferedReader (java.io.BufferedReader)46 URISyntaxException (java.net.URISyntaxException)45