List of usage examples for org.apache.http.protocol RequestContent RequestContent
public RequestContent()
From source file:org.apache.synapse.transport.passthru.config.TargetConfiguration.java
public TargetConfiguration(ConfigurationContext configurationContext, ParameterInclude parameters, WorkerPool pool, PassThroughTransportMetricsCollector metrics, ProxyAuthenticator proxyAuthenticator) { super(configurationContext, parameters, pool, metrics); httpProcessor = new ImmutableHttpProcessor( new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue() }); this.connectionTimeoutConfiguration = new ConnectionTimeoutConfiguration(conf.getConnectionIdleTime(), conf.getMaximumConnectionLifespan()); this.proxyAuthenticator = proxyAuthenticator; }
From source file:android.core.TestHttpClient.java
public TestHttpClient() { super();/*from www . ja v a2 s . com*/ this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1) .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1"); this.httpproc = new BasicHttpProcessor(); // Required protocol interceptors this.httpproc.addInterceptor(new RequestContent()); this.httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors this.httpproc.addInterceptor(new RequestConnControl()); this.httpproc.addInterceptor(new RequestUserAgent()); this.httpproc.addInterceptor(new RequestExpectContinue()); this.httpexecutor = new HttpRequestExecutor(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.context = new BasicHttpContext(null); }
From source file:com.nirima.jenkins.SimpleArtifactCopier.java
private void init() throws URISyntaxException { URI targetURI = host.toURI(); targetHost = new HttpHost(targetURI.getHost(), targetURI.getPort()); params = new BasicHttpParams(); params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024); httpexecutor = new HttpRequestExecutor(); httpproc = new BasicHttpProcessor(); // Required protocol interceptors httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); context = new BasicHttpContext(); conn = new DefaultHttpClientConnection(); connStrategy = new DefaultConnectionReuseStrategy(); }
From source file:net.kungfoo.grizzly.proxy.impl.Activator.java
private static void setupClient() throws IOReactorException { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); connectingIOReactor = new DefaultConnectingIOReactor(1, params); BasicHttpProcessor originServerProc = new BasicHttpProcessor(); originServerProc.addInterceptor(new RequestContent()); originServerProc.addInterceptor(new RequestTargetHost()); originServerProc.addInterceptor(new RequestConnControl()); originServerProc.addInterceptor(new RequestUserAgent()); originServerProc.addInterceptor(new RequestExpectContinue()); NHttpClientHandler connectingHandler = new ConnectingHandler(originServerProc, new DefaultConnectionReuseStrategy(), params); connectingEventDispatch = new DefaultClientIOEventDispatch(connectingHandler, params); }
From source file:com.devoteam.srit.xmlloader.http.test.HttpLoaderServer.java
public void sendRequest(String method, String uri, HttpParams params) throws IOException { // Required protocol interceptors httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); context.setAttribute(ExecutionContext.HTTP_CONNECTION, Clientconn); context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, hostname); try {/*from w ww .jav a2 s. c om*/ testConnection(); BasicHttpRequest br = new BasicHttpRequest(method, uri); context.setAttribute(ExecutionContext.HTTP_REQUEST, br); br.setParams(params); //myclass.doSendRequest(br, Clientconn, context); } catch (Exception e) { } }
From source file:com.jrodeo.remote.TestHttpCore.java
public TestHttpCore() { super();//from w ww .j ava 2 s .c o m this.params = new SyncBasicHttpParams(); this.params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); this.params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); this.params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); this.params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024); this.params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000); this.httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent() }, null); this.httpexecutor = new HttpRequestExecutor(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.pool = new BasicConnPool(this.params); }
From source file:bigbird.benchmark.BenchmarkWorker.java
public BenchmarkWorker(final HttpParams params, int verbosity, final RequestGenerator requestGenerator, final HttpHost targetHost, int count, boolean keepalive) { super();// w w w .j a va2 s .c o m this.params = params; this.requestGenerator = requestGenerator; this.context = new BasicHttpContext(null); this.targetHost = targetHost; this.count = count; this.keepalive = keepalive; this.httpProcessor = new BasicHttpProcessor(); this.httpexecutor = new HttpRequestExecutor(); // Required request interceptors this.httpProcessor.addInterceptor(new RequestContent()); this.httpProcessor.addInterceptor(new RequestTargetHost()); // Recommended request interceptors this.httpProcessor.addInterceptor(new RequestConnControl()); this.httpProcessor.addInterceptor(new RequestUserAgent()); this.httpProcessor.addInterceptor(new RequestExpectContinue()); this.connstrategy = new DefaultConnectionReuseStrategy(); this.verbosity = verbosity; }
From source file:com.cxic.ip.WebUrl.java
public String getResponseStr() { String userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", getClass()); HttpProcessor httpprocessorCopy = null; if (httpprocessorCopy == null) { final HttpProcessorBuilder b = HttpProcessorBuilder.create(); b.addAll(new RequestDefaultHeaders(null), new RequestContent(), new RequestTargetHost(), // new RequestClientConnControl(), new RequestUserAgent(userAgentCopy), new RequestExpectContinue()); b.add(new RequestAddCookies()); b.add(new RequestAcceptEncoding()); b.add(new RequestAuthCache()); b.add(new ResponseProcessCookies()); b.add(new ResponseContentEncoding()); httpprocessorCopy = b.build();//from www. j a va 2s. co m } HttpHost proxy = new HttpHost(ip, port, "http"); // DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient httpclient = HttpClients.custom() // .setRoutePlanner(routePlanner) .setProxy(proxy).setHttpProcessor(httpprocessorCopy).build(); String r = ""; HttpGet httpGet = new HttpGet(url); // httpGet.setHeader("GET http://www.stilllistener.com/checkpoint1/test2/ HTTP/1.1",""); // httpGet.setHeader("Host","www.stilllistener.com"); // httpGet.setHeader("User-Agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0"); // httpGet.setHeader("User-Agent","Baiduspider+(+http://www.baidu.com/search/spider.htm)"); // httpGet.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // httpGet.setHeader("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3"); // httpGet.setHeader("Accept-Encoding","gzip, deflate"); // httpGet.setHeader("Referer",url); // httpGet.setHeader("Connection","keep-alive"); // httpGet.setHeader("Cache-Control","max-age=0"); CloseableHttpResponse response1 = null; try { response1 = httpclient.execute(httpGet); HttpEntity entity1 = response1.getEntity(); String line = response1.getStatusLine().getReasonPhrase(); // System.out.println(line); if (line.equals("OK")) { r = EntityUtils.toString(entity1); // System.out.println(r); // do something useful with the response body // and ensure it is fully consumed // InputStream in = entity1.getContent(); // System.out.println(EntityUtils.toString(entity1,"GB2312")); //System.out.println(in.toString()); } // do something useful with the response body // and ensure it is fully consumed // InputStream in = entity1.getContent(); // System.out.println(EntityUtils.toString(entity1,"GB2312")); //System.out.println(in.toString()); //System.out.println(EntityUtils.toString(entity1)); EntityUtils.consume(entity1); response1.close(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return r; }
From source file:com.couchbase.client.ClusterManager.java
/** * Creates a connection to the Couchbase REST interface. * * @param uris A list of servers in the cluster. * @param username The cluster admin user name. * @param password The cluster admin password. *//*from www .j av a 2s .c o m*/ public ClusterManager(List<URI> uris, String username, String password) { addrs = uris; user = username; pass = password; httpproc = new ImmutableHttpProcessor( new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue() }); httpexecutor = new HttpRequestExecutor(); context = new BasicHttpContext(null); conn = new DefaultHttpClientConnection(); }
From source file:net.spy.memcached.CouchbaseConnection.java
private List<CouchbaseNode> createConnections(List<InetSocketAddress> addrs) throws IOException { List<CouchbaseNode> nodeList = new LinkedList<CouchbaseNode>(); for (InetSocketAddress a : addrs) { HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "Spymemcached Client/1.1"); HttpProcessor httpproc = new ImmutableHttpProcessor( new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(), }); AsyncNHttpClientHandler protocolHandler = new AsyncNHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(), new DefaultConnectionReuseStrategy(), new DirectByteBufferAllocator(), params); protocolHandler.setEventListener(new EventLogger()); AsyncConnectionManager connMgr = new AsyncConnectionManager(new HttpHost(a.getHostName(), a.getPort()), NUM_CONNS, protocolHandler, params); getLogger().info("Added %s to connect queue", a); CouchbaseNode node = connFactory.createCouchDBNode(a, connMgr); node.init();/*from ww w . j av a2 s . com*/ nodeList.add(node); } return nodeList; }