Search in sources :

Example 56 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ResurrectionRemix.

the class CookiesTest method testCookiesWithNonMatchingCase.

/**
     * Test that cookies aren't case-sensitive with respect to hostname.
     * http://b/3167208
     */
public void testCookiesWithNonMatchingCase() throws Exception {
    // use a proxy so we can manipulate the origin server's host name
    server = new MockWebServer();
    server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
    server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
    server.play();
    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
    HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
    getCookies.getEntity().consumeContent();
    server.takeRequest();
    HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
    sendCookies.getEntity().consumeContent();
    RecordedRequest sendCookiesRequest = server.takeRequest();
    assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) HttpHost(org.apache.http.HttpHost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) MockWebServer(com.google.mockwebserver.MockWebServer) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 57 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ResurrectionRemix.

the class AbstractProxyTest method testConnectViaProxy.

/**
     * http://code.google.com/p/android/issues/detail?id=2690
     */
private void testConnectViaProxy(ProxyConfig proxyConfig) throws Exception {
    MockResponse mockResponse = new MockResponse().setResponseCode(200).setBody("this response comes via a proxy");
    server.enqueue(mockResponse);
    server.play();
    HttpClient httpProxyClient = newHttpClient();
    HttpGet request = new HttpGet("http://android.com/foo");
    proxyConfig.configure(server, httpProxyClient, request);
    HttpResponse response = httpProxyClient.execute(request);
    assertEquals("this response comes via a proxy", contentToString(response));
    RecordedRequest get = server.takeRequest();
    assertEquals("GET http://android.com/foo HTTP/1.1", get.getRequestLine());
    assertContains(get.getHeaders(), "Host: android.com");
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 58 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project android_frameworks_base by ResurrectionRemix.

the class AbstractProxyTest method testExplicitNoProxyCancelsSystemProperty.

public void testExplicitNoProxyCancelsSystemProperty() throws Exception {
    server.enqueue(new MockResponse().setBody("Via the origin server!"));
    server.play();
    System.setProperty("http.proxyHost", "proxy.foo");
    System.setProperty("http.proxyPort", "8080");
    HttpClient client = newHttpClient();
    HttpGet request = new HttpGet(server.getUrl("/bar").toURI());
    request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ConnRouteParams.NO_HOST);
    HttpResponse response = client.execute(request);
    assertEquals("Via the origin server!", contentToString(response));
    RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("GET /bar HTTP/1.1", recordedRequest.getRequestLine());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 59 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class Util method getRelationship.

private List<String> getRelationship(String tablename) throws ClientProtocolException, IOException {
    LinkedList<String> result = new LinkedList<String>();
    StringBuilder sb = new StringBuilder();
    sb.append(this.baseurl);
    sb.append("/api/now/table/");
    sb.append("sys_db_object");
    sb.append("?sysparm_exclude_reference_link=true");
    sb.append("&sysparm_query=name=");
    sb.append(tablename);
    sb.append("&sysparm_fields=name,super_class");
    HttpGet httpget = new HttpGet(sb.toString());
    httpget.setHeader("Accept", "application/json");
    HttpResponse response = this.client.execute(httpget);
    Map<String, String> info = extractResponse4OneRowFromArray(response);
    result.add(info.get("name"));
    String superclass = info.get("super_class");
    while (superclass != null && !superclass.isEmpty()) {
        sb.setLength(0);
        sb.append(this.baseurl);
        sb.append("/api/now/table/");
        sb.append("sys_db_object/");
        sb.append(superclass);
        sb.append("?sysparm_exclude_reference_link=true");
        sb.append("&sysparm_fields=name,super_class");
        httpget = new HttpGet(sb.toString());
        httpget.setHeader("Accept", "application/json");
        response = this.client.execute(httpget);
        info = extractResponse4OneRowFromObject(response);
        result.add(info.get("name"));
        superclass = info.get("super_class");
    }
    Collections.reverse(result);
    return result;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) LinkedList(java.util.LinkedList)

Example 60 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class paloconnection method sendToServer.

public HttpEntity sendToServer(List<NameValuePair> qparams, String strAPIUrl) throws paloexception {
    try {
        URI uri = URIUtils.createURI("http", strServer, Integer.valueOf(strPort), strAPIUrl, URLEncodedUtils.format(qparams, "UTF-8"), null);
        HttpGet req = new HttpGet(uri);
        // System.out.println(req.getURI());
        // Send to Server
        HttpResponse rsp = paloHttpClient.execute(paloTargetHost, req);
        HttpEntity entity = rsp.getEntity();
        if (rsp.getStatusLine().getStatusCode() != 200) {
            // Error had been occured
            // Close Connection and thend raise paloexception error
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            paloexception plX = new paloexception(csv.get(0), csv.get(1), csv.get(2));
            csv.close();
            entity.consumeContent();
            // paloHttpClient.getConnectionManager().shutdown();
            throw (plX);
        } else {
            return entity;
        }
    } catch (Exception e) {
        // if(paloHttpClient!=null)paloHttpClient.getConnectionManager().shutdown();
        throw new paloexception(e.getMessage());
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196