List of usage examples for org.apache.http.impl.conn DefaultClientConnectionOperator DefaultClientConnectionOperator
public DefaultClientConnectionOperator(final SchemeRegistry schemes)
From source file:com.dlmu.heipacker.crawler.examples.conn.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 {// w ww . j av a 2 s. c o m 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(); } }
From source file:httpclient.conn.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 {/*from www . j av a 2 s . c o m*/ 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(); } }
From source file:httpclient.conn.OperatorConnectProxy.java
public static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http"); // some general setup // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); // 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); // 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 {//from w w w. j ava 2s.c o m 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); // there is no request entity conn.flush(); System.out.println("receiving response header"); HttpResponse rsp = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); printResponseHeader(rsp); System.out.println("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:com.dlmu.heipacker.crawler.examples.conn.OperatorConnectProxy.java
public static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http"); // some general setup // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); supportedSchemes.register(new Scheme("https", 443, SSLSocketFactory.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); // 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 {/*from ww w .j a va 2s .c om*/ 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); // there is no request entity conn.flush(); System.out.println("receiving response header"); HttpResponse rsp = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); printResponseHeader(rsp); System.out.println("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java
protected ClientConnectionOperator createConnectionOperator(final SchemeRegistry schreg) { return new DefaultClientConnectionOperator(schreg); }
From source file:org.apache.http.impl.conn.ConnPoolBench.java
public static void newPool(int c, long reps) throws Exception { Log log = LogFactory.getLog(ConnPoolBench.class); DefaultClientConnectionOperator connOperator = new DefaultClientConnectionOperator( SchemeRegistryFactory.createDefault()); HttpConnPool pool = new HttpConnPool(log, connOperator, c, c * 10, -1, TimeUnit.MILLISECONDS); WorkerThread1[] workers = new WorkerThread1[c]; for (int i = 0; i < workers.length; i++) { workers[i] = new WorkerThread1(pool, reps); }//from w ww . ja v a2 s. co m long start = System.currentTimeMillis(); for (int i = 0; i < workers.length; i++) { workers[i].start(); } for (int i = 0; i < workers.length; i++) { workers[i].join(); } long finish = System.currentTimeMillis(); float totalTimeSec = (float) (finish - start) / 1000; System.out.print("Concurrency level:\t"); System.out.println(c); System.out.print("Total operations:\t"); System.out.println(c * reps); System.out.print("Time taken for tests:\t"); System.out.print(totalTimeSec); System.out.println(" seconds"); }
From source file:org.apache.http.impl.conn.ConnPoolBench.java
static void oldPool(int c, long reps) throws Exception { ClientConnectionOperator operator = new DefaultClientConnectionOperator( SchemeRegistryFactory.createDefault()); ConnPerRoute connPerRoute = new ConnPerRouteBean(c); ConnPoolByRoute pool = new ConnPoolByRoute(operator, connPerRoute, c * 10); WorkerThread2[] workers = new WorkerThread2[c]; for (int i = 0; i < workers.length; i++) { workers[i] = new WorkerThread2(pool, reps); }//from ww w.j a va 2 s. c om long start = System.currentTimeMillis(); for (int i = 0; i < workers.length; i++) { workers[i].start(); } for (int i = 0; i < workers.length; i++) { workers[i].join(); } long finish = System.currentTimeMillis(); float totalTimeSec = (float) (finish - start) / 1000; System.out.print("Concurrency level:\t"); System.out.println(c); System.out.print("Total operations:\t"); System.out.println(c * reps); System.out.print("Time taken for tests:\t"); System.out.print(totalTimeSec); System.out.println(" seconds"); }
From source file:org.apache.http.impl.conn.SingleClientConnManager.java
/** * Hook for creating the connection operator. * It is called by the constructor.//w ww . j a v a 2 s. com * 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 to use, or <code>null</code> * * @return the connection operator to use */ protected ClientConnectionOperator createConnectionOperator(final SchemeRegistry schreg) { return new DefaultClientConnectionOperator(schreg); }
From source file:org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.java
/** * Hook for creating the connection operator. * It is called by the constructor./*from ww w .j a v a2 s .c o m*/ * 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 }