List of usage examples for org.apache.http.params HttpParams getIntParameter
int getIntParameter(String str, int i);
From source file:org.hydracache.server.httpd.HttpParamsFactoryTest.java
@Test public void testSocketTimeoutSetting() { HttpParamsFactory factory = new HttpParamsFactory(); int expectedSocketTimeout = 500; factory.setSocketTimeout(expectedSocketTimeout); HttpParams params = factory.create(); assertEquals("Socket timeout is not correctly set", expectedSocketTimeout, params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0)); }
From source file:org.hydracache.server.httpd.HttpParamsFactoryTest.java
@Test public void testSocketBufferSizeSetting() { HttpParamsFactory factory = new HttpParamsFactory(); int expectedBufferSize = 1024; factory.setSocketBufferSize(expectedBufferSize); HttpParams params = factory.create(); assertEquals("Socket buffer size is not correctly set", expectedBufferSize, params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 0)); }
From source file:com.google.api.client.http.apache.ApacheHttpTransportTest.java
private void checkDefaultHttpClient(DefaultHttpClient client) { HttpParams params = client.getParams(); assertTrue(client.getConnectionManager() instanceof ThreadSafeClientConnManager); assertEquals(8192, params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1)); DefaultHttpRequestRetryHandler retryHandler = (DefaultHttpRequestRetryHandler) client .getHttpRequestRetryHandler(); assertEquals(0, retryHandler.getRetryCount()); assertFalse(retryHandler.isRequestSentRetryEnabled()); }
From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagonTest.java
public void testSetMaxRedirectsParamViaConfig() { HttpMethodConfiguration methodConfig = new HttpMethodConfiguration(); int maxRedirects = 2; methodConfig.addParam(ClientPNames.MAX_REDIRECTS, "%i," + maxRedirects); HttpConfiguration config = new HttpConfiguration(); config.setAll(methodConfig);//from w w w . j a v a 2 s . c o m TestWagon wagon = new TestWagon(); wagon.setHttpConfiguration(config); HttpHead method = new HttpHead(); wagon.setParameters(method); HttpParams params = method.getParams(); assertNotNull(params); assertEquals(maxRedirects, params.getIntParameter(ClientPNames.MAX_REDIRECTS, -1)); }
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.ECFHttpClientProtocolSocketFactory.java
public Socket connectSocket(final Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int timeout = params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, ECFHttpClientProtocolSocketFactory.class, "connectSocket " + remoteAddress.toString() + " timeout=" + timeout); //$NON-NLS-1$ //$NON-NLS-2$ try {//ww w .j a va 2 s.co m // Use String.valueOf to protect against null Trace.trace(Activator.PLUGIN_ID, "bind(" + String.valueOf(localAddress) + ")"); //$NON-NLS-1$//$NON-NLS-2$ sock.bind(localAddress); Trace.trace(Activator.PLUGIN_ID, "connect(" + remoteAddress.toString() + ", " + timeout + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ sock.connect(remoteAddress, timeout); Trace.trace(Activator.PLUGIN_ID, "connected"); //$NON-NLS-1$ } catch (IOException e) { Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, ECFHttpClientProtocolSocketFactory.class, "createSocket", e); //$NON-NLS-1$ fireEvent(socketConnectListener, new SocketClosedEvent(source, sock, sock)); Trace.throwing(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_THROWING, ECFHttpClientProtocolSocketFactory.class, "createSocket", e); //$NON-NLS-1$ throw e; } Socket toReturn; Socket wrapped = new CloseMonitoringSocket(sock, socketConnectListener, source); SocketConnectedEvent connectedEvent = new SocketConnectedEvent(source, sock, wrapped); fireEvent(socketConnectListener, connectedEvent); // Change the wrapped socket if one of the receivers of the SocketConnectedEvent changed it if (connectedEvent.getSocket() != wrapped) { toReturn = connectedEvent.getSocket(); ((CloseMonitoringSocket) wrapped).setWrappedSocket(toReturn); } else { toReturn = wrapped; } return toReturn; }
From source file:hornet.framework.technical.HTTPClientParameterBuilderTest.java
/** * Teste la mthode <tt>loadHttpParamToHttpClientFromConfig</tt> pour le cas o le paramtrage par dfaut * est dfini./*from w w w . ja v a2 s. co m*/ */ @SuppressWarnings("unchecked") @Test public void testLoadHttpParamToHttpClientShouldLoadDefaultValue() { final HttpClient httpClient = new DefaultHttpClient(); HTTPClientParameterBuilder.loadHttpParamToHttpClientFromConfig(httpClient, null); final HttpParams httpParams = httpClient.getParams(); assertEquals(CONST_3000, httpParams.getIntParameter("http.connection.timeout", 0)); final Map<HttpHost, Integer> maxPerHost = (Map<HttpHost, Integer>) httpParams .getParameter("http.connection-manager.max-per-host"); assertEquals(1, maxPerHost.size()); assertTrue(maxPerHost.containsKey(new HttpHost("hostname"))); assertEquals(Integer.valueOf(CONST_50), maxPerHost.get(new HttpHost("hostname"))); assertEquals(CONST_50, httpParams.getIntParameter("http.connection-manager.max-total", 0)); assertEquals(CONST_3000, httpParams.getLongParameter("http.connection-manager.timeout", 0)); assertEquals(CONST_60000, httpParams.getIntParameter("http.socket.timeout", 0)); assertEquals(org.apache.http.impl.conn.PoolingHttpClientConnectionManager.class, httpParams.getParameter("http.connection-manager.class")); }
From source file:com.subgraph.vega.internal.http.proxy.VegaHttpRequestParser.java
public VegaHttpRequestParser(final VegaHttpServerConnection conn, final SessionInputBuffer buffer, final LineParser parser, final HttpRequestFactory requestFactory, final HttpParams params) { if (requestFactory == null) { throw new IllegalArgumentException("Request factory may not be null"); }/*from w w w.ja v a 2 s . com*/ this.conn = conn; this.sessionBuffer = buffer; this.lineParser = parser; this.requestFactory = requestFactory; this.lineBuf = new CharArrayBuffer(128); this.maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); }
From source file:org.vietspider.net.apache.DefaultResponseParser.java
public DefaultResponseParser(final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { if (buffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); }/*from w w w . j a v a 2s .c om*/ if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this._sessionBuffer = buffer; // this.timeoutSocket = params.getBooleanParameter("vietspider.socket.timeout", false); this.maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT; if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); this.maxGarbageLines = params.getIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, Integer.MAX_VALUE); }
From source file:org.opendatakit.http.conn.GaeManagedClientConnection.java
@Override public void flush() throws IOException { // flush is always called by // org.apache.http.protocol.HttpRequestExecutor.doSendRequest // Build and issue the URLFetch request here. URLFetchService service = URLFetchServiceFactory.getURLFetchService(); boolean redirect = HttpClientParams.isRedirecting(params); @SuppressWarnings("unused") boolean authenticate = HttpClientParams.isAuthenticating(params); // TODO: verify that authentication is handled by URLFetchService... // default is to throw an exception on a overly-large request // follow redirects (e.g., to https), and to validate server // certificates. com.google.appengine.api.urlfetch.FetchOptions f = com.google.appengine.api.urlfetch.FetchOptions.Builder .withDefaults();// w ww . j a v a 2 s . co m f.disallowTruncate(); f.validateCertificate(); if (redirect) { f.followRedirects(); } else { f.doNotFollowRedirects(); } // set a deadline if we have a wait-for-continue limit // in an expectContinue situation // or a timeout value set on the connection. HttpParams params = request.getParams(); int deadline = 0; int msWaitForContinue = params.getIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, 2000); if (expectContinueHeaders == null) { msWaitForContinue = 0; } int soTimeout = org.apache.http.params.HttpConnectionParams.getSoTimeout(params); int connTimeout = org.apache.http.params.HttpConnectionParams.getConnectionTimeout(params); if (soTimeout <= 0 || connTimeout <= 0) { deadline = 0; // wait forever... } else { int maxDelay = Math.max(Math.max(timeoutMilliseconds, msWaitForContinue), connTimeout); deadline = soTimeout + maxDelay; } if (deadline > 0) { logger.info("URLFetch timeout (socket + connection) (ms): " + deadline); f.setDeadline(new Double(0.001 * (double) deadline)); } f.validateCertificate(); com.google.appengine.api.urlfetch.HTTPMethod method; if (request instanceof HttpGet) { method = HTTPMethod.GET; } else if (request instanceof HttpPut) { method = HTTPMethod.PUT; } else if (request instanceof HttpPost) { method = HTTPMethod.POST; } else if (request instanceof HttpHead) { method = HTTPMethod.HEAD; } else if (request instanceof HttpDelete) { method = HTTPMethod.DELETE; } else if (request instanceof EntityEnclosingRequestWrapper) { String name = ((EntityEnclosingRequestWrapper) request).getMethod(); method = HTTPMethod.valueOf(name); } else if (request instanceof RequestWrapper) { String name = ((RequestWrapper) request).getMethod(); method = HTTPMethod.valueOf(name); } else { throw new IllegalStateException("Unrecognized Http request method"); } // we need to construct the URL for the request // to the target host. The request line, for, e.g., // a get, needs to be added to the URL. URL url = new URL(targetHost.getSchemeName(), targetHost.getHostName(), targetHost.getPort(), request.getRequestLine().getUri()); com.google.appengine.api.urlfetch.HTTPRequest req = new com.google.appengine.api.urlfetch.HTTPRequest(url, method, f); Header[] headers = request.getAllHeaders(); for (Header h : headers) { req.addHeader(new com.google.appengine.api.urlfetch.HTTPHeader(h.getName(), h.getValue())); } // restore the expect-continue header if (expectContinueHeaders != null) { for (Header h : expectContinueHeaders) { req.addHeader(new com.google.appengine.api.urlfetch.HTTPHeader(h.getName(), h.getValue())); } } // see if we need to copy entity body over... if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); if (entity != null) { ByteArrayOutputStream blobStream = new ByteArrayOutputStream(); entity.writeTo(blobStream); req.setPayload(blobStream.toByteArray()); } } response = service.fetch(req); }
From source file:com.archivas.clienttools.arcutils.impl.adapter.HCAPAdapter.java
/** * Retrieves the current connection timeout, null if not set or if set to Integer.MIN_VALUE * //from w ww . j av a 2s.c om * @return The current timeout */ protected Integer getIntClientParameter(final String parameter) { HttpParams params = httpClient.getParams(); int value = params.getIntParameter(parameter, Integer.MIN_VALUE); if (value != Integer.MIN_VALUE) { return value; } else { return null; } }