本文整理汇总了Java中org.apache.commons.httpclient.params.HttpParams类的典型用法代码示例。如果您正苦于以下问题:Java HttpParams类的具体用法?Java HttpParams怎么用?Java HttpParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpParams类属于org.apache.commons.httpclient.params包,在下文中一共展示了HttpParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultParams
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
@Override
public HttpParams getDefaultParams()
{
if (httpParams == null)
{
synchronized (this)
{
if (httpParams == null)
{
httpParams = createParams();
}
}
}
return httpParams;
}
示例2: getParameter
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
@Override
public Object getParameter(final String name)
{
// See if the parameter has been explicitly defined
Object param = null;
paramLock.readLock().lock();
try
{
param = this.parameters.get(name);
}
finally
{
paramLock.readLock().unlock();
}
if (param == null)
{
// If not, see if defaults are available
HttpParams defaults = getDefaults();
if (defaults != null)
{
// Return default parameter value
param = defaults.getParameter(name);
}
}
return param;
}
示例3: main
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
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);
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...
}
示例4: testChallengeSelection
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public void testChallengeSelection() throws Exception {
List authPrefs = new ArrayList(3);
authPrefs.add(AuthPolicy.NTLM);
authPrefs.add(AuthPolicy.DIGEST);
authPrefs.add(AuthPolicy.BASIC);
HttpParams httpparams = new DefaultHttpParams();
httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
Map map = new HashMap();
map.put("unknown", "unknown realm=\"whatever\"");
map.put("basic", "basic realm=\"whatever\"");
AuthScheme authscheme = processor.selectAuthScheme(map);
assertTrue(authscheme instanceof BasicScheme);
}
示例5: testInvalidChallenge
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public void testInvalidChallenge() throws Exception {
List authPrefs = new ArrayList(3);
authPrefs.add("unsupported1");
authPrefs.add("unsupported2");
HttpParams httpparams = new DefaultHttpParams();
httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
Map map = new HashMap();
map.put("unsupported1", "unsupported1 realm=\"whatever\"");
map.put("unsupported2", "unsupported2 realm=\"whatever\"");
try {
AuthScheme authscheme = processor.selectAuthScheme(map);
fail("AuthChallengeException should have been thrown");
} catch (AuthChallengeException e) {
//ignore
}
}
示例6: testUnsupportedChallenge
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public void testUnsupportedChallenge() throws Exception {
List authPrefs = new ArrayList(3);
authPrefs.add(AuthPolicy.NTLM);
authPrefs.add(AuthPolicy.BASIC);
authPrefs.add(AuthPolicy.DIGEST);
HttpParams httpparams = new DefaultHttpParams();
httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
Map map = new HashMap();
map.put("unsupported1", "unsupported1 realm=\"whatever\"");
map.put("unsupported2", "unsupported2 realm=\"whatever\"");
try {
AuthScheme authscheme = processor.selectAuthScheme(map);
fail("AuthChallengeException should have been thrown");
} catch (AuthChallengeException e) {
//expected
}
}
示例7: testInvalidChallengeProcessing
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public void testInvalidChallengeProcessing() throws Exception {
HttpParams httpparams = new DefaultHttpParams();
AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
Map map = new HashMap();
map.put("basic", "basic realm=\"whatever\", param=\"value\"");
AuthState authstate = new AuthState();
AuthScheme authscheme = processor.processChallenge(authstate, map);
assertTrue(authscheme instanceof BasicScheme);
assertEquals("whatever", authscheme.getRealm());
assertEquals(authscheme, authstate.getAuthScheme());
assertEquals("value", authscheme.getParameter("param"));
Map map2 = new HashMap();
map2.put("ntlm", "NTLM");
try {
// Basic authentication scheme expected
authscheme = processor.processChallenge(authstate, map2);
fail("AuthenticationException should have been thrown");
} catch (AuthenticationException e) {
//expected
}
}
示例8: setParameter
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public static void setParameter(HttpParams params, String paramName, String paramValue) {
Class<?> paramType = getParameterType(paramName);
if (paramType.equals(Boolean.class)) {
params.setBooleanParameter(paramName, Boolean.parseBoolean(paramValue));
} else if (paramType.equals(Integer.class)) {
params.setIntParameter(paramName, Integer.parseInt(paramValue));
} else if (paramType.equals(Long.class)) {
params.setLongParameter(paramName, Long.parseLong(paramValue));
} else if (paramType.equals(Double.class)) {
params.setDoubleParameter(paramName, Double.parseDouble(paramValue));
} else if (paramType.equals(String.class)) {
params.setParameter(paramName, paramValue);
} else if (paramType.equals(Class.class)) {
try {
Class<?> configuredClass = Class.forName(paramValue, true, ClassLoaderUtils.getDefaultClassLoader());
params.setParameter(paramName, configuredClass);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not locate the class needed to configure the HttpClient.", e);
}
} else {
throw new RuntimeException("Attempted to configure an HttpClient parameter '" + paramName + "' " +
"of a type not supported through Workflow configuration: " + paramType.getName());
}
}
示例9: configureDefaultHttpClientParams
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
protected void configureDefaultHttpClientParams(HttpParams params) {
params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS, MultiThreadedHttpConnectionManager.class);
params.setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109);
params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 10000);
Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(20));
params.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap);
params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 20);
params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 2*60*1000);
boolean retrySocketException = new Boolean(ConfigContext.getCurrentContextConfig().getProperty(RETRY_SOCKET_EXCEPTION_PROPERTY));
if (retrySocketException) {
LOG.info("Installing custom HTTP retry handler to retry requests in face of SocketExceptions");
params.setParameter(HttpMethodParams.RETRY_HANDLER, new CustomHttpMethodRetryHandler());
}
}
示例10: AuthChallengeProcessor
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
/**
* Creates an authentication challenge processor with the given {@link HttpParams HTTP
* parameters}
*
* @param params the {@link HttpParams HTTP parameters} used by this processor
*/
public AuthChallengeProcessor(final HttpParams params) {
super();
if (params == null) {
throw new IllegalArgumentException("Parameter collection may not be null");
}
this.params = params;
}
示例11: promptForCredentials
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
private Credentials promptForCredentials(
final AuthScheme authScheme,
final HttpParams params,
final AuthScope authscope)
{
LOG.debug("Credentials required");
Credentials creds = null;
CredentialsProvider credProvider =
(CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
if (credProvider != null) {
try {
creds = credProvider.getCredentials(
authScheme, authscope.getHost(), authscope.getPort(), false);
} catch (CredentialsNotAvailableException e) {
LOG.warn(e.getMessage());
}
if (creds != null) {
this.state.setCredentials(authscope, creds);
if (LOG.isDebugEnabled()) {
LOG.debug(authscope + " new credentials given");
}
}
} else {
LOG.debug("Credentials provider not available");
}
return creds;
}
示例12: promptForProxyCredentials
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
private Credentials promptForProxyCredentials(
final AuthScheme authScheme,
final HttpParams params,
final AuthScope authscope)
{
LOG.debug("Proxy credentials required");
Credentials creds = null;
CredentialsProvider credProvider =
(CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
if (credProvider != null) {
try {
creds = credProvider.getCredentials(
authScheme, authscope.getHost(), authscope.getPort(), true);
} catch (CredentialsNotAvailableException e) {
LOG.warn(e.getMessage());
}
if (creds != null) {
this.state.setProxyCredentials(authscope, creds);
if (LOG.isDebugEnabled()) {
LOG.debug(authscope + " new credentials given");
}
}
} else {
LOG.debug("Proxy credentials provider not available");
}
return creds;
}
示例13: checkDate
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
private void checkDate(String date) throws Exception {
Header header = new Header("Set-Cookie", "custno=12345;Expires='"+date+"';");
HttpParams params = new DefaultHttpParamsFactory().getDefaultParams();
CookieSpec cookiespec = new CookieSpecBase();
cookiespec.setValidDateFormats(
(Collection)params.getParameter(HttpMethodParams.DATE_PATTERNS));
cookieParse(cookiespec, "localhost", 80, "/", false, header);
}
示例14: testChallengeProcessing
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public void testChallengeProcessing() throws Exception {
HttpParams httpparams = new DefaultHttpParams();
AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
Map map = new HashMap();
map.put("basic", "basic realm=\"whatever\", param=\"value\"");
AuthState authstate = new AuthState();
AuthScheme authscheme = processor.processChallenge(authstate, map);
assertTrue(authscheme instanceof BasicScheme);
assertEquals("whatever", authscheme.getRealm());
assertEquals(authscheme, authstate.getAuthScheme());
assertEquals("value", authscheme.getParameter("param"));
}
示例15: main
import org.apache.commons.httpclient.params.HttpParams; //导入依赖的package包/类
public static void main(String[] args) {
// register the auth scheme
AuthPolicy.registerAuthScheme("Negotiate", NegotiateScheme.class);
// include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference
ArrayList schemes = new ArrayList();
schemes.add("Negotiate");
HttpParams params = DefaultHttpParams.getDefaultParams();
params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
// now that our scheme has been registered we can execute methods against
// servers that require "Negotiate" authentication...
HttpClient client = new HttpClient();
// The Negotiate scheme uses JAAS as credential provider but the
// httpclient api require us to supply cred anyway.
// a work around is to provide an empty set of creds.
Credentials use_jaas_creds = new Credentials() {};
client.getState().setCredentials(
new AuthScope(null, -1, null),
use_jaas_creds);
GetMethod httpget = new GetMethod(args[0]);
try {
client.executeMethod(httpget);
//System.out.println(httpget.getStatusLine());
//System.out.println(httpget.getResponseBodyAsString());
} catch (Exception e) {
e.printStackTrace();
} finally {
// release any connection resources used by the method
httpget.releaseConnection();
}
}