Search in sources :

Example 91 with HttpClient

use of org.apache.http.client.HttpClient in project eap-additional-testsuite by jboss-set.

the class UndertowSslSecurityDomainTestCase method testForbidden.

/**
 * Tests access to resource that requires authentication and authorization. Principal has not required role.
 */
@Test
public void testForbidden() {
    HttpClient client = SSLTruststoreUtil.getHttpClientWithSSL(CLIENT_KEYSTORE_FILE, PASSWORD, CLIENT_TRUSTSTORE_FILE, PASSWORD);
    assertAccessForbidden(client);
    closeClient(client);
}
Also used : HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Test(org.junit.Test)

Example 92 with HttpClient

use of org.apache.http.client.HttpClient in project eap-additional-testsuite by jboss-set.

the class UndertowTwoWaySslNeedClientAuthTestCase method testSendingTrustedClientCertificate.

@Test
public void testSendingTrustedClientCertificate() {
    HttpClient client = SSLTruststoreUtil.getHttpClientWithSSL(CLIENT_KEYSTORE_FILE, PASSWORD, CLIENT_TRUSTSTORE_FILE, PASSWORD);
    assertConnectionToServer(client, SC_OK);
    closeClient(client);
}
Also used : HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Test(org.junit.Test)

Example 93 with HttpClient

use of org.apache.http.client.HttpClient in project eap-additional-testsuite by jboss-set.

the class UndertowTwoWaySslNeedClientAuthTestCase method testSendingNonTrustedClientCertificateFails.

@Test
public void testSendingNonTrustedClientCertificateFails() {
    HttpClient client = SSLTruststoreUtil.getHttpClientWithSSL(UNTRUSTED_STORE_FILE, PASSWORD, CLIENT_TRUSTSTORE_FILE, PASSWORD);
    assertSslHandshakeFails(client);
    closeClient(client);
}
Also used : HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Test(org.junit.Test)

Example 94 with HttpClient

use of org.apache.http.client.HttpClient in project uavstack by uavorg.

the class DoTestOpenTSDBQuery method main.

@SuppressWarnings("resource")
public static void main(String[] args) throws ClientProtocolException, IOException {
    String queryurl = "http://localhost:8765/hm/query";
    HttpPost post = new HttpPost(queryurl);
    HttpClient client = new DefaultHttpClient();
    UAVHttpMessage request = new UAVHttpMessage();
    request.putRequest("start", "146234606");
    request.putRequest("end", "1462346020");
    request.putRequest("metric", "urlResp.tmax");
    request.putRequest("aggregator", "sum");
    request.putRequest("downsample", "1ms-avg");
    LinkedHashMap<String, String> tags = new LinkedHashMap<String, String>();
    tags.put("ip", "127.0.0.1");
    request.putRequest("tags", JSONHelper.toString(tags));
    request.putRequest(DataStoreProtocol.DATASTORE_NAME, HealthManagerConstants.DataStore_Monitor);
    String queryJson = JSONHelper.toString(request);
    // String queryJson = "{\"request\":"
    // +"{\"start\":\"1461908927\",\"end\":\"1461908932\","
    // +"\"datastore.name\":\"monitorDataStore\","
    // +"\"queries\":[{"
    // +"\"aggregator\":\"sum\","
    // +"\"metric\":\"urlResp.tmax\","
    // +"\"downsample\":\"1ms-avg\","
    // +"\"tags\":{\"ip\":\"127.0.0.1\"}"
    // +"}]"
    // +"},"
    // +"\"responseAsJsonString\":\"{}\"}";
    StringEntity entity = new StringEntity(queryJson);
    post.setEntity(entity);
    HttpResponse response = client.execute(post);
    if (response != null) {
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            String result = EntityUtils.toString(resEntity);
            LOG.info(result);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) LinkedHashMap(java.util.LinkedHashMap)

Example 95 with HttpClient

use of org.apache.http.client.HttpClient in project summer-bean by cn-cerc.

the class RemoteService method postData.

private String postData(String url, String params) throws ClientProtocolException, IOException {
    HttpPost httpPost = new HttpPost(url);
    StringEntity entity = new StringEntity(params.toString(), "UTF-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    log.debug("post: " + url);
    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(httpPost);
    // 如果请求成功
    if (response.getStatusLine().getStatusCode() != 200) {
        this.setMessage("请求服务器失败,错误代码为:" + response.getStatusLine().getStatusCode());
        return null;
    }
    // 获取响应实体
    HttpEntity entity2 = response.getEntity();
    return EntityUtils.toString(entity2, "UTF-8");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse)

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