Package org.apache.http.impl.client

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


    }

    public void testRejectRelativeRedirect() throws Exception {
        this.localServer.register("*", new RelativeRedirectService());

        DefaultHttpClient client = new DefaultHttpClient();

        client.getParams().setBooleanParameter(
                ClientPNames.REJECT_RELATIVE_REDIRECT, true);
        HttpGet httpget = new HttpGet("/oldlocation/");

        try {
            client.execute(getServerHttp(), httpget);
            fail("ClientProtocolException exception should have been thrown");
        } catch (ClientProtocolException e) {
            assertTrue(e.getCause() instanceof ProtocolException);
            // expected
        }
View Full Code Here


    }

    public void testRejectBogusRedirectLocation() throws Exception {
        this.localServer.register("*", new BogusRedirectService("xxx://bogus"));

        DefaultHttpClient client = new DefaultHttpClient();

        HttpGet httpget = new HttpGet("/oldlocation/");

        try {
            client.execute(getServerHttp(), httpget);
            fail("IllegalStateException should have been thrown");
        } catch (IllegalStateException e) {
            // expected
        }
    }
View Full Code Here

        String host = "localhost";
        int port = this.localServer.getServicePort();
        this.localServer.register("*",
                new BogusRedirectService("http://"+ host +":"+ port +"/newlocation/?p=I have spaces"));

        DefaultHttpClient client = new DefaultHttpClient();

        HttpGet httpget = new HttpGet("/oldlocation/");

        try {
            client.execute(getServerHttp(), httpget);
            fail("ClientProtocolException should have been thrown");
        } catch (ClientProtocolException e) {
            assertTrue(e.getCause() instanceof ProtocolException);
            // expected
        }
View Full Code Here

        int port = this.localServer.getServicePort();

        this.localServer.register("*",
                new BasicRedirectService(host, port));

        DefaultHttpClient client = new DefaultHttpClient();
       
        CookieStore cookieStore = new BasicCookieStore();
        client.setCookieStore(cookieStore);
       
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        cookie.setDomain("localhost");
        cookie.setPath("/");
       
        cookieStore.addCookie(cookie);

        HttpContext context = new BasicHttpContext();
        HttpGet httpget = new HttpGet("/oldlocation/");

       
        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }
       
View Full Code Here

        int port = this.localServer.getServicePort();

        this.localServer.register("*",
                new BasicRedirectService(host, port));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        List<Header> defaultHeaders = new ArrayList<Header>(1);
        defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, "my-test-client"));
       
        client.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders);
       
        HttpGet httpget = new HttpGet("/oldlocation/");

       
        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }
       
View Full Code Here

        int port = this.localServer.getServicePort();
        String host = "localhost";
        UriListeningService listener = new UriListeningService();
        this.localServer.register("*", listener);
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse response;

        if(!relative) {
            String request = "http://" + host + ":" + port + uri;
            HttpGet httpget = new HttpGet(request);
            response = client.execute(httpget);
            response.getEntity().consumeContent()
        } else {
            HttpHost target = new HttpHost(host, port);
            HttpGet httpget = new HttpGet(uri);
            response = client.execute(target, httpget);
            response.getEntity().consumeContent()
        }
       
        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());      
        assertEquals(uri, listener.getRequestedUri());
View Full Code Here

        ThreadSafeClientConnManager mgr = createTSCCM(params, null);

        // Zero connections in the pool
        assertEquals(0, mgr.getConnectionsInPool());
       
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);

        // Get some random data
        HttpGet httpget = new HttpGet("/random/20000");
        HttpHost target = getServerHttp();
       
        HttpResponse response = client.execute(target, httpget);

        ClientConnectionRequest connreq = mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
View Full Code Here

        ThreadSafeClientConnManager mgr = createTSCCM(params, null);

        // Zero connections in the pool
        assertEquals(0, mgr.getConnectionsInPool());
       
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);

        // Get some random data
        HttpGet httpget = new HttpGet("/random/20000");
        HttpHost target = getServerHttp();
       
        HttpResponse response = client.execute(target, httpget);

        ClientConnectionRequest connreq = mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
View Full Code Here

        ThreadSafeClientConnManager mgr = createTSCCM(params, null);

        // Zero connections in the pool
        assertEquals(0, mgr.getConnectionsInPool());
       
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);

        // Get some random data
        HttpGet httpget = new HttpGet("/random/20000");
        HttpHost target = getServerHttp();
       
        HttpResponse response = client.execute(target, httpget);

        ClientConnectionRequest connreq = mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
View Full Code Here

        ThreadSafeClientConnManager mgr = createTSCCM(params, null);

        // Zero connections in the pool
        assertEquals(0, mgr.getConnectionsInPool());
       
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);

        // Get some random data
        HttpGet httpget = new HttpGet("/dropdead");
        HttpHost target = getServerHttp();
       
        HttpResponse response = client.execute(target, httpget);

        ClientConnectionRequest connreq = mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
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.