Java 类org.apache.http.impl.conn.DefaultClientConnectionOperator 实例源码

项目:PhET    文件:OperatorConnectDirect.java   
public static void main(String[] args) throws Exception {
    HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    // some general setup
    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    SchemeRegistry supportedSchemes = new SchemeRegistry();
    SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    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();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
    } finally {
        System.out.println("closing connection");
        conn.close();
    }
}
项目:cJUnit-mc626    文件:OperatorConnectDirect.java   
public static void main(String[] args) throws Exception {
    HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    // some general setup
    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    SchemeRegistry supportedSchemes = new SchemeRegistry();
    SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    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();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
    } finally {
        System.out.println("closing connection");
        conn.close();
    }
}
项目:LibraryH3lp-Transfer-Bot    文件:OperatorConnectDirect.java   
public static void main(String[] args) throws Exception {
    HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    // some general setup
    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    SchemeRegistry supportedSchemes = new SchemeRegistry();
    supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    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();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
    } finally {
        System.out.println("closing connection");
        conn.close();
    }
}
项目:whiskers    文件:HttpHost.java   
@Override
protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schemeRegistry) {
    resolver = new InMemoryDnsResolver();
    DefaultClientConnectionOperator op = new DefaultClientConnectionOperator(schemeRegistry, resolver);
    return op;
}
项目:Gw2InfoViewer    文件:OperatorConnectDirect.java   
public static void main(String[] args) throws Exception {
    HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    // some general setup
    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    SchemeRegistry supportedSchemes = new SchemeRegistry();
    supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    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();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
    } finally {
        System.out.println("closing connection");
        conn.close();
    }
}
项目:lams    文件:PoolingClientConnectionManager.java   
/**
 * Hook for creating the connection operator.
 * It is called by the constructor.
 * Derived classes can override this method to change the
 * instantiation of the operator.
 * The default implementation here instantiates
 * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
 *
 * @param schreg    the scheme registry.
 *
 * @return  the connection operator to use
 */
protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg) {
        return new DefaultClientConnectionOperator(schreg, this.dnsResolver);
}
项目:lams    文件:ThreadSafeClientConnManager.java   
/**
 * Hook for creating the connection operator.
 * It is called by the constructor.
 * Derived classes can override this method to change the
 * instantiation of the operator.
 * The default implementation here instantiates
 * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
 *
 * @param schreg    the scheme registry.
 *
 * @return  the connection operator to use
 */
protected ClientConnectionOperator
    createConnectionOperator(SchemeRegistry schreg) {

    return new DefaultClientConnectionOperator(schreg);// @ThreadSafe
}
项目:purecloud-iot    文件:ThreadSafeClientConnManager.java   
/**
 * Hook for creating the connection operator.
 * It is called by the constructor.
 * Derived classes can override this method to change the
 * instantiation of the operator.
 * The default implementation here instantiates
 * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
 *
 * @param schreg    the scheme registry.
 *
 * @return  the connection operator to use
 */
protected ClientConnectionOperator
    createConnectionOperator(final SchemeRegistry schreg) {

    return new DefaultClientConnectionOperator(schreg);// @ThreadSafe
}
项目:cJUnit-mc626    文件:ThreadSafeClientConnManager.java   
/**
 * Hook for creating the connection operator.
 * It is called by the constructor.
 * Derived classes can override this method to change the
 * instantiation of the operator.
 * The default implementation here instantiates
 * {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
 *
 * @param schreg    the scheme registry.
 *
 * @return  the connection operator to use
 */
protected ClientConnectionOperator
    createConnectionOperator(SchemeRegistry schreg) {

    return new DefaultClientConnectionOperator(schreg);// @ThreadSafe
}