Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.DefaultHttpClient


    assertEquals("Authentication failed", payLoad);
  }
 
  @Test
  public void queryParamsTest() throws ClientProtocolException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/query_params?key1=value1&key2=value2");
    HttpResponse response = httpclient.execute(httpget);
    List<String> expectedHeaders = Arrays.asList(new String[] {"Server", "Date", "Content-Length", "Etag", "Connection"});

    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here


    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
    HttpResponse response = httpclient.execute(httpget);
    List<String> expectedHeaders = Arrays.asList(new String[] {"Server", "Date", "Content-Length", "Etag", "Connection"});

    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/w");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/ww");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/wwfw");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/wfwf");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

    List<Header> headers = new LinkedList<Header>();
    headers.add(new BasicHeader("Connection", "Close"));
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/wfffwfff");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
View Full Code Here

        if (multiThreadedHttpClient)
            connManager = new ThreadSafeClientConnManager(httpParams, registry);
        else
            connManager = new SingleClientConnManager(httpParams, registry);

        DefaultHttpClient client = new DefaultHttpClient(connManager, httpParams);

        client.getParams().setParameter(AllClientPNames.MAX_REDIRECTS,
                                        new Integer(maxRedirects));
        client.getParams().setParameter(AllClientPNames.ALLOW_CIRCULAR_REDIRECTS,
                                        allowCircularRedirects);
        client.getParams().setParameter(AllClientPNames.SO_TIMEOUT,
                           new Integer(socketTimeout));
        client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT,
                        new Integer(connTimeout));

        if (cookiePolicy == null)
        {
            client.setCookieStore(null);
        }
        else
        {
            client.getParams().setParameter(AllClientPNames.COOKIE_POLICY,
                    cookiePolicy);
        }
       

        if (proxyProperties != null)
        {
            HttpHost proxy = new HttpHost(
                    proxyProperties.getProxyHostName(),
                    proxyProperties.getProxyPort());

          client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

            //now set headers for auth
            AuthScope authScope = new AuthScope(AuthScope.ANY_HOST,
                    AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
            Credentials credentials = proxyProperties.getCredentials();
            client.getCredentialsProvider().setCredentials(authScope, credentials);
        }

        return client;
    }
View Full Code Here

     *                       content.
     */
    protected XCapHttpResponse get(URI uri)
            throws XCapException
    {
        DefaultHttpClient httpClient = createHttpClient();
        try
        {
            HttpGet getMethod = new HttpGet(uri);
            getMethod.setHeader("Connection", "close");
            Credentials credentials =
                    new UsernamePasswordCredentials(getUserName(), password);
            httpClient.getCredentialsProvider().
                    setCredentials(AuthScope.ANY, credentials);

            HttpResponse response = httpClient.execute(getMethod);
            XCapHttpResponse result = createResponse(response);
            if (logger.isDebugEnabled())
            {
                byte[] contentBytes = result.getContent();
                String contenString;
                // for debug purposes print only xmls
                // skip the icon queries
                if(contentBytes != null && result.getContentType() != null
                        && !result.getContentType()
                                .startsWith(PresContentClient.CONTENT_TYPE))
                    contenString = new String(contentBytes);
                else
                    contenString = "";

                String logMessage = String.format(
                        "Getting resource %1s from the server content:%2s",
                        uri.toString(),
                        contenString
                );
                logger.debug(logMessage);
            }
            return result;
        }
        catch (IOException e)
        {
            String errorMessage = String.format(
                    "%1s resource cannot be read",
                    uri.toString());
            throw new XCapException(errorMessage, e);
        }
        finally
        {
            httpClient.getConnectionManager().shutdown();
        }
    }
View Full Code Here

     * @throws XCapException         if there is some error during operation.
     */
    public XCapHttpResponse put(XCapResource resource)
            throws XCapException
    {
        DefaultHttpClient httpClient = createHttpClient();
        try
        {
            URI resourceUri = getResourceURI(resource.getId());
            HttpPut putMethod = new HttpPut(resourceUri);
            putMethod.setHeader("Connection", "close");
            StringEntity stringEntity = new StringEntity(resource.getContent());
            stringEntity.setContentType(resource.getContentType());
            stringEntity.setContentEncoding("UTF-8");
            putMethod.setEntity(stringEntity);
            Credentials credentials =
                    new UsernamePasswordCredentials(getUserName(), password);
            httpClient.getCredentialsProvider().
                    setCredentials(AuthScope.ANY, credentials);
            if (logger.isDebugEnabled())
            {
                String logMessage = String.format(
                        "Puting resource %1s to the server %2s",
                        resource.getId().toString(),
                        resource.getContent()
                );
                logger.debug(logMessage);
            }
            HttpResponse response = httpClient.execute(putMethod);
            return createResponse(response);
        }
        catch (IOException e)
        {
            String errorMessage = String.format(
                    "%1s resource cannot be put",
                    resource.getId().toString());
            throw new XCapException(errorMessage, e);
        }
        finally
        {
            httpClient.getConnectionManager().shutdown();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.DefaultHttpClient

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.