Examples of DefaultHttpClient


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

    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

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

    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

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

        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

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

     *                       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

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

     * @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

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

     */
    public XCapHttpResponse delete(XCapResourceId resourceId)
            throws XCapException
    {
        assertConnected();
        DefaultHttpClient httpClient = createHttpClient();
        try
        {
            URI resourceUri = getResourceURI(resourceId);
            HttpDelete deleteMethod = new HttpDelete(resourceUri);
            deleteMethod.setHeader("Connection", "close");
            Credentials credentials =
                    new UsernamePasswordCredentials(getUserName(), password);
            httpClient.getCredentialsProvider().
                    setCredentials(AuthScope.ANY, credentials);
            if (logger.isDebugEnabled())
            {
                String logMessage = String.format(
                        "Deleting resource %1s from the server",
                        resourceId.toString()
                );
                logger.debug(logMessage);
            }
            HttpResponse response = httpClient.execute(deleteMethod);
            return createResponse(response);
        }
        catch (IOException e)
        {
            String errorMessage = String.format(
                    "%1s resource cannot be deleted",
                    resourceId.toString());
            throw new XCapException(errorMessage, e);
        }
        finally
        {
            httpClient.getConnectionManager().shutdown();
        }
    }
View Full Code Here

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

     *
     * @return the HTTP client.
     */
    private DefaultHttpClient createHttpClient()
    {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        try
        {
            // make sure we use Certificate Verification Service if
            // for some reason the certificate needs to be shown to user
            // for approval
            ClientConnectionManager ccm = httpClient.getConnectionManager();
            SchemeRegistry sr = ccm.getSchemeRegistry();
            SSLContext ctx = certificateVerification.getSSLContext(
                uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort());
            org.apache.http.conn.ssl.SSLSocketFactory ssf
                = new org.apache.http.conn.ssl.SSLSocketFactory(
                        ctx, new HostNameResolverImpl());
            ssf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory
                .ALLOW_ALL_HOSTNAME_VERIFIER);
            sr.register(new Scheme("https", ssf, 443));
        }
        catch(Throwable e)
        {
            logger.error("Cannot add our trust manager to httpClient", e);
        }
        HttpParams httpParams = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
        return httpClient;
    }
View Full Code Here

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

    this.tileWidth = tileWidth;
    this.tileHeight = tileHeight;
    this.style = style;
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(10);
    httpClient = new DefaultHttpClient(manager);
  }
View Full Code Here

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

      server.deploy(archive);

      try
      {
         // Get an HTTP Client
         final HttpClient client = new DefaultHttpClient();

         // Make an HTTP Request
         final String echoValue = "EmbeddedBiatch";
         final List<NameValuePair> params = new ArrayList<NameValuePair>();
         params.add(new BasicNameValuePair("jsp", PATH_JSP));
         params.add(new BasicNameValuePair("echo", echoValue));
         final URI uri = URIUtils.createURI("http", "localhost", 8080,
               appName + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here

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

      server.deploy(archive);

      try
      {
         // Get an HTTP Client
         final HttpClient client = new DefaultHttpClient();

         // Make an HTTP Request
         final URI uri = URIUtils.createURI("http", "localhost", 8080,
               appName + SEPARATOR + servletClass.getSimpleName(), null, null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.