Example usage for org.apache.http.protocol BasicHttpContext BasicHttpContext

List of usage examples for org.apache.http.protocol BasicHttpContext BasicHttpContext

Introduction

In this page you can find the example usage for org.apache.http.protocol BasicHttpContext BasicHttpContext.

Prototype

public BasicHttpContext() 

Source Link

Usage

From source file:org.cee.net.impl.HttpWebResponse.java

private void executeRequest() throws IOException {
    HttpGet httpGet = new HttpGet(getUrlWithoutHash(originalLocation));
    HttpContext context = new BasicHttpContext();
    HttpResponse response = httpClient.execute(httpGet, context);
    entity = response.getEntity();//www  . ja  v a2  s.  com
    if (entity == null) {
        throw new IOException("No entity received for " + originalLocation.toExternalForm());
    }
    URL redirectUrl = (URL) context.getAttribute(HttpClientFactory.LAST_REDIRECT_URL);
    if (redirectUrl != null) {
        location = redirectUrl;
    }
}

From source file:gmusic.api.comm.ApacheConnector.java

public ApacheConnector() {
    HttpParams params = new BasicHttpParams();
    params.removeParameter("User-Agent");
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
    // HttpConnectionParams.setConnectionTimeout(params, 150000);
    // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis);
    httpClient = new DefaultHttpClient(params);
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:net.zorgblub.typhon.sync.TyphonWebProgressService.java

@Inject
public TyphonWebProgressService(Context context, Configuration config, HttpClient client) {
    this.httpContext = new BasicHttpContext();
    this.config = config;
    this.client = client;

    this.dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    // explicitly set timezone of input if needed
    dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("Zulu"));
}

From source file:gmusic.api.api.comm.ApacheConnector.java

public ApacheConnector() {
    final HttpParams params = new BasicHttpParams();
    params.removeParameter("User-Agent");
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
    // HttpConnectionParams.setConnectionTimeout(params, 150000);
    // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis);
    httpClient = new DefaultHttpClient(params);
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:org.eclipse.lyo.rio.trs.tests.ChangeLogCreationTest.java

@BeforeClass
public static void setupOnce() {
    try {//ww  w .jav a2s. c o  m
        prop = getConfigPropertiesInstance();
        String resCreationFactoryUri = prop.getProperty("configResourceCreationFactoryUri");
        String resCreationContent = (prop.getProperty("configResContentFile").equals("")
                ? prop.getProperty("configResContent")
                : readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResContentFile"))));
        String resContentType = prop.getProperty("configContentType");
        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();
        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));

        //Create a resource using the resource creation factory.. oslc:CreationFactory
        createdResourceUrl = SendUtil.createResource(resCreationFactoryUri, httpClient, httpContext,
                resContentType, resCreationContent);

        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (SendException e) {
        terminateTest(Messages.getServerString("tests.general.trs.send.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:org.etk.common.net.ETKHttpClient.java

public HttpEntity execute(String targetURL) throws ClientProtocolException, IOException {
    HttpHost targetHost = new HttpHost("127.0.0.1", 8080, "http");

    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials("demo", "gtn"));

    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);

    // Add AuthCache to the execution context
    BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

    HttpGet httpget = new HttpGet(targetURL);
    Header header = new BasicHeader("Content-Type", "application/json");
    httpget.setHeader(header);//from  w ww. j  av a 2  s.  c om
    HttpResponse response = httpClient.execute(targetHost, httpget, localcontext);
    DumpHttpResponse.dumpHeader(response);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        entity = new BufferedHttpEntity(entity);
    }
    EntityUtils.consume(entity);

    return entity;
}

From source file:org.eclipse.lyo.oslc4j.bugzilla.utils.BugzillaHttpClient.java

public BugzillaHttpClient(String rootURL, Credentials credentials) throws UnsupportedEncodingException {
    this.rootURL = rootURL;

    authorization = "&Bugzilla_login=" + URLEncoder.encode(credentials.getUsername(), "UTF-8")
            + "&Bugzilla_password=" + URLEncoder.encode(credentials.getPassword(), "UTF-8");

    httpClient = getHttpClient();/*  w w  w .  ja  v  a 2  s  .c om*/

    cntxt = new BasicHttpContext();
}

From source file:de.tsystems.mms.apm.performancesignature.viewer.rest.model.CustomJenkinsHttpClient.java

public CustomJenkinsHttpClient(final URI uri, final String username, final String password,
        final boolean verifyCertificate, final CustomProxy customProxy) {

    super(uri, addAuthentication(createHttpClientBuilder(verifyCertificate, customProxy), uri, username,
            password));//  w w w. java  2  s . c o  m
    if (StringUtils.isNotBlank(username)) {
        BasicHttpContext httpContext = new BasicHttpContext();
        httpContext.setAttribute("preemptive-auth", new BasicScheme());
        super.setLocalContext(httpContext);
    }
}

From source file:com.subgraph.vega.internal.http.proxy.ConnectionTask.java

private void processingLoop() throws IOException, HttpException {
    while (!Thread.interrupted() && connection.isOpen()) {
        HttpContext ctx = new BasicHttpContext();
        httpService.handleRequest(connection, ctx);
        processRequestContext(ctx);// ww w .  j a  v  a2 s  .  c  o m
    }
}

From source file:mobi.jenkinsci.ci.client.JenkinsHttpClient.java

public JenkinsHttpClient(final JenkinsConfig config) throws MalformedURLException {
    this.config = config;
    if (config.getUsername() == null) {
        httpClient = httpClientFactory.getHttpClient();
    } else {//from ww  w  .java2s  .c om
        final URL url = new URL(config.getUrl());
        httpClient = httpClientFactory.getBasicAuthHttpClient(url, config.getUsername(), config.getPassword());

        final AuthCache authCache = new BasicAuthCache();
        final BasicScheme basicAuth = new BasicScheme();
        authCache.put(new HttpHost(url.getHost(), url.getPort()), basicAuth);

        httpContext = new BasicHttpContext();
        httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
}