List of usage examples for org.apache.commons.httpclient.params DefaultHttpParams getDefaultParams
public static HttpParams getDefaultParams()
From source file:CustomAuthenticationExample.java
public static void main(String[] args) { // register the auth scheme AuthPolicy.registerAuthScheme(SecretAuthScheme.NAME, SecretAuthScheme.class); // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference, // this can be done on a per-client or per-method basis but we'll do it // globally for this example HttpParams params = DefaultHttpParams.getDefaultParams(); ArrayList schemes = new ArrayList(); schemes.add(SecretAuthScheme.NAME);/*from w w w.ja va 2 s .c om*/ schemes.addAll((Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY)); params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes); // now that our scheme has been registered we can execute methods against // servers that require "Secret" authentication... }
From source file:net.adamcin.httpsig.http.apache3.Http3Util.java
public static void enableAuth(HttpClient client, Keychain keychain, KeyId keyId) { Signer signer = new Signer(keychain, keyId); CredentialsProvider credProvider = (CredentialsProvider) client.getParams() .getParameter(CredentialsProvider.PROVIDER); CredentialsProvider newProvider;/*from w w w . j a v a 2 s . c o m*/ if (credProvider instanceof SignerCredentialsProvider) { newProvider = new SignerCredentialsProvider(signer, ((SignerCredentialsProvider) credProvider).getDelegatee()); } else { newProvider = new SignerCredentialsProvider(signer, credProvider); } client.getParams().setParameter(CredentialsProvider.PROVIDER, newProvider); AuthPolicy.registerAuthScheme(Constants.SCHEME, Http3SignatureAuthScheme.class); List<String> schemes = new ArrayList<String>(); schemes.add(Constants.SCHEME); Collection authSchemePriority = (Collection) DefaultHttpParams.getDefaultParams() .getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY); if (authSchemePriority != null) { schemes.addAll(authSchemePriority); } client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes); }
From source file:com.datatorrent.demos.samplestream.YahooFinanceCSVInputOperator.java
@Override public void setup(OperatorContext context) { url = prepareURL();/*from ww w.ja v a 2 s . c o m*/ client = new HttpClient(); method = new GetMethod(url); DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
/** * Initializes the http client with correct httpmethod. Adds Authorization header to request. * @param client/* w ww . ja v a 2s . c o m*/ * @param uri * @param methodType * @return */ protected HttpMethod getInitializedHttpMethod(HttpClient client, String uri, HttpMethodType methodType) { Calendar now = GregorianCalendar.getInstance(); _apiSession.setLastRequestDateTimeUtc(new Date(now.getTimeInMillis())); _apiSession.setHash(CryptographyHelper.computeHash(_apiSession, _sharedSecret)); String authHeader = AuthorizationHelper.toAuthorizationHeader(_apiSession); HttpMethod method; switch (methodType) { case GET: method = new GetMethod(uri); break; case PUT: method = new PutMethod(uri); method.setRequestHeader("Content-Type", "text/xml"); break; case POST: method = new PostMethod(uri); method.setRequestHeader("Content-Type", "text/xml"); break; case DELETE: method = new DeleteMethod(uri); break; default: method = new GetMethod(uri); } HttpParams params = DefaultHttpParams.getDefaultParams(); method.setRequestHeader("Authorization", authHeader); client.setParams((HttpClientParams) params); return method; }
From source file:org.glite.slcs.shibclient.TestShibbolethClient.java
/** * Sets the default CookiePolicy to use. Don't use it!!! * // w ww . j a v a 2 s .c o m * @param httpClient */ private static void setHttpClientCookiePolicy(HttpClient httpClient) { System.out.println("actual CookiePolicy= " + httpClient.getParams().getCookiePolicy()); // httpClient.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); DefaultHttpParams.getDefaultParams().setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); System.out.println("CookiePolicy= " + httpClient.getParams().getCookiePolicy()); }
From source file:org.lockss.plugin.silverchair.PostHttpClientUrlConnection.java
/** Called by org.lockss.config.MiscConfig *///from ww w . j a v a 2s .c o m public static void setConfig(Configuration config, Configuration oldConfig, Configuration.Differences diffs) { if (diffs.contains(PREFIX)) { acceptHeader = config.get(PARAM_ACCEPT_HEADER, DEFAULT_ACCEPT_HEADER); Set<String> set = new HashSet(); for (String s : (List<String>) config.getList(PARAM_SINGLE_VALUED_HEADERS, DEFAULT_SINGLE_VALUED_HEADERS)) { set.add(s.toLowerCase()); } singleValuedHdrs = set; HttpParams params = DefaultHttpParams.getDefaultParams(); if (diffs.contains(PARAM_COOKIE_POLICY)) { String policy = config.get(PARAM_COOKIE_POLICY, DEFAULT_COOKIE_POLICY); params.setParameter(HttpMethodParams.COOKIE_POLICY, getCookiePolicy(policy)); } if (diffs.contains(PARAM_SINGLE_COOKIE_HEADER)) { boolean val = config.getBoolean(PARAM_SINGLE_COOKIE_HEADER, DEFAULT_SINGLE_COOKIE_HEADER); params.setBooleanParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, val); } ServerTrustLevel stl = (ServerTrustLevel) config.getEnum(ServerTrustLevel.class, PARAM_SERVER_TRUST_LEVEL, DEFAULT_SERVER_TRUST_LEVEL); DISP_FACT.setDefaultFactory(getDefaultSocketFactory(stl)); } }
From source file:org.lockss.util.urlconn.HttpClientUrlConnection.java
/** Called by org.lockss.config.MiscConfig *//*from w ww .j a va 2 s . c o m*/ public static void setConfig(Configuration config, Configuration oldConfig, Configuration.Differences diffs) { if (diffs.contains(PREFIX)) { acceptHeader = config.get(PARAM_ACCEPT_HEADER, DEFAULT_ACCEPT_HEADER); HttpParams params = DefaultHttpParams.getDefaultParams(); if (diffs.contains(PARAM_COOKIE_POLICY)) { String policy = config.get(PARAM_COOKIE_POLICY, DEFAULT_COOKIE_POLICY); params.setParameter(HttpMethodParams.COOKIE_POLICY, getCookiePolicy(policy)); } if (diffs.contains(PARAM_SINGLE_COOKIE_HEADER)) { boolean val = config.getBoolean(PARAM_SINGLE_COOKIE_HEADER, DEFAULT_SINGLE_COOKIE_HEADER); params.setBooleanParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, val); } ServerTrustLevel stl = (ServerTrustLevel) config.getEnum(ServerTrustLevel.class, PARAM_SERVER_TRUST_LEVEL, DEFAULT_SERVER_TRUST_LEVEL); DISP_FACT.setDefaultFactory(getDefaultSocketFactory(stl)); } }
From source file:org.sakaiproject.nakamura.grouper.util.GrouperHttpUtil.java
/** * Construct an {@link HttpClient} which is configured to authenticate to Nakamura. * @return the configured client.// w w w . ja v a 2 s .co m */ public static HttpClient getHttpClient(GrouperConfiguration grouperConfiguration) { HttpClient client = new HttpClient(); DefaultHttpParams.getDefaultParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); HttpState state = client.getState(); state.setCredentials( new AuthScope(grouperConfiguration.getUrl().getHost(), getPort(grouperConfiguration.getUrl())), new UsernamePasswordCredentials(grouperConfiguration.getUsername(), grouperConfiguration.getPassword())); client.getParams().setAuthenticationPreemptive(true); client.getParams().setSoTimeout(grouperConfiguration.getHttpTimeout()); return client; }