List of usage examples for org.apache.commons.httpclient.params HttpClientParams MAX_REDIRECTS
String MAX_REDIRECTS
To view the source code for org.apache.commons.httpclient.params HttpClientParams MAX_REDIRECTS.
Click Source Link
From source file:com.simplifide.core.net.LicenseConnection.java
public void connect() { HttpClientParams params = new HttpClientParams(); params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); params.setIntParameter(HttpClientParams.MAX_REDIRECTS, 4); HttpClient client = new HttpClient(params); client.getHttpConnectionManager().getParams().setConnectionTimeout(30000); GetMethod post = new GetMethod("http://simplifide.com/drupal/free_trial2"); post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); /* NameValuePair[] data = { new NameValuePair("user_name", "joe"), new NameValuePair("password", "aaa"), new NameValuePair("name", "joker"), new NameValuePair("email", "beta"), };/*from w w w.java 2 s.com*/ post.setRequestBody(data); */ try { int rettype = client.executeMethod(post); byte[] responseBody = post.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data String tstring = new String(responseBody); } catch (HttpException e) { HardwareLog.logError(e); } catch (IOException e) { HardwareLog.logError(e); } finally { post.releaseConnection(); } }
From source file:com.orange.mmp.net.http.HttpConnectionManager.java
public Connection getConnection() throws MMPNetException { SimpleHttpConnectionManager shcm = new SimpleHttpConnectionManager(); HttpClientParams defaultHttpParams = new HttpClientParams(); defaultHttpParams.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); defaultHttpParams.setParameter(HttpConnectionParams.TCP_NODELAY, true); defaultHttpParams.setParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); defaultHttpParams.setParameter(HttpConnectionParams.SO_LINGER, 0); defaultHttpParams.setParameter(HttpClientParams.MAX_REDIRECTS, 3); defaultHttpParams.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false); HttpClient httpClient2 = new HttpClient(defaultHttpParams, shcm); if (HttpConnectionManager.proxyHost != null) { defaultHttpParams.setParameter("http.route.default-proxy", new HttpHost(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort)); // TODO Host configuration ! if (HttpConnectionManager.proxyHost != null/* && this.useProxy*/) { HostConfiguration config = new HostConfiguration(); config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort); httpClient2.setHostConfiguration(config); } else {//from w w w . ja v a 2s.c o m HostConfiguration config = new HostConfiguration(); config.setProxyHost(null); httpClient2.setHostConfiguration(config); } } return new HttpConnection(httpClient2); }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Create basic http client with default params. * * @return HttpClient instance/* w ww .j av a 2 s . c o m*/ */ private static HttpClient getBaseInstance() { HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, IE_USER_AGENT); httpClient.getParams().setParameter(HttpClientParams.MAX_REDIRECTS, MAX_REDIRECTS); httpClient.getParams().setCookiePolicy("DavMailCookieSpec"); return httpClient; }
From source file:ch.cyberduck.core.http.HTTP3Session.java
protected HostConfiguration getHostConfiguration(Host host) { int port = host.getPort(); final HostConfiguration configuration = new StickyHostConfiguration(); if ("https".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 443;//w w w . j ava 2 s .c o m } // Configuration with custom socket factory using the trust manager configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol(host.getProtocol().getScheme(), new SSLSocketFactory(this.getTrustManager(host.getHostname())), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPSProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host)); } } } else if ("http".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 80; } configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol( host.getProtocol().getScheme(), new DefaultProtocolSocketFactory(), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host)); } } } final HostParams parameters = configuration.getParams(); parameters.setParameter(HttpMethodParams.USER_AGENT, this.getUserAgent()); parameters.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); parameters.setParameter(HttpMethodParams.SO_TIMEOUT, this.timeout()); parameters.setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "ISO-8859-1"); parameters.setParameter(HttpClientParams.MAX_REDIRECTS, 10); return configuration; }
From source file:com.motorola.studio.android.common.utilities.HttpUtils.java
private InputStream getInputStreamForUrl(String url, IProgressMonitor monitor, boolean returnStream) throws IOException { SubMonitor subMonitor = SubMonitor.convert(monitor); subMonitor.beginTask(UtilitiesNLS.HttpUtils_MonitorTask_PreparingConnection, 300); StudioLogger.debug(HttpUtils.class, "Verifying proxy usage for opening http connection"); //$NON-NLS-1$ // Try to retrieve proxy configuration to use if necessary IProxyService proxyService = ProxyManager.getProxyManager(); IProxyData proxyData = null;/*from w w w . ja va2 s. c o m*/ if (proxyService.isProxiesEnabled() || proxyService.isSystemProxiesEnabled()) { Authenticator.setDefault(new NetAuthenticator()); if (url.startsWith("https")) { proxyData = proxyService.getProxyData(IProxyData.HTTPS_PROXY_TYPE); StudioLogger.debug(HttpUtils.class, "Using https proxy"); //$NON-NLS-1$ } else if (url.startsWith("http")) { proxyData = proxyService.getProxyData(IProxyData.HTTP_PROXY_TYPE); StudioLogger.debug(HttpUtils.class, "Using http proxy"); //$NON-NLS-1$ } else { StudioLogger.debug(HttpUtils.class, "Not using any proxy"); //$NON-NLS-1$ } } // Creates the http client and the method to be executed HttpClient client = null; client = new HttpClient(); // If there is proxy data, work with it if (proxyData != null) { if (proxyData.getHost() != null) { // Sets proxy host and port, if any client.getHostConfiguration().setProxy(proxyData.getHost(), proxyData.getPort()); } if ((proxyData.getUserId() != null) && (proxyData.getUserId().trim().length() > 0)) { // Sets proxy user and password, if any Credentials cred = new UsernamePasswordCredentials(proxyData.getUserId(), proxyData.getPassword() == null ? "" : proxyData.getPassword()); //$NON-NLS-1$ client.getState().setProxyCredentials(AuthScope.ANY, cred); } } InputStream streamForUrl = null; getMethod = new GetMethod(url); getMethod.setFollowRedirects(true); // set a 30 seconds timeout HttpMethodParams params = getMethod.getParams(); params.setSoTimeout(15 * ONE_SECOND); getMethod.setParams(params); boolean trying = true; Credentials credentials = null; subMonitor.worked(100); subMonitor.setTaskName(UtilitiesNLS.HttpUtils_MonitorTask_ContactingSite); do { StudioLogger.info(HttpUtils.class, "Attempting to make a connection"); //$NON-NLS-1$ // retry to connect to the site once, also set the timeout for 5 seconds HttpClientParams clientParams = client.getParams(); clientParams.setIntParameter(HttpClientParams.MAX_REDIRECTS, 1); clientParams.setSoTimeout(5 * ONE_SECOND); client.setParams(clientParams); client.executeMethod(getMethod); if (subMonitor.isCanceled()) { break; } else { AuthState authorizationState = getMethod.getHostAuthState(); String authenticationRealm = authorizationState.getRealm(); if (getMethod.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { StudioLogger.debug(HttpUtils.class, "Client requested authentication; retrieving credentials"); //$NON-NLS-1$ credentials = authenticationRealmCache.get(authenticationRealm); if (credentials == null) { StudioLogger.debug(HttpUtils.class, "Credentials not found; prompting user for login/password"); //$NON-NLS-1$ subMonitor.setTaskName(UtilitiesNLS.HttpUtils_MonitorTask_WaitingAuthentication); LoginPasswordDialogCreator dialogCreator = new LoginPasswordDialogCreator(url); if (dialogCreator.openLoginPasswordDialog() == LoginPasswordDialogCreator.OK) { credentials = new UsernamePasswordCredentials(dialogCreator.getTypedLogin(), dialogCreator.getTypedPassword()); } else { // cancel pressed; stop trying trying = false; // set the monitor canceled to be able to stop process subMonitor.setCanceled(true); } } if (credentials != null) { AuthScope scope = new AuthScope(null, -1, authenticationRealm); client.getState().setCredentials(scope, credentials); } subMonitor.worked(100); } else if (getMethod.getStatusCode() == HttpStatus.SC_OK) { StudioLogger.debug(HttpUtils.class, "Http connection suceeded"); //$NON-NLS-1$ subMonitor.setTaskName(UtilitiesNLS.HttpUtils_MonitorTask_RetrievingSiteContent); if ((authenticationRealm != null) && (credentials != null)) { authenticationRealmCache.put(authenticationRealm, credentials); } else { // no authentication was necessary, just work the monitor subMonitor.worked(100); } StudioLogger.info(HttpUtils.class, "Retrieving site content"); //$NON-NLS-1$ // if the stream should not be returned (ex: only testing the connection is // possible), then null will be returned if (returnStream) { streamForUrl = getMethod.getResponseBodyAsStream(); } // succeeded; stop trying trying = false; subMonitor.worked(100); } else { // unhandled return status code trying = false; subMonitor.worked(200); } } } while (trying); subMonitor.done(); return streamForUrl; }
From source file:es.juntadeandalucia.mapea.proxy.ProxyRedirect.java
/*************************************************************************** * Process the HTTP Get request/*from w w w.j a v a 2 s .co m*/ ***************************************************************************/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { String serverUrl = request.getParameter("url"); // manages a get request if it's the geoprint or getcapabilities operation boolean isGeoprint = serverUrl.toLowerCase().contains("mapeaop=geoprint"); boolean isGetCapabilities = serverUrl.toLowerCase().contains("getcapabilities"); boolean isGetFeatureInfo = serverUrl.toLowerCase().contains("wmsinfo"); if (isGeoprint || isGetCapabilities || isGetFeatureInfo) { String strErrorMessage = ""; serverUrl = checkTypeRequest(serverUrl); if (!serverUrl.equals("ERROR")) { // removes mapeaop parameter String url = serverUrl.replaceAll("\\&?\\??mapeaop=geoprint", ""); url = serverUrl.replaceAll("\\&?\\??mapeaop=getcapabilities", ""); url = serverUrl.replaceAll("\\&?\\??mapeaop=wmsinfo", ""); HttpClient client = new HttpClient(); GetMethod httpget = null; try { httpget = new GetMethod(url); HttpClientParams params = client.getParams(); params.setIntParameter(HttpClientParams.MAX_REDIRECTS, numMaxRedirects); client.executeMethod(httpget); // REDIRECTS MANAGEMENT if (httpget.getStatusCode() == HttpStatus.SC_OK) { // PATH_SECURITY_PROXY - AG Header[] respHeaders = httpget.getResponseHeaders(); int compSize = httpget.getResponseBody().length; ArrayList<Header> headerList = new ArrayList<Header>(Arrays.asList(respHeaders)); String headersString = headerList.toString(); boolean checkedContent = checkContent(headersString, compSize, serverUrl); // FIN_PATH_SECURITY_PROXY if (checkedContent) { if (request.getProtocol().compareTo("HTTP/1.0") == 0) { response.setHeader("Pragma", "no-cache"); } else if (request.getProtocol().compareTo("HTTP/1.1") == 0) { response.setHeader("Cache-Control", "no-cache"); } response.setDateHeader("Expires", -1); // set content-type headers if (isGeoprint) { response.setContentType("application/json"); } else if (isGetCapabilities) { response.setContentType("text/xml"); } /* * checks if it has requested an getfeatureinfo to modify the response content * type. */ String requesteredUrl = request.getParameter("url"); if (GETINFO_PLAIN_REGEX.matcher(requesteredUrl).matches()) { response.setContentType("text/plain"); } else if (GETINFO_GML_REGEX.matcher(requesteredUrl).matches()) { response.setContentType("application/gml+xml"); } else if (GETINFO_HTML_REGEX.matcher(requesteredUrl).matches()) { response.setContentType("text/html"); } InputStream st = httpget.getResponseBodyAsStream(); ServletOutputStream sos = response.getOutputStream(); IOUtils.copy(st, sos); } else { strErrorMessage += errorType; log.error(strErrorMessage); } } else { strErrorMessage = "Unexpected failure: " + httpget.getStatusLine().toString(); log.error(strErrorMessage); } httpget.releaseConnection(); } catch (Exception e) { log.error("Error al tratar el contenido de la peticion: " + e.getMessage(), e); } finally { if (httpget != null) { httpget.releaseConnection(); } } } else { // String errorXML = strErrorMessage; String errorXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><error><descripcion>Error en el parametro url de entrada</descripcion></error>"; response.setContentType("text/xml"); try { PrintWriter out = response.getWriter(); out.print(errorXML); response.flushBuffer(); } catch (Exception e) { log.error(e); } } } else { doPost(request, response); } }
From source file:com.google.enterprise.connector.sharepoint.wsclient.soap.SPClientFactory.java
private HttpClient createHttpClient(Credentials credentials) { HttpClient httpClientToUse = new HttpClient(); HttpClientParams params = httpClientToUse.getParams(); // Fix for the Issue[5408782] SharePoint connector fails to traverse a site, // circular redirect exception is observed. params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); // If ALLOW_CIRCULAR_REDIRECTS is set to true, HttpClient throws an // exception if a series of redirects includes the same resources more than // once. MAX_REDIRECTS allows you to specify a maximum number of redirects // to follow. params.setIntParameter(HttpClientParams.MAX_REDIRECTS, 10); params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, HTTP_CLIENT_TIMEOUT_SECONDS * 1000); params.setIntParameter(HttpClientParams.SO_TIMEOUT, HTTP_CLIENT_TIMEOUT_SECONDS * 1000); httpClientToUse.getState().setCredentials(AuthScope.ANY, credentials); return httpClientToUse; }
From source file:nu.validator.xml.PrudentHttpEntityResolver.java
/** * Sets the timeouts of the HTTP client. * /*from ww w. jav a 2s.c om*/ * @param connectionTimeout * timeout until connection established in milliseconds. Zero * means no timeout. * @param socketTimeout * timeout for waiting for data in milliseconds. Zero means no * timeout. */ public static void setParams(int connectionTimeout, int socketTimeout, int maxRequests) { HttpConnectionManagerParams hcmp = client.getHttpConnectionManager().getParams(); hcmp.setConnectionTimeout(connectionTimeout); hcmp.setSoTimeout(socketTimeout); hcmp.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxRequests); hcmp.setMaxTotalConnections(200); // XXX take this from a property PrudentHttpEntityResolver.maxRequests = maxRequests; HttpClientParams hcp = client.getParams(); hcp.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); hcp.setIntParameter(HttpClientParams.MAX_REDIRECTS, 20); // Gecko // default }
From source file:org.apache.abdera.protocol.client.AbderaClient.java
/** * Set the maximum number of redirects/*from www . ja va 2 s . c o m*/ */ public AbderaClient setMaximumRedirects(int redirects) { client.getParams().setIntParameter(HttpClientParams.MAX_REDIRECTS, redirects); return this; }
From source file:org.apache.abdera.protocol.client.AbderaClient.java
/** * Get the maximum number of redirects// w w w. j ava 2s .com */ public int getMaximumRedirects() { return client.getParams().getIntParameter(HttpClientParams.MAX_REDIRECTS, DEFAULT_MAX_REDIRECTS); }