Java 类org.apache.commons.httpclient.params.DefaultHttpParams 实例源码

项目:lib-commons-httpclient    文件: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);
    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... 
}
项目:lib-commons-httpclient    文件:TestChallengeProcessor.java   
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);
}
项目:lib-commons-httpclient    文件:TestChallengeProcessor.java   
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
    }
}
项目:lib-commons-httpclient    文件:TestChallengeProcessor.java   
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
    }
}
项目:lib-commons-httpclient    文件:TestChallengeProcessor.java   
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
    }
}
项目:httpclient3-ntml    文件: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);
    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... 
}
项目:httpclient3-ntml    文件:TestChallengeProcessor.java   
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);
}
项目:httpclient3-ntml    文件:TestChallengeProcessor.java   
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
    }
}
项目:httpclient3-ntml    文件:TestChallengeProcessor.java   
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
    }
}
项目:httpclient3-ntml    文件:TestChallengeProcessor.java   
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
    }
}
项目:httpsig-java    文件: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;
    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);
}
项目:alfresco-core    文件:HttpClientFactory.java   
public void init()
{
    this.sslKeyStore = new AlfrescoKeyStoreImpl(sslEncryptionParameters.getKeyStoreParameters(),  keyResourceLoader);
    this.sslTrustStore = new AlfrescoKeyStoreImpl(sslEncryptionParameters.getTrustStoreParameters(), keyResourceLoader);
    this.sslSocketFactory = new AuthSSLProtocolSocketFactory(sslKeyStore, sslTrustStore, keyResourceLoader);

    // Setup the Apache httpclient library to use our concurrent HttpParams factory
    DefaultHttpParams.setHttpParamsFactory(new NonBlockingHttpParamsFactory());
}
项目:lib-commons-httpclient    文件:TestChallengeProcessor.java   
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"));
}
项目:lib-commons-httpclient    文件:CustomAuthenticationNegotiateExample.java   
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();
    }            

}
项目:apex-malhar    文件:StockTickInput.java   
@Override
public void setup(OperatorContext context)
{
  url = prepareURL();
  client = new HttpClient();
  method = new GetMethod(url);
  DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY);
}
项目:apex-malhar    文件:YahooFinanceCSVInputOperator.java   
@Override
public void setup(OperatorContext context)
{
  url = prepareURL();
  client = new HttpClient();
  method = new GetMethod(url);
  DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY);
}
项目:httpclient3-ntml    文件:TestChallengeProcessor.java   
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"));
}