List of usage examples for org.apache.http.params HttpParams setIntParameter
HttpParams setIntParameter(String str, int i);
From source file:com.couchbase.client.ViewNodeTest.java
private AsyncConnectionManager createConMgr(String host, int port) throws IOReactorException { HttpHost target = new HttpHost(host, port); int maxConnections = 1; 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, "Couchbase Java 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 ViewNode.MyHttpRequestExecutionHandler(), new DefaultConnectionReuseStrategy(), new DirectByteBufferAllocator(), params); protocolHandler.setEventListener(new ViewNode.EventLogger()); RequeueOpCallback callback = mock(RequeueOpCallback.class); AsyncConnectionManager manager = new AsyncConnectionManager(target, maxConnections, protocolHandler, params, callback);/*from w ww .j av a 2s . co m*/ return manager; }
From source file:NioHttpClient.java
public NioHttpClient(String user_agent, HttpRequestExecutionHandler request_handler, EventListener connection_listener) throws Exception { // Construct the long-lived HTTP parameters. HttpParams parameters = new BasicHttpParams(); parameters // Socket data timeout is 5,000 milliseconds (5 seconds). .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) // Maximum time allowed for connection establishment is 10,00 milliseconds (10 seconds). .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) // Socket buffer size is 8 kB. .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // Don't bother to check for stale TCP connections. .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) // Don't use Nagle's algorithm (in other words minimize latency). .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) // Set the user agent string that the client sends to the server. .setParameter(CoreProtocolPNames.USER_AGENT, user_agent); // Construct the core HTTP request processor. BasicHttpProcessor http_processor = new BasicHttpProcessor(); // Add Content-Length header to request where appropriate. http_processor.addInterceptor(new RequestContent()); // Always include Host header in requests. http_processor.addInterceptor(new RequestTargetHost()); // Maintain connection keep-alive by default. http_processor.addInterceptor(new RequestConnControl()); // Include user agent information in each request. http_processor.addInterceptor(new RequestUserAgent()); // Allocate an HTTP client handler. BufferingHttpClientHandler client_handler = new BufferingHttpClientHandler(http_processor, // Basic HTTP Processor. request_handler, new DefaultConnectionReuseStrategy(), parameters); client_handler.setEventListener(connection_listener); // Use two worker threads for the IO reactor. io_reactor = new DefaultConnectingIOReactor(2, parameters); io_event_dispatch = new DefaultClientIOEventDispatch(client_handler, parameters); }
From source file:org.apache.synapse.transport.passthru.config.BaseConfiguration.java
protected HttpParams buildHttpParams() { HttpParams params = new BasicHttpParams(); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, conf.getIntProperty(HttpConnectionParams.SO_TIMEOUT, 60000)) .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, conf.getIntProperty(HttpConnectionParams.CONNECTION_TIMEOUT, 0)) .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, conf.getIntProperty(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)) .setParameter(HttpProtocolParams.ORIGIN_SERVER, conf.getStringProperty(HttpProtocolParams.ORIGIN_SERVER, "WSO2-PassThrough-HTTP")) .setParameter(HttpProtocolParams.USER_AGENT, conf.getStringProperty(HttpProtocolParams.USER_AGENT, "Synapse-PT-HttpComponents-NIO")); // setParameter(HttpProtocolParams.HTTP_ELEMENT_CHARSET, // conf.getStringProperty(HttpProtocolParams.HTTP_ELEMENT_CHARSET, HTTP.DEFAULT_PROTOCOL_CHARSET));//TODO:This does not works with HTTPCore 4.3 return params; }
From source file:swp.bibclient.Network.java
/** * Fragt bei einem Server nach den Medien an. * * @return Die Liste der Medien.//from w w w. j av a 2s . co m * @throws IOException * Kann geworfen werden bei IO-Problemen. */ public final List<Medium> getMediums() throws IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setzen eines ConnectionTimeout von 2 Sekunden: HttpParams params = httpClient.getParams(); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); httpClient.setParams(params); // Der BibServer sollte lokal laufen, daher zugriff auf Localhost // 10.0.2.2 fr den AndroidEmulator. HttpContext localContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(server + mediumpath); String text = null; Log.i(Network.class.getName(), "Try to get a http connection..."); HttpResponse response = httpClient.execute(httpGet, localContext); HttpEntity entity = response.getEntity(); text = getASCIIContentFromEntity(entity); Log.i(Network.class.getName(), "Create new Gson object"); Gson gson = new Gson(); Log.i(Network.class.getName(), "Create listOfTestObject"); // Wir arbeiten mit einem TypeToken um fr eine generische Liste wieder // Objekte zu erhalten. Type listOfTestObject = new TypeToken<List<Medium>>() { }.getType(); Log.i(Network.class.getName(), "Convert to a list."); /* * Hier befindet sich ein unsicherer Cast, da wir nicht wirklich wissen, * ob der String, den wir von der Website bekommen, sich wirklich in * eine Liste von Bchern umwandeln lsst */ try { @SuppressWarnings("unchecked") List<Medium> list = Collections.synchronizedList((List<Medium>) gson.fromJson(text, listOfTestObject)); return list; } catch (ClassCastException e) { throw new ClientProtocolException("Returned type is not a list of book objects"); } }
From source file:org.dspace.submit.lookup.ArXivService.java
protected List<Record> search(String query, String arxivid, int max_result) throws IOException, HttpException { List<Record> results = new ArrayList<Record>(); HttpGet method = null;// w w w . j av a 2s . c om try { HttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); try { URIBuilder uriBuilder = new URIBuilder("http://export.arxiv.org/api/query"); uriBuilder.addParameter("id_list", arxivid); uriBuilder.addParameter("search_query", query); uriBuilder.addParameter("max_results", String.valueOf(max_result)); method = new HttpGet(uriBuilder.build()); } catch (URISyntaxException ex) { throw new HttpException(ex.getMessage()); } // Execute the method. HttpResponse response = client.execute(method); StatusLine responseStatus = response.getStatusLine(); int statusCode = responseStatus.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_BAD_REQUEST) throw new RuntimeException("arXiv query is not valid"); else throw new RuntimeException("Http call failed: " + responseStatus); } try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db = factory.newDocumentBuilder(); Document inDoc = db.parse(response.getEntity().getContent()); Element xmlRoot = inDoc.getDocumentElement(); List<Element> dataRoots = XMLUtils.getElementList(xmlRoot, "entry"); for (Element dataRoot : dataRoots) { Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot); if (crossitem != null) { results.add(crossitem); } } } catch (Exception e) { throw new RuntimeException("ArXiv identifier is not valid or not exist"); } } finally { if (method != null) { method.releaseConnection(); } } return results; }
From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java
public void run() { logger.info("Starting server."); System.out.println("Starting server...."); //int localPort = MaryProperties.needInteger("socket.port"); int localPort = serverPort; HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html")); //registry.register("/process", new FileDataRequestHandler("perception.html")); //registry.register("/perceptionTest", new UtterancePlayRequestHandler()); DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName); UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH); registry.register("/options", infoRH); registry.register("/queryStatement", infoRH); registry.register("/process", new UtterancePlayRequestHandler(infoRH)); registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH)); registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH)); registry.register("*", new FileDataRequestHandler()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5); int numParallelThreads = 5; logger.info("Waiting for client to connect on port " + localPort); System.out.println("Waiting for client to connect on port " + localPort); try {//from w w w . ja v a 2 s. c o m ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params); ioReactor.listen(new InetSocketAddress(localPort)); ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.info("Interrupted", ex); System.out.println("Interrupted" + ex.toString()); } catch (IOException e) { logger.info("Problem with HTTP connection ", e); System.out.println("Problem with HTTP connection " + e.toString()); } logger.debug("Shutdown"); System.out.println("Shutdown"); }
From source file:com.yanzhenjie.andserver.DefaultAndServer.java
@Override public void run() { try {/* ww w.j a v a 2s . c o m*/ mServerSocket = new ServerSocket(); mServerSocket.setReuseAddress(true); mServerSocket.bind(new InetSocketAddress(mPort)); // HTTP?? BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); // HTTP Attribute. HttpParams httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WebServer/1.1"); // Http? HttpRequestHandlerRegistry handlerRegistry = new HttpRequestHandlerRegistry(); for (Map.Entry<String, AndServerRequestHandler> handlerEntry : mRequestHandlerMap.entrySet()) { handlerRegistry.register("/" + handlerEntry.getKey(), new DefaultHttpRequestHandler(handlerEntry.getValue())); } // HTTP? HttpService httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); httpService.setParams(httpParams); httpService.setHandlerResolver(handlerRegistry); /** * ? */ while (isLoop) { // if (!mServerSocket.isClosed()) { Socket socket = mServerSocket.accept(); DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection(); serverConnection.bind(socket, httpParams); // Dispatch request handler. RequestHandleTask requestTask = new RequestHandleTask(this, httpService, serverConnection); requestTask.setDaemon(true); AndWebUtil.executeRunnable(requestTask); } } } catch (Exception e) { } finally { close(); } }
From source file:NioHttpServer.java
public NioHttpServer(int port, // TCP port for the server. HttpRequestHandler request_responder, // Scheme level responder for HTTP requests from clients. EventListener connection_listener) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler service_handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", request_responder); service_handler.setHandlerResolver(reqistry); service_handler.setEventListener(connection_listener); // Provide a connection listener. // Use two worker threads for the IO reactor. io_reactor = new DefaultListeningIOReactor(2, params); io_event_dispatch = new DefaultServerIOEventDispatch(handler, params); this.port = port; // Set the listening TCP port. }
From source file:com.zotoh.maedr.device.apache.HttpIO.java
protected void onStart() throws Exception { // mostly copied from apache http tutotial... HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, (int) getSocetTimeoutMills()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // 8k? .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Apache-HttpCore/4.x"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); ConnectionReuseStrategy strategy = new DefaultConnectionReuseStrategy(); HttpResponseFactory rspFac = new DefaultHttpResponseFactory(); NHttpServiceHandler svc;/* ww w . j av a 2 s. com*/ EventListener evt = new EventLogger(getId(), tlog()); if (isAsync()) { AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, rspFac, strategy, params); NHttpRequestHandlerRegistry r = new NHttpRequestHandlerRegistry(); r.register("*", new HttpNRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } else { StreamedHttpServiceHandler handler = new StreamedHttpServiceHandler(httpproc, rspFac, strategy, params); HttpRequestHandlerRegistry r = new HttpRequestHandlerRegistry(); r.register("*", new HttpRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } IOEventDispatch disp = isSSL() ? onSSL(svc, params) : onBasic(svc, params); ListeningIOReactor ioReactor; ioReactor = new DefaultListeningIOReactor(getWorkers(), params); ioReactor.listen(new InetSocketAddress(NetUte.getNetAddr(getHost()), getPort())); _curIO = ioReactor; // start... runServer(disp, ioReactor); }
From source file:org.sonatype.nexus.test.utils.hc4client.Hc4ClientHelper.java
@Override public void start() throws Exception { super.start(); HttpParams params = new SyncBasicHttpParams(); params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024); params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getConnectTimeout()); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, getReadTimeout()); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); final PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(); connManager.setMaxTotal(getMaxTotalConnections()); connManager.setDefaultMaxPerRoute(getMaxConnectionsPerHost()); httpClient = new DefaultHttpClient(connManager, params); getLogger().info("Starting the HTTP client"); }