List of usage examples for org.apache.http.protocol HttpContext getAttribute
Object getAttribute(String str);
From source file:org.eclipse.mylyn.commons.repositories.http.core.HttpUtil.java
public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host, final HttpContext context, final HttpRequestBase method, final IProgressMonitor progress) throws IOException { Assert.isNotNull(client);//from w w w . j a v a2 s .com Assert.isNotNull(method); final IOperationMonitor monitor = OperationUtil.convert(progress); ICancellableOperation operation = new ICancellableOperation() { @Override public void abort() { method.abort(); } @Override public boolean isCanceled() { return monitor.isCanceled(); } }; CancellableOperationMonitorThread thread = null; if (context != null) { thread = (CancellableOperationMonitorThread) context.getAttribute(CONTEXT_KEY_MONITOR_THREAD); } if (thread != null) { thread.addOperation(operation); } try { return client.execute(host, method, context); } catch (InterruptedIOException e) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } throw e; } finally { if (thread != null) { thread.removeOperation(operation); } } }
From source file:se.vgregion.pubsub.twitter.impl.PreemptiveBasicAuth.java
public void process(HttpRequest request, HttpContext context) { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // If not auth scheme has been initialized yet if (authState.getAuthScheme() == null) { Credentials creds = new UsernamePasswordCredentials(username, password); authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }// w w w .j a v a 2s .co m }
From source file:com.normalexception.app.rx8club.html.HtmlFormUtils.java
/** * Submit a form and its contents//from w ww . j av a2s .c o m * @param url The url to submit the form to * @param nvps The name value pair of the contents * @param attachment If true, add attachment headers * @return True if it worked * @throws ClientProtocolExecption * @throws IOException */ private static boolean formSubmit(String url, List<NameValuePair> nvps, boolean attachment) throws ClientProtocolException, IOException { HttpClient httpclient = LoginFactory.getInstance().getClient(); HttpPost httpost = ClientUtils.getHttpPost(url); Log.d(TAG, "[Submit] Submit URL: " + url); // If there is an attachment, we need to add some data // to the post header if (attachment) { String pN = ""; for (NameValuePair nvp : nvps) { if (nvp.getName().equals(VBulletinKeys.PostNumber.getValue())) { pN = nvp.getValue(); break; } } httpost.setHeader("Content-Type", "application/x-www-form-urlencoded"); httpost.setHeader("Referer", WebUrls.postSubmitAddress + pN); } httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpContext context = LoginFactory.getInstance().getHttpContext(); HttpResponse response = httpclient.execute(httpost, context); HttpEntity entity = response.getEntity(); StatusLine statusLine = response.getStatusLine(); Log.d(TAG, "[Submit] Status: " + statusLine.getStatusCode()); if (entity != null) { responseContent = EntityUtils.toString(entity, "UTF-8"); //httpost.releaseConnection(); HttpUriRequest request = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST); responseUrl = request.getURI().toString(); Log.d(TAG, "[Submit] Response URL: " + responseUrl); return true; } return false; }
From source file:com.liferay.portal.search.solr.interceptor.PreemptiveAuthInterceptor.java
@Override public void process(HttpRequest request, HttpContext httpContext) { AuthState authState = (AuthState) httpContext.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() != null) { return;// w w w. j a v a2s . c om } CredentialsProvider credentialsProvider = (CredentialsProvider) httpContext .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHttpHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); AuthScope authScope = new AuthScope(targetHttpHost.getHostName(), targetHttpHost.getPort()); Credentials credentials = credentialsProvider.getCredentials(authScope); if (credentials != null) { authState.update(new BasicScheme(), credentials); } }
From source file:at.bitfire.davdroid.webdav.PreemptiveAuthInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }/*from w ww . j a v a 2 s . c om*/ } }
From source file:kuona.client.PreemptiveAuth.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authScheme != null) { Credentials creds = credsProvider .getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials for preemptive authentication"); }/* w ww . j av a 2 s .com*/ authState.update(authScheme, creds); } } }
From source file:ch.bfh.abcvote.util.helpers.SocksConnectionSocketFactory.java
/** * ConnectionSocketFactory needed for Socks Proxy * @param context the http context/* w w w .j a v a2 s . c o m*/ * @return returns a proxy socket */ public Socket createSocket(final HttpContext context) { InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address"); Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); return new Socket(proxy); }
From source file:com.serphacker.serposcope.scraper.http.extensions.ScrapClientPlainConnectionFactory.java
@Override public Socket createSocket(final HttpContext context) throws IOException { InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("proxy.socks"); if (socksaddr != null) { return new Socket(new Proxy(Proxy.Type.SOCKS, socksaddr)); } else {// www . j a v a 2s.co m return new Socket(); } }
From source file:dtu.ds.warnme.app.ws.client.https.ssl.PreemptiveAuthenticationRequestInterceptor.java
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }/* w w w . j a va 2 s . c om*/ } }
From source file:org.apache.camel.component.http4.PreemptiveAuthInterceptor.java
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); // If no auth scheme avaialble yet, try to initialize it preemptively if (authState.getAuthScheme() == null) { AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(HttpClientContext.CREDS_PROVIDER); if (authScheme != null) { Credentials creds = credsProvider.getCredentials(AuthScope.ANY); if (creds == null) { throw new HttpException("No credentials for preemptive authentication"); }/*from www . ja v a 2s . co m*/ authState.update(authScheme, creds); } } }