当前位置: 首页>>代码示例>>Java>>正文


Java HttpParams.setParameter方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.params.HttpParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java HttpParams.setParameter方法的具体用法?Java HttpParams.setParameter怎么用?Java HttpParams.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.params.HttpParams的用法示例。


在下文中一共展示了HttpParams.setParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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... 
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:CustomAuthenticationExample.java

示例2: 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);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:TestChallengeProcessor.java

示例3: 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
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestChallengeProcessor.java

示例4: 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
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:22,代码来源:TestChallengeProcessor.java

示例5: 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());
	}
}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:25,代码来源:HttpClientHelper.java

示例6: 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());
	}

	
}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:21,代码来源:HttpInvokerConnector.java

示例7: 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();
    }            
    
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:CustomAuthenticationNegotiateExample.java

示例8: executeMethod

import org.apache.commons.httpclient.params.HttpParams; //导入方法依赖的package包/类
/**
     * Requests the received method.
     *
     * Executes the method through the inherited HttpClient.executedMethod(method).
     *
     * @param method                HTTP method request.
     */
    @Override
    public int executeMethod(HttpMethod method) throws IOException {
        try {
            // Update User Agent
            HttpParams params = method.getParams();
            String userAgent = OwnCloudClientManagerFactory.getUserAgent();
            params.setParameter(HttpMethodParams.USER_AGENT, userAgent);

            Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
                    method.getName() + " " + method.getPath());

//	        logCookiesAtRequest(method.getRequestHeaders(), "before");
//	        logCookiesAtState("before");
            method.setFollowRedirects(false);

            int status = super.executeMethod(method);

            if (mFollowRedirects) {
                status = followRedirection(method).getLastStatus();
            }

//	        logCookiesAtRequest(method.getRequestHeaders(), "after");
//	        logCookiesAtState("after");
//	        logSetCookiesAtResponse(method.getResponseHeaders());

            return status;

        } catch (IOException e) {
            //Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occurred", e);
            throw e;
        }
    }
 
开发者ID:PicFrame,项目名称:picframe,代码行数:40,代码来源:OwnCloudClient.java


注:本文中的org.apache.commons.httpclient.params.HttpParams.setParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。