List of usage examples for org.apache.http.params HttpParams getParameter
Object getParameter(String str);
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testProxyAuth() { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); when(proxySettings.getProxyAuthentication()).thenReturn(proxyAuth); when(proxyAuth.getUsername()).thenReturn("user"); when(proxyAuth.getPassword()).thenReturn("pass"); final HttpClient client = underTest.client(); final HttpParams params = client.getParams(); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), notNullValue()); assertThat(((DefaultHttpClient) client).getCredentialsProvider().getCredentials(new AuthScope(host, port)), notNullValue());//w w w.jav a 2 s.co m }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testProxyReconfigure() { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); DefaultHttpClient client = (DefaultHttpClient) underTest.client(); HttpParams params = client.getParams(); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), nullValue()); assertThat(client.getCredentialsProvider().getCredentials(new AuthScope(host, port)), nullValue()); when(proxySettings.getProxyAuthentication()).thenReturn(proxyAuth); when(proxyAuth.getUsername()).thenReturn("user"); when(proxyAuth.getPassword()).thenReturn("pass"); final DefaultHttpClient reconfigured = (DefaultHttpClient) underTest.client(); params = reconfigured.getParams();/*from w w w. ja va2 s . c o m*/ assertThat(reconfigured, equalTo(client)); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), notNullValue()); assertThat(reconfigured.getCredentialsProvider().getCredentials(new AuthScope(host, port)), notNullValue()); }
From source file:org.apache.synapse.transport.passthru.config.SourceConfigurationTest.java
@Test public void testGetHttpParams() throws Exception { HttpParams httpParams = sourceConfiguration.getHttpParams(); Assert.assertNotNull("HTTP Parameters are null.", httpParams); String originServer = (String) httpParams.getParameter(HttpProtocolParams.ORIGIN_SERVER); Assert.assertEquals("Origin Server isn't correct.", "WSO2-PassThrough-HTTP", originServer); }
From source file:org.commonjava.maven.galley.transport.htcli.internal.LocationSSLSocketFactory.java
@Override public Socket createSocket(final HttpParams params) throws IOException { // logger.info( "Creating socket...looking for repository definition in parameters..." ); final HttpLocation repo = (HttpLocation) params.getParameter(Http.HTTP_PARAM_LOCATION); if (repo != null) { // logger.info( "Creating socket...using repository: {}", repo ); final SSLSocketFactory fac = getSSLFactory(repo); if (fac != null) { // logger.info( "Creating socket using repo-specific factory" ); return fac.createSocket(params); } else {// w w w . j a va2 s . co m // logger.info( "No repo-specific factory; Creating socket using default factory (this)" ); return super.createSocket(params); } } else { // logger.info( "No repo; Creating socket using default factory (this)" ); return super.createSocket(params); } }
From source file:hornet.framework.technical.HTTPClientParameterBuilderTest.java
/** * Teste la mthode <tt>loadHttpParamToHttpClientFromConfig</tt> pour le cas o le paramtrage par dfaut * est dfini./*from w ww .j av a 2s .c o m*/ */ @SuppressWarnings("unchecked") @Test public void testLoadHttpParamToHttpClientShouldLoadDefaultValue() { final HttpClient httpClient = new DefaultHttpClient(); HTTPClientParameterBuilder.loadHttpParamToHttpClientFromConfig(httpClient, null); final HttpParams httpParams = httpClient.getParams(); assertEquals(CONST_3000, httpParams.getIntParameter("http.connection.timeout", 0)); final Map<HttpHost, Integer> maxPerHost = (Map<HttpHost, Integer>) httpParams .getParameter("http.connection-manager.max-per-host"); assertEquals(1, maxPerHost.size()); assertTrue(maxPerHost.containsKey(new HttpHost("hostname"))); assertEquals(Integer.valueOf(CONST_50), maxPerHost.get(new HttpHost("hostname"))); assertEquals(CONST_50, httpParams.getIntParameter("http.connection-manager.max-total", 0)); assertEquals(CONST_3000, httpParams.getLongParameter("http.connection-manager.timeout", 0)); assertEquals(CONST_60000, httpParams.getIntParameter("http.socket.timeout", 0)); assertEquals(org.apache.http.impl.conn.PoolingHttpClientConnectionManager.class, httpParams.getParameter("http.connection-manager.class")); }
From source file:org.vietspider.net.client.impl.AnonymousHttpClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connManager = null; HttpParams params = getParams(); ClientConnectionManagerFactory factory = null; // Try first getting the factory directly as an object. factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY); if (factory == null) { // then try getting its class name. String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try { Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (InstantiationException ex) { throw new InstantiationError(ex.getMessage()); }//from w ww. j av a 2 s .co m } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new SingleClientConnManager(getParams(), registry); } return connManager; }
From source file:ucar.httpservices.CustomSSLProtocolSocketFactory.java
private SSLContext trustedauthentication(HttpParams params) throws Exception { String keypath = null;//from w w w .j a v a 2s .c om String keypassword = null; String trustpath = null; String trustpassword = null; HTTPSSLProvider provider = null; if (params == null) return null; Object o = params.getParameter(HTTPAuthPolicy.PROVIDER); if (o == null) return null; if (!(o instanceof HTTPSSLProvider)) throw new HTTPException("CustomSSLProtocolSocketFactory: provide is not SSL provider"); provider = (HTTPSSLProvider) o; keypath = provider.getKeystore(); keypassword = provider.getKeypassword(); trustpath = provider.getTruststore(); trustpassword = provider.getTrustpassword(); TrustManager[] trustmanagers = null; KeyManager[] keymanagers = null; KeyStore keystore = buildstore(keypath, keypassword, "key"); if (keystore != null) { KeyManagerFactory kmfactory = KeyManagerFactory.getInstance("SunX509"); kmfactory.init(keystore, keypassword.toCharArray()); keymanagers = kmfactory.getKeyManagers(); } KeyStore truststore = buildstore(trustpath, trustpassword, "trust"); if (truststore != null) { //todo: TrustManagerFactory trfactory = TrustManagerFactory.getInstance("SunX509"); //trfactory.init(truststore, trustpassword.toCharArray()); //trustmanagers = trfactory.getTrustManagers(); trustmanagers = new TrustManager[] { new CustomX509TrustManager(truststore) }; } if (trustmanagers == null) trustmanagers = new TrustManager[] { new CustomX509TrustManager(null) }; SSLContext sslcontext = SSLContext.getInstance("TSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; }
From source file:fedroot.dacs.http.DacsClientContext.java
public DacsClientContext(HttpParams httpParams) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ClientConnectionManager cm = new ThreadSafeClientConnManager(schemeRegistry); if (httpParams.getParameter(ClientPNames.COOKIE_POLICY) == null) { httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); }//from w w w . j av a 2 s .c om httpClient = new DefaultHttpClient(cm, httpParams); cookieStore = new BasicCookieStore(); httpContext = new BasicHttpContext(); // Bind custom cookie store to the local context httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:org.apache.http.impl.client.AbstractHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { final SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; final HttpParams params = getParams(); ClientConnectionManagerFactory factory = null; final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try {//from ww w .j a v a2s . c om final Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (final ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (final InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new BasicClientConnectionManager(registry); } return connManager; }