List of usage examples for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT
String CONNECTION_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT.
Click Source Link
From source file:org.opencastproject.kernel.security.TrustedHttpClientImpl.java
@Override public HttpResponse execute(HttpUriRequest httpUriRequest, int connectionTimeout, int socketTimeout) throws TrustedHttpClientException { HttpClient httpClient = makeHttpClient(); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); // Add the request header to elicit a digest auth response httpUriRequest.setHeader(REQUESTED_AUTH_HEADER, DIGEST_AUTH); httpUriRequest.setHeader(SecurityConstants.AUTHORIZATION_HEADER, "true"); if (serviceRegistry != null && serviceRegistry.getCurrentJob() != null) httpUriRequest.setHeader(CURRENT_JOB_HEADER, Long.toString(serviceRegistry.getCurrentJob().getId())); // If a security service has been set, use it to pass the current security context on logger.debug("Adding security context to request"); Organization organization = securityService.getOrganization(); if (organization != null) { httpUriRequest.setHeader(SecurityConstants.ORGANIZATION_HEADER, organization.getId()); User currentUser = securityService.getUser(); if (currentUser != null) httpUriRequest.setHeader(SecurityConstants.USER_HEADER, currentUser.getUserName()); }/* ww w. j a v a 2 s.c om*/ if ("GET".equalsIgnoreCase(httpUriRequest.getMethod()) || "HEAD".equalsIgnoreCase(httpUriRequest.getMethod())) { // Set the user/pass UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); // Run the request (the http client handles the multiple back-and-forth requests) HttpResponse response = null; try { response = httpClient.execute(httpUriRequest); responseMap.put(response, httpClient); return response; } catch (IOException e) { // close the http connection(s) httpClient.getConnectionManager().shutdown(); throw new TrustedHttpClientException(e); } } // HttpClient doesn't handle the request dynamics for other verbs (especially when sending a streamed multipart // request), so we need to handle the details of the digest auth back-and-forth manually manuallyHandleDigestAuthentication(httpUriRequest, httpClient); HttpResponse response = null; try { response = httpClient.execute(httpUriRequest); if (nonceTimeoutRetries > 0 && hadNonceTimeoutResponse(response)) { httpClient.getConnectionManager().shutdown(); response = retryAuthAndRequestAfterNonceTimeout(httpUriRequest, response); } responseMap.put(response, httpClient); return response; } catch (Exception e) { // if we have a response, remove it from the map if (response != null) { responseMap.remove(response); } // close the http connection(s) httpClient.getConnectionManager().shutdown(); throw new TrustedHttpClientException(e); } }
From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java
private void setTimeouts(HttpClientParams params) { params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); }
From source file:org.talend.core.nexus.HttpClientTransport.java
public void doRequestOne(IProgressMonitor monitor, final URI requestURI) throws Exception { if (monitor == null) { monitor = new NullProgressMonitor(); }/*w ww . j a va 2 s . c o m*/ if (monitor.isCanceled()) { throw new OperationCanceledException(); } if (requestURI == null) { return; } DefaultHttpClient httpClient = new DefaultHttpClient(); IProxySelectorProvider proxySelectorProvider = null; try { if (StringUtils.isNotBlank(username)) { // set username httpClient.getCredentialsProvider().setCredentials( new AuthScope(requestURI.getHost(), requestURI.getPort()), new UsernamePasswordCredentials(username, password)); } int timeout = NexusServerUtils.getTimeout(); IDesignerCoreService designerCoreService = CoreRuntimePlugin.getInstance().getDesignerCoreService(); if (designerCoreService != null) { timeout = designerCoreService.getTACConnectionTimeout() * 1000; } HttpParams params = httpClient.getParams(); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); proxySelectorProvider = addProxy(httpClient, requestURI); HttpResponse response = execute(monitor, httpClient, requestURI); processResponseCode(response); } catch (org.apache.http.conn.HttpHostConnectException e) { // connection failure throw e; } catch (java.net.SocketTimeoutException e) { // Read timed out throw e; } catch (Exception e) { throw new Exception(requestURI.toString(), e); } finally { httpClient.getConnectionManager().shutdown(); removeProxy(proxySelectorProvider); } }