Package org.apache.http.conn

Examples of org.apache.http.conn.ClientConnectionOperator


        HttpParams params = new SyncBasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUseExpectContinue(params, false);

        // one operator can be used for many connections
        ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

        HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
        req.addHeader("Host", target.getHostName());

        HttpContext ctx = new BasicHttpContext();

        OperatedClientConnection conn = scop.createConnection();
        try {
            System.out.println("opening connection to " + target);
            scop.openConnection(conn, target, null, ctx, params);
            System.out.println("sending request");
            conn.sendRequestHeader(req);
            // there is no request entity
            conn.flush();

View Full Code Here


        HttpParams params = new SyncBasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUseExpectContinue(params, false);

        // one operator can be used for many connections
        ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

        HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
        // In a real application, request interceptors should be used
        // to add the required headers.
        req.addHeader("Host", target.getHostName());

        HttpContext ctx = new BasicHttpContext();

        OperatedClientConnection conn = scop.createConnection();
        try {
            System.out.println("opening connection to " + proxy);
            scop.openConnection(conn, proxy, null, ctx, params);

            // Creates a request to tunnel a connection.
            // For details see RFC 2817, section 5.2
            String authority = target.getHostName() + ":" + target.getPort();
            HttpRequest connect = new BasicHttpRequest("CONNECT", authority,
                    HttpVersion.HTTP_1_1);
            // In a real application, request interceptors should be used
            // to add the required headers.
            connect.addHeader("Host", authority);

            System.out.println("opening tunnel to " + target);
            conn.sendRequestHeader(connect);
            // there is no request entity
            conn.flush();

            System.out.println("receiving confirmation for tunnel");
            HttpResponse connected = conn.receiveResponseHeader();
            System.out.println("----------------------------------------");
            printResponseHeader(connected);
            System.out.println("----------------------------------------");
            int status = connected.getStatusLine().getStatusCode();
            if ((status < 200) || (status > 299)) {
                System.out.println("unexpected status code " + status);
                System.exit(1);
            }
            System.out.println("receiving response body (ignored)");
            conn.receiveResponseEntity(connected);

            // Now we have a tunnel to the target. As we will be creating a
            // layered TLS/SSL socket immediately afterwards, updating the
            // connection with the new target is optional - but good style.
            // The scheme part of the target is already "https", though the
            // connection is not yet switched to the TLS/SSL protocol.
            conn.update(null, target, false, params);

            System.out.println("layering secure connection");
            scop.updateSecureConnection(conn, target, ctx, params);

            // finally we have the secure connection and can send the request

            System.out.println("sending request");
            conn.sendRequestHeader(req);
View Full Code Here

    @Test
    public void testStatelessConnections() throws Exception {
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);

        ClientConnectionOperator operator = new DefaultClientConnectionOperator(
                supportedSchemes);

        ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
        ConnPoolByRoute connPool = new ConnPoolByRoute(operator, connPerRoute, 20);
        try {
View Full Code Here

    @Test
    public void testStatefullConnections() throws Exception {
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);

        ClientConnectionOperator operator = new DefaultClientConnectionOperator(
                supportedSchemes);

        ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
        ConnPoolByRoute connPool = new ConnPoolByRoute(operator, connPerRoute, 20);
        try {
View Full Code Here



    public void testBasicPoolEntry() {
        HttpRoute route = new HttpRoute(TARGET);
        ClientConnectionOperator ccop =
            new DefaultClientConnectionOperator(supportedSchemes);

        BasicPoolEntry bpe = null;
        try {
            bpe = new BasicPoolEntry(null, null, null);
View Full Code Here

    public void testStatelessConnections() throws Exception {
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);

        ClientConnectionOperator operator = new DefaultClientConnectionOperator(
                supportedSchemes);
       
        BasicHttpParams params = new BasicHttpParams();
        ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
        HttpConnectionManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
View Full Code Here

    public void testStatefullConnections() throws Exception {
        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);

        ClientConnectionOperator operator = new DefaultClientConnectionOperator(
                supportedSchemes);
       
        BasicHttpParams params = new BasicHttpParams();
        ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
        HttpConnectionManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
View Full Code Here

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUseExpectContinue(params, false);

        // one operator can be used for many connections
        ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

        HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
        req.addHeader("Host", target.getHostName());
       
        HttpContext ctx = new BasicHttpContext();

        OperatedClientConnection conn = scop.createConnection();
        try {
            System.out.println("opening connection to " + target);
            scop.openConnection(conn, target, null, ctx, params);
            System.out.println("sending request");
            conn.sendRequestHeader(req);
            // there is no request entity
            conn.flush();

View Full Code Here

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUseExpectContinue(params, false);

        // one operator can be used for many connections
        ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

        HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
        // In a real application, request interceptors should be used
        // to add the required headers.
        req.addHeader("Host", target.getHostName());
       
        HttpContext ctx = new BasicHttpContext();

        OperatedClientConnection conn = scop.createConnection();
        try {
            System.out.println("opening connection to " + proxy);
            scop.openConnection(conn, proxy, null, ctx, params);

            // Creates a request to tunnel a connection.
            // For details see RFC 2817, section 5.2
            String authority = target.getHostName() + ":" + target.getPort();
            HttpRequest connect = new BasicHttpRequest("CONNECT", authority,
                    HttpVersion.HTTP_1_1);
            // In a real application, request interceptors should be used
            // to add the required headers.
            connect.addHeader("Host", authority);

            System.out.println("opening tunnel to " + target);
            conn.sendRequestHeader(connect);
            // there is no request entity
            conn.flush();

            System.out.println("receiving confirmation for tunnel");
            HttpResponse connected = conn.receiveResponseHeader();
            System.out.println("----------------------------------------");
            printResponseHeader(connected);
            System.out.println("----------------------------------------");
            int status = connected.getStatusLine().getStatusCode();
            if ((status < 200) || (status > 299)) {
                System.out.println("unexpected status code " + status);
                System.exit(1);
            }
            System.out.println("receiving response body (ignored)");
            conn.receiveResponseEntity(connected);

            // Now we have a tunnel to the target. As we will be creating a
            // layered TLS/SSL socket immediately afterwards, updating the
            // connection with the new target is optional - but good style.
            // The scheme part of the target is already "https", though the
            // connection is not yet switched to the TLS/SSL protocol.
            conn.update(null, target, false, params);

            System.out.println("layering secure connection");
            scop.updateSecureConnection(conn, target, ctx, params);

            // finally we have the secure connection and can send the request

            System.out.println("sending request");
            conn.sendRequestHeader(req);
View Full Code Here

        HttpParams params = new SyncBasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUseExpectContinue(params, false);

        // one operator can be used for many connections
        ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

        HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
        req.addHeader("Host", target.getHostName());
       
        HttpContext ctx = new BasicHttpContext();

        OperatedClientConnection conn = scop.createConnection();
        try {
            System.out.println("opening connection to " + target);
            scop.openConnection(conn, target, null, ctx, params);
            System.out.println("sending request");
            conn.sendRequestHeader(req);
            // there is no request entity
            conn.flush();

View Full Code Here

TOP

Related Classes of org.apache.http.conn.ClientConnectionOperator

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.