Example usage for org.apache.commons.httpclient.params HttpClientParams HttpClientParams

List of usage examples for org.apache.commons.httpclient.params HttpClientParams HttpClientParams

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpClientParams HttpClientParams.

Prototype

public HttpClientParams() 

Source Link

Usage

From source file:org.archive.wayback.liveweb.StdRemoteLiveWebCache.java

/**
 * StdRemoteLiveWebCache constructor initializes and configures connection objects.
 *///from   ww  w.j a  va  2 s  . c  o  m
public StdRemoteLiveWebCache() {
    connectionManager = new MultiThreadedHttpConnectionManager();
    hostConfiguration = new HostConfiguration();
    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler());
    httpClient = new HttpClient(params, connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}

From source file:org.archive.wayback.resourceindex.ziplines.Http11BlockLoader.java

/**
 * //from  ww  w .  ja  va  2s  .c om
 */
public Http11BlockLoader() {
    connectionManager = new MultiThreadedHttpConnectionManager();
    hostConfiguration = new HostConfiguration();
    HttpClientParams params = new HttpClientParams();
    //        params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler());
    http = new HttpClient(params, connectionManager);
    http.setHostConfiguration(hostConfiguration);
}

From source file:org.aselect.server.request.handler.xsaml20.ProxyHTTPMetadataProvider.java

/**
 * The Constructor./*from  w  w w  . ja va 2 s . com*/
 * 
 * @param metadataURL
 *            the metadata url
 * @param requestTimeout
 *            the request timeout
 * @param proxyHost
 *            the proxy host
 * @param proxyPort
 *            the proxy port
 * @throws MetadataProviderException
 *             the metadata provider exception
 */
public ProxyHTTPMetadataProvider(String metadataURL, int requestTimeout, String proxyHost, int proxyPort)
        throws MetadataProviderException {

    super(metadataURL, requestTimeout);

    _systemLogger = ASelectSystemLogger.getHandle();
    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(requestTimeout);
    proxyhttpClient = new HttpClient(clientParams);
    proxyhttpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
    URI l_metadataURI;
    try {
        l_metadataURI = new URI(getMetadataURI());
    } catch (URISyntaxException e) {
        throw new MetadataProviderException("Illegal URL syntax", e);
    }

    proxyauthScope = new AuthScope(l_metadataURI.getHost(), l_metadataURI.getPort());

    // commons-http-client >= 4.0 might use:
    // ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
    // httpclient.getConnectionManager().getSchemeRegistry(),
    // ProxySelector.getDefault());
    // httpclient.setRoutePlanner(routePlanner);

    // or:
    // HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    // getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

}

From source file:org.atricore.idbus.kernel.main.mediation.camel.component.http.IDBusHttpComponent.java

@Override
protected Endpoint<HttpExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
    uri = uri.startsWith("idbus-http:") ? remaining : uri;

    HttpClientParams params = new HttpClientParams();
    IntrospectionSupport.setProperties(params, parameters, "httpClient.");

    configureParameters(parameters);/*  www  . java2 s  .c  o  m*/

    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    URI httpUri = URISupport.createRemainingURI(new URI(uri), parameters);
    uri = httpUri.toString();

    IDBusHttpEndpoint endpoint = new IDBusHttpEndpoint(this, uri, httpUri, params, getHttpConnectionManager(),
            httpClientConfigurer);
    if (httpBinding != null) {
        endpoint.setBinding(httpBinding);
    }
    setProperties(endpoint, parameters);
    return endpoint;
}

From source file:org.bibsonomy.rest.client.worker.HttpWorker.java

/**
 * @param username the username// w  w  w.ja  v  a 2  s.  co m
 * @param apiKey the apikey
 */
public HttpWorker(final String username, final String apiKey) {
    this.username = username;
    this.apiKey = apiKey;

    this.httpClient = new HttpClient();
    final HttpClientParams httpClientParams = new HttpClientParams();
    final DefaultHttpMethodRetryHandler defaultHttpMethodRetryHandler = new DefaultHttpMethodRetryHandler(0,
            false);
    httpClientParams.setParameter(HeaderUtils.HEADER_USER_AGENT,
            USER_AGENT_VALUE + "_" + RestClientUtils.getRestClientVersion());
    httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, defaultHttpMethodRetryHandler);
    httpClientParams.setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, RestClientUtils.CONTENT_CHARSET);
    httpClientParams.setAuthenticationPreemptive(true);

    this.httpClient.setParams(httpClientParams);
}

From source file:org.cloudfoundry.identity.uaa.provider.saml.FixedHttpMetaDataProviderTest.java

public void setUp(String url, RestTemplate template) throws Exception {
    params = new HttpClientParams();
    params.setSoTimeout(1000);//from w  w w  .j a v a 2  s. com
    params.setConnectionManagerTimeout(1000);
    fixedHttpMetaDataProvider = FixedHttpMetaDataProvider.buildProvider(dummyTimer, params, url, template);
    fixedHttpMetaDataProvider.setExpirationTimeMillis(100);
    fixedHttpMetaDataProvider.setTicker(ticker);
}

From source file:org.cloudfoundry.identity.uaa.provider.saml.IdentityProviderConfiguratorTests.java

@Test
public void testGetIdentityProviders() throws Exception {
    conf.setClientParams(new HttpClientParams());
    testGetIdentityProviderDefinitions(3);
    conf.getSamlIdentityProviders();/*  w w w . j  a  va2 s  .c  o m*/
}

From source file:org.craftercms.cstudio.loadtesting.actions.BaseAction.java

public int runAction(HttpClient httpClient, HttpMethodBase method, String username) throws Exception {
    HttpClientParams params = new HttpClientParams();
    params.setSoTimeout(0);/* w w w. j a va2s . c o  m*/
    httpClient.setParams(params);
    if (username != null) {
        method.addRequestHeader("cookie", "username=" + username);
    }
    return httpClient.executeMethod(method);
}

From source file:org.dawnsci.usagedata.internal.recording.uploading.BasicUploader.java

/**
 * This method does the heavy lifting when it comes to downloads.
 * /*w ww  . j  a v  a2 s  .  c  o m*/
 * I can envision a time when we may want to upload something other than files.
 * We may, for example, want to upload an in-memory representation of the files.
 * For now, in the spirit of having something that works is better than
 * overengineering something you may not need, we're just dealing with files.
 * 
 * @param monitor
 *            an instance of something that implements
 *            {@link IProgressMonitor}. Must not be <code>null</code>.
 * @throws Exception 
 */
UploadResult doUpload(IProgressMonitor monitor) throws Exception {
    monitor.beginTask("Upload", getUploadParameters().getFiles().length + 3); //$NON-NLS-1$
    /*
     * The files that we have been provided with were determined while the recorder
     * was suspended. We should be safe to work with these files without worrying
     * that other threads are messing with them. We do need to consider that other
     * processes running outside of our JVM may be messing with these files and
     * anticipate errors accordingly.
     */

    // TODO Does it make sense to create a custom exception for this?
    if (!hasUserAuthorizedUpload())
        throw new Exception("User has not authorized upload."); //$NON-NLS-1$

    /*
     * There appears to be some mechanism on some versions of HttpClient that
     * allows the insertion of compression technology. For now, we don't worry
     * about compressing our output; we can worry about that later.
     */
    PostMethod post = new PostMethod(getSettings().getUploadUrl());

    post.setRequestHeader(HTTP_USERID, getSettings().getUserId());
    post.setRequestHeader(HTTP_WORKSPACEID, getSettings().getWorkspaceId());
    post.setRequestHeader(HTTP_TIME, String.valueOf(System.currentTimeMillis()));
    post.setRequestHeader(USER_AGENT, getSettings().getUserAgent());

    boolean loggingServerActivity = getSettings().isLoggingServerActivity();
    if (loggingServerActivity) {
        post.setRequestHeader("LOGGING", "true"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    post.setRequestEntity(new MultipartRequestEntity(getFileParts(monitor), post.getParams()));

    // Configure the HttpClient to timeout after one minute.
    HttpClientParams httpParameters = new HttpClientParams();
    httpParameters.setSoTimeout(getSocketTimeout()); // "So" means "socket"; who knew?

    monitor.worked(1);

    int result = new HttpClient(httpParameters).executeMethod(post);

    handleServerResponse(post);

    monitor.worked(1);

    post.releaseConnection();

    // Check the result. HTTP return code of 200 means success.
    if (result == 200) {
        for (File file : getUploadParameters().getFiles()) {
            // TODO what if file delete fails?
            if (file.exists())
                file.delete();
        }
    }

    monitor.worked(1);

    monitor.done();

    return new UploadResult(result);
}

From source file:org.devproof.portal.module.bookmark.service.SynchronizeServiceImpl.java

@Override
public DeliciousBean getDataFromDelicious(String username, String password, String tags) {
    logger.debug("Retrieve data from delicious");
    HttpClient httpClient = new HttpClient();
    HttpClientParams httpClientParams = new HttpClientParams();
    DefaultHttpMethodRetryHandler defaultHttpMethodRetryHandler = new DefaultHttpMethodRetryHandler(0, false);
    httpClientParams.setParameter("User-Agent", BookmarkConstants.USER_AGENT);
    httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, defaultHttpMethodRetryHandler);
    httpClient.setParams(httpClientParams);
    httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    String urlTag = "";
    if (StringUtils.isNotEmpty(tags)) {
        urlTag = "tag=" + tags;
    }//w ww  .j  av  a  2s .  c o  m
    HttpMethod method = new GetMethod(BookmarkConstants.DELICIOUS_API + urlTag);
    method.setDoAuthentication(true);
    DeliciousBean bean = new DeliciousBean();
    try {
        int httpCode = httpClient.executeMethod(method);
        bean.setHttpCode(httpCode);
        if (!bean.hasError()) {
            XStream xstream = new XStream(new DomDriver());
            xstream.alias("posts", DeliciousBean.class);
            xstream.alias("post", DeliciousPostBean.class);
            xstream.addImplicitCollection(DeliciousBean.class, "posts");
            xstream.useAttributeFor(String.class);
            xstream.useAttributeFor(Integer.class);
            bean = (DeliciousBean) xstream.fromXML(method.getResponseBodyAsStream());
            bean.setHttpCode(httpCode);
        } else {
            bean.setErrorMessage("Unknown Error: Http Status: " + httpCode);
        }
    } catch (HttpException e) {
        bean.setErrorMessage(e.getMessage());
    } catch (IOException e) {
        bean.setErrorMessage(e.getMessage());
    }
    method.releaseConnection();
    return bean;
}