Java Code Examples for org.apache.http.params.HttpParams
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project exo.social.client, under directory /src/main/java/org/exoplatform/social/client/core/net/.
Source file: SocialHttpClientImpl.java

/** * Create a new HttpClient with reasonable defaults. * @return SocialHttpClient for you to use for all your requests. */ public static SocialHttpClient newInstance(){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new SocialHttpClientImpl(manager,params); }
Example 2
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: HttpClientSingleton.java

public static HttpClient getInstance(){ if (instance == null) { instance=new DefaultHttpClient(); HttpParams httpParams=instance.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams,Values.TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams,Values.TIMEOUT); } return instance; }
Example 3
From project Airports, under directory /src/com/nadmm/airports/utils/.
Source file: NetworkUtils.java

public static HttpClient getHttpClient(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); HttpParams params=new BasicHttpParams(); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry); HttpClient client=new DefaultHttpClient(cm,params); return client; }
Example 4
From project and-bible, under directory /jsword-tweaks/src/main/java/jsword/org/crosswire/common/util/.
Source file: WebResource.java

/** * Construct a WebResource for the given URL, going through the optional proxy and port, while timing out if too much time has passed. * @param theURI the Resource to get via HTTP * @param theProxyHost the proxy host or null * @param theProxyPort the proxy port or null, where null means use the standard port * @param theTimeout the length of time in milliseconds to allow a connection to respond before timing out */ public WebResource(URI theURI,String theProxyHost,Integer theProxyPort,int theTimeout){ uri=theURI; client=new DefaultHttpClient(); HttpParams params=client.getParams(); HttpConnectionParams.setSoTimeout(params,theTimeout); HttpConnectionParams.setConnectionTimeout(params,theTimeout); if (theProxyHost != null && theProxyHost.length() > 0) { HttpHost proxy=new HttpHost(theProxyHost,theProxyPort == null ? -1 : theProxyPort.intValue()); ConnRouteParams.setDefaultProxy(params,proxy); ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()); ((AbstractHttpClient)client).setRoutePlanner(routePlanner); } }
Example 5
From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.
Source file: CatchAPI.java

private HttpClient getHttpClientNoToken(){ if (httpClientNoToken == null) { HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(params,userAgent); HttpProtocolParams.setContentCharset(params,"UTF-8"); httpClientNoToken=new DefaultHttpClient(params); } return httpClientNoToken; }
Example 6
From project android-async-http, under directory /src/com/loopj/android/http/.
Source file: AsyncHttpClient.java

/** * Sets the connection time oout. By default, 10 seconds * @param timeout the connect/socket timeout in milliseconds */ public void setTimeout(int timeout){ final HttpParams httpParams=this.httpClient.getParams(); ConnManagerParams.setTimeout(httpParams,timeout); HttpConnectionParams.setSoTimeout(httpParams,timeout); HttpConnectionParams.setConnectionTimeout(httpParams,timeout); }
Example 7
From project android-client, under directory /xwiki-android-rest/src/org/xwiki/android/rest/.
Source file: HttpConnector.java

/** * initialize the general property fields */ private void initialize(){ client=new DefaultHttpClient(); HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,10000); HttpConnectionParams.setSoTimeout(params,20000); client.setParams(params); }
Example 8
From project Android-SyncAdapter-JSON-Server-Example, under directory /src/com/puny/android/network/util/.
Source file: DrupalJSONServerNetworkUtilityBase.java

/** * Configures the httpClient to connect to the URL provided. */ public static void maybeCreateHttpClient(){ if (mHttpClient == null) { mHttpClient=new DefaultHttpClient(); final HttpParams params=mHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT); } }
Example 9
From project android_external_oauth, under directory /core/src/main/java/net/oauth/client/httpclient4/.
Source file: HttpClient4.java

SingleClient(){ HttpClient client=new DefaultHttpClient(); ClientConnectionManager mgr=client.getConnectionManager(); if (!(mgr instanceof ThreadSafeClientConnManager)) { HttpParams params=client.getParams(); client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params); } this.client=client; }
Example 10
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.
Source file: EasSyncService.java

private HttpClient getHttpClient(int timeout){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,timeout); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClient client=new DefaultHttpClient(getClientConnectionManager(),params); return client; }
Example 11
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/google/.
Source file: GoogleSuggestClient.java

public GoogleSuggestClient(Context context){ super(context); mHttpClient=new DefaultHttpClient(); HttpParams params=mHttpClient.getParams(); HttpProtocolParams.setUserAgent(params,USER_AGENT); params.setLongParameter(HTTP_TIMEOUT,HTTP_TIMEOUT_MS); mSuggestUri=null; }
Example 12
From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.
Source file: Flickr.java

private void Flickr(){ final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,"UTF-8"); final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); final ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(params,registry); mClient=new DefaultHttpClient(manager,params); }
Example 13
From project bbb-java, under directory /src/main/java/org/mconf/web/.
Source file: Authentication.java

@SuppressWarnings("deprecation") public Authentication(String server,String username,String password) throws HttpException, IOException { this.server=server; SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); registry.register(new Scheme("https",new FakeSocketFactory(),443)); HttpParams params=new BasicHttpParams(); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false); client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,registry),params); authenticated=authenticate(username,password); }
Example 14
From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/http/.
Source file: RequestHandler.java

public static DefaultHttpClient getThreadSafeClient(){ DefaultHttpClient client=new DefaultHttpClient(); ClientConnectionManager mgr=client.getConnectionManager(); HttpParams params=client.getParams(); client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params); return client; }
Example 15
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/goodreads/.
Source file: GoodreadsManager.java

/** * Create an HttpClient with specifically set buffer sizes to deal with potentially exorbitant settings on some HTC handsets. * @return */ private HttpClient newHttpClient(){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,30000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpConnectionParams.setLinger(params,0); HttpConnectionParams.setTcpNoDelay(params,false); HttpClient httpClient=new DefaultHttpClient(params); return httpClient; }
Example 16
From project BusFollower, under directory /src/net/argilo/busfollower/ocdata/.
Source file: OCTranspoDataFetcher.java

private HttpParams getHttpParams(){ HttpParams httpParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,TIMEOUT_CONNECTION); HttpConnectionParams.setSoTimeout(httpParams,TIMEOUT_SOCKET); return httpParams; }
Example 17
From project capedwarf-blue, under directory /urlfetch/src/main/java/org/jboss/capedwarf/urlfetch/.
Source file: JBossURLFetchService.java

protected HttpClient getClient(){ if (client == null) { SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory())); HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,30 * 1000); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,"UTF-8"); ClientConnectionManager ccm=new ThreadSafeClientConnManager(schemeRegistry); client=new DefaultHttpClient(ccm,params); } return client; }
Example 18
From project components-ness-httpclient, under directory /client/src/main/java/com/nesscomputing/httpclient/factory/httpclient4/.
Source file: ApacheHttpClient4Factory.java

private <T>void contributeParameters(final DefaultHttpClient httpClient,final HttpRequestBase httpRequest,final HttpClientRequest<T> httpClientRequest){ final Map<String,Object> parameters=httpClientRequest.getParameters(); if (parameters != null && parameters.size() > 0) { HttpParams clientParams=httpClient.getParams(); HttpParams requestParams=httpRequest.getParams(); for ( Map.Entry<String,Object> entry : parameters.entrySet()) { clientParams.setParameter(entry.getKey(),entry.getValue()); requestParams.setParameter(entry.getKey(),entry.getValue()); } } }
Example 19
From project crest, under directory /core/src/test/java/org/codegist/crest/io/http/.
Source file: HttpClientHttpChannelFactoryTest.java

private void openShouldCreateAHttpClientHttpChannelInstanceWithClientFor(HttpUriRequest expectedRequest,MethodType methodType) throws Exception { HttpClientHttpChannel expected=mock(HttpClientHttpChannel.class); HttpParams params=mock(HttpParams.class); when(expectedRequest.getParams()).thenReturn(params); whenNew(HttpClientHttpChannel.class).withArguments(client,expectedRequest).thenReturn(expected); HttpChannel actual=toTest.open(methodType,"url",Values.UTF8); assertSame(expected,actual); verify(params).setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8"); }
Example 20
From project DeliciousDroid, under directory /src/com/deliciousdroid/client/.
Source file: HttpClientFactory.java

public static HttpClient getThreadSafeClient(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,100); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry); HttpClient client=new DefaultHttpClient(mgr,params); return client; }
Example 21
From project droidparts, under directory /extra/src/org/droidparts/http/wrapper/.
Source file: DefaultHttpClientWrapper.java

public DefaultHttpClientWrapper(String userAgent){ super(userAgent); httpClient=new DefaultHttpClient(); HttpParams params=httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params,BUFFER_SIZE); if (userAgent != null) { HttpProtocolParams.setUserAgent(params,userAgent); } }
Example 22
From project eve-api, under directory /cdi/src/main/java/org/onsteroids/eve/api/connector/http/.
Source file: PooledHttpApiConnection.java

/** * Initializses and configures the http client connection pool. */ private void initializeHttpClient(){ LOG.debug("Configuring the HttpClientPool with a maximum of {} connections",maxConnections); HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,maxConnections); ConnPerRouteBean connPerRoute=new ConnPerRouteBean(maxConnections); HttpHost serverHost=new HttpHost(serverUri.getHost(),serverUri.getPort()); connPerRoute.setMaxForRoute(new HttpRoute(serverHost),maxConnections); ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(cm,params); }
Example 23
From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/http/.
Source file: HttpClient.java

/** * Setup DefaultHttpClient Use ThreadSafeClientConnManager. */ private void prepareHttpClient(){ if (DEBUG) { enableDebug(); } HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,10); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); mClient=new DefaultHttpClient(cm,params); mClient.addResponseInterceptor(gzipResponseIntercepter); }
Example 24
From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/client/.
Source file: HttpClientFactory.java

public static synchronized HttpClient getHttpClient(){ if (client == null) { HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,MAX_TOTAL_CONNECTIONS); ConnPerRouteBean connPerRoute=new ConnPerRouteBean(MAX_PER_ROUTE); ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry); client=new DefaultHttpClient(cm,params); } System.out.println("return cached client"); return client; }
Example 25
From project Game_3, under directory /android/src/playn/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 26
From project generic-store-for-android, under directory /src/com/wareninja/opensource/common/.
Source file: WebService.java

public WebService(String serviceName){ HttpParams myParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams,20000); HttpConnectionParams.setSoTimeout(myParams,20000); httpClient=new DefaultHttpClient(myParams); localContext=new BasicHttpContext(); webServiceUrl=serviceName; }
Example 27
From project hsDroid, under directory /src/de/nware/app/hsDroid/provider/.
Source file: HttpClientFactory.java

public synchronized static DefaultHttpClient getHttpClient(int connectionTimeoutMillis){ if (httpClient == null) { httpClient=new DefaultHttpClient(); ClientConnectionManager connectionManager=httpClient.getConnectionManager(); HttpParams httpParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,connectionTimeoutMillis); httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams,connectionManager.getSchemeRegistry()),httpParams); } return httpClient; }
Example 28
From project httpbuilder, under directory /src/main/java/groovyx/net/http/.
Source file: AsyncHTTPBuilder.java

/** * Initializes threading parameters for the HTTPClient's {@link ThreadSafeClientConnManager}, and this class' ThreadPoolExecutor. */ protected void initThreadPools(final int poolSize,final ExecutorService threadPool){ if (poolSize < 1) throw new IllegalArgumentException("poolSize may not be < 1"); HttpParams params=client != null ? client.getParams() : new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,poolSize); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(poolSize)); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); super.client=new DefaultHttpClient(cm,params); this.threadPool=threadPool != null ? threadPool : new ThreadPoolExecutor(poolSize,poolSize,120,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>()); }
Example 29
From project httpClient, under directory /httpclient/src/test/java/org/apache/http/conn/params/.
Source file: TestRouteParams.java

@Test public void testSetGet(){ HttpParams params=new BasicHttpParams(); Assert.assertNull("phantom proxy",ConnRouteParams.getDefaultProxy(params)); Assert.assertNull("phantom route",ConnRouteParams.getForcedRoute(params)); Assert.assertNull("phantom address",ConnRouteParams.getLocalAddress(params)); ConnRouteParams.setDefaultProxy(params,TARGET1); Assert.assertSame("wrong proxy",TARGET1,ConnRouteParams.getDefaultProxy(params)); ConnRouteParams.setForcedRoute(params,ROUTE1); Assert.assertSame("wrong route",ROUTE1,ConnRouteParams.getForcedRoute(params)); ConnRouteParams.setLocalAddress(params,LOCAL1); Assert.assertSame("wrong address",LOCAL1,ConnRouteParams.getLocalAddress(params)); }
Example 30
From project 4308Cirrus, under directory /tendril-android-lib/src/main/java/edu/colorado/cs/cirrus/android/.
Source file: HttpUtils.java

public static HttpClient getNewHttpClient(){ try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new EasySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } }
Example 31
From project android-bankdroid, under directory /src/eu/nullbyte/android/urllib/.
Source file: Urllib.java

public Urllib(boolean acceptInvalidCertificates,boolean allowCircularRedirects){ this.acceptInvalidCertificates=acceptInvalidCertificates; this.headers=new HashMap<String,String>(); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,this.charset); params.setBooleanParameter("http.protocol.expect-continue",false); if (allowCircularRedirects) params.setBooleanParameter("http.protocol.allow-circular-redirects",true); if (acceptInvalidCertificates) { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",new EasySSLSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry); httpclient=new DefaultHttpClient(manager,params); } else { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry); httpclient=new DefaultHttpClient(manager,params); } context=new BasicHttpContext(); }
Example 32
From project androidquery, under directory /src/com/androidquery/callback/.
Source file: AbstractAjaxCallback.java

private static DefaultHttpClient getClient(){ if (client == null || !REUSE_CLIENT) { AQUtility.debug("creating http client"); HttpParams httpParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,NET_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams,NET_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(25)); HttpConnectionParams.setSocketBufferSize(httpParams,8192); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",ssf == null ? SSLSocketFactory.getSocketFactory() : ssf,443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,registry); client=new DefaultHttpClient(cm,httpParams); } return client; }
Example 33
From project android_packages_apps_Gallery2, under directory /gallerycommon/src/com/android/gallery3d/common/.
Source file: HttpClientFactory.java

/** * Creates an HttpClient with the specified userAgent string. * @param userAgent the userAgent string * @return the client */ public static HttpClient newHttpClient(String userAgent){ try { Class<?> clazz=Class.forName("android.net.http.AndroidHttpClient"); Method newInstance=clazz.getMethod("newInstance",String.class); Object instance=newInstance.invoke(null,userAgent); HttpClient client=(HttpClient)instance; HttpParams params=client.getParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1); ConnManagerParams.setTimeout(params,60 * 1000); return client; } catch ( InvocationTargetException e) { throw new RuntimeException(e); } catch ( ClassNotFoundException e) { throw new RuntimeException(e); } catch ( NoSuchMethodException e) { throw new RuntimeException(e); } catch ( IllegalAccessException e) { throw new RuntimeException(e); } }
Example 34
From project andstatus, under directory /src/org/andstatus/app/net/.
Source file: ConnectionOAuth.java

public ConnectionOAuth(MyAccount ma){ super(ma); mOauthBaseUrl=ma.getOauthBaseUrl(); HttpParams parameters=new BasicHttpParams(); HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(parameters,false); HttpConnectionParams.setTcpNoDelay(parameters,true); HttpConnectionParams.setSocketBufferSize(parameters,8192); SchemeRegistry schReg=new SchemeRegistry(); schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg); mClient=new DefaultHttpClient(tsccm,parameters); OAuthKeys oak=new OAuthKeys(ma.getOriginId()); mConsumer=new CommonsHttpOAuthConsumer(oak.getConsumerKey(),oak.getConsumerSecret()); mProvider=new CommonsHttpOAuthProvider(getApiUrl(apiEnum.OAUTH_REQUEST_TOKEN),getApiUrl(apiEnum.OAUTH_ACCESS_TOKEN),getApiUrl(apiEnum.OAUTH_AUTHORIZE)); mProvider.setOAuth10a(true); if (ma.dataContains(ConnectionOAuth.USER_TOKEN) && ma.dataContains(ConnectionOAuth.USER_SECRET)) { setAuthInformation(ma.getDataString(ConnectionOAuth.USER_TOKEN,null),ma.getDataString(ConnectionOAuth.USER_SECRET,null)); } }
Example 35
From project andtweet, under directory /src/com/xorcode/andtweet/net/.
Source file: ConnectionOAuth.java

public ConnectionOAuth(SharedPreferences sp){ super(sp); HttpParams parameters=new BasicHttpParams(); HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(parameters,false); HttpConnectionParams.setTcpNoDelay(parameters,true); HttpConnectionParams.setSocketBufferSize(parameters,8192); SchemeRegistry schReg=new SchemeRegistry(); schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg); mClient=new DefaultHttpClient(tsccm,parameters); mConsumer=new CommonsHttpOAuthConsumer(OAuthKeys.TWITTER_CONSUMER_KEY,OAuthKeys.TWITTER_CONSUMER_SECRET); loadSavedKeys(sp); }
Example 36
From project Anki-Android, under directory /src/com/tomgibara/android/veecheck/.
Source file: VeecheckThread.java

private VeecheckResult performRequest(VeecheckVersion version,String uri) throws ClientProtocolException, IOException, IllegalStateException, SAXException { HttpClient client=new DefaultHttpClient(); HttpParams params=client.getParams(); HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SO_TIMEOUT); HttpGet request=new HttpGet(version.substitute(uri)); HttpResponse response=client.execute(request); HttpEntity entity=response.getEntity(); try { StatusLine line=response.getStatusLine(); if (line.getStatusCode() != 200) { throw new IOException("Request failed: " + line.getReasonPhrase()); } Header header=response.getFirstHeader(HTTP.CONTENT_TYPE); Encoding encoding=identityEncoding(header); VeecheckResult handler=new VeecheckResult(version); Xml.parse(entity.getContent(),encoding,handler); return handler; } finally { entity.consumeContent(); } }
Example 37
From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 38
From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 39
From project capedwarf-green, under directory /connect/src/main/java/org/jboss/capedwarf/connect/server/.
Source file: ServerProxyHandler.java

/** * Get client. * @return the client */ private synchronized HttpClient getClient(){ if (client == null) { HttpParams params=createHttpParams(); HttpProtocolParams.setVersion(params,config.getHttpVersion()); HttpProtocolParams.setContentCharset(params,config.getContentCharset()); HttpProtocolParams.setUseExpectContinue(params,config.isExpectContinue()); HttpConnectionParams.setStaleCheckingEnabled(params,config.isStaleCheckingEnabled()); HttpConnectionParams.setConnectionTimeout(params,config.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(params,config.getSoTimeout()); HttpConnectionParams.setSocketBufferSize(params,config.getSocketBufferSize()); SchemeRegistry schemeRegistry=createSchemeRegistry(); ClientConnectionManager ccm=createClientConnectionManager(params,schemeRegistry); HttpClient tmp=createClient(ccm,params); String username=config.getUsername(); String password=config.getPassword(); if (username != null && password != null) { if (tmp instanceof AbstractHttpClient) { CredentialsProvider credsProvider=AbstractHttpClient.class.cast(tmp).getCredentialsProvider(); credsProvider.setCredentials(new AuthScope(config.getHostName(),config.getSslPort()),new UsernamePasswordCredentials(username,password)); } else { Logger.getLogger(getClass().getName()).warning("Cannot set CredentialsProvider on HttpClient: " + tmp); } } client=tmp; } return client; }
Example 40
From project cloudify, under directory /rest-client/src/main/java/org/cloudifysource/restclient/.
Source file: GSRestClient.java

/** * Returns a HTTP client configured to use SSL. * @return HTTP client configured to use SSL * @throws RestException Reporting different failures while creating the HTTP client */ public final DefaultHttpClient getSSLHttpClient() throws RestException { try { final KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); final SSLSocketFactory sf=new RestSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme(HTTPS,sf,url.getPort())); final ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( final KeyStoreException e) { throw new RestException(e); } catch ( final NoSuchAlgorithmException e) { throw new RestException(e); } catch ( final CertificateException e) { throw new RestException(e); } catch ( final IOException e) { throw new RestException(e); } catch ( final KeyManagementException e) { throw new RestException(e); } catch ( final UnrecoverableKeyException e) { throw new RestException(e); } }
Example 41
From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 42
From project couchdb-lucene, under directory /src/main/java/com/github/rnewson/couchdb/lucene/.
Source file: HttpClientFactory.java

public static synchronized HttpClient getInstance() throws MalformedURLException { if (instance == null) { final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params,false); HttpConnectionParams.setTcpNoDelay(params,true); HttpConnectionParams.setStaleCheckingEnabled(params,false); ConnManagerParams.setMaxTotalConnections(params,1000); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(1000)); final SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),5984)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); final ClientConnectionManager cm=new ShieldedClientConnManager(new ThreadSafeClientConnManager(params,schemeRegistry)); instance=new DefaultHttpClient(cm,params); if (INI != null) { final CredentialsProvider credsProvider=new BasicCredentialsProvider(); final Iterator<?> it=INI.getKeys(); while (it.hasNext()) { final String key=(String)it.next(); if (!key.startsWith("lucene.") && key.endsWith(".url")) { final URL url=new URL(INI.getString(key)); if (url.getUserInfo() != null) { credsProvider.setCredentials(new AuthScope(url.getHost(),url.getPort()),new UsernamePasswordCredentials(url.getUserInfo())); } } } instance.setCredentialsProvider(credsProvider); instance.addRequestInterceptor(new PreemptiveAuthenticationRequestInterceptor(),0); } } return instance; }
Example 43
From project dccsched, under directory /src/com/underhilllabs/dccsched/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 44
From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 45
From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.
Source file: TickleServiceHelper.java

static String getCookie(final Context context) throws ClientProtocolException, IOException, URISyntaxException { Settings settings=Settings.getInstance(context); final String authToken=settings.getString("web_connect_auth_token"); if (authToken == null) return null; Log.i(LOGTAG,authToken); Log.i(LOGTAG,"getting cookie"); DefaultHttpClient client=new DefaultHttpClient(); String continueURL=ServiceHelper.BASE_URL; URI uri=new URI(ServiceHelper.AUTH_URL + "?continue=" + URLEncoder.encode(continueURL,"UTF-8")+ "&auth="+ authToken); HttpGet method=new HttpGet(uri); final HttpParams getParams=new BasicHttpParams(); HttpClientParams.setRedirecting(getParams,false); method.setParams(getParams); HttpResponse res=client.execute(method); Header[] headers=res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return null; } String ascidCookie=null; for ( Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { String value=header.getValue(); String[] pairs=value.split(";"); ascidCookie=pairs[0]; } } settings.setString("Cookie",ascidCookie); return ascidCookie; }
Example 46
From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/service/.
Source file: RestService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 47
From project DiscogsForAndroid, under directory /src/com/discogs/services/.
Source file: NetworkHelper.java

private void initHTTPClient(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setContentCharset(params,"utf-8"); params.setBooleanParameter("http.protocol.expect-continue",false); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params,true); ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connectionManager,params); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,false)); httpClient.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding","gzip"); } } } ); httpClient.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity=response.getEntity(); if (entity != null) { Header ceheader=entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs=ceheader.getElements(); for (int i=0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } } } ); }
Example 48
From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void updateProxySettings(){ if (appContext == null) { return; } HttpParams httpParams=httpClient.getParams(); ConnectivityManager connectivity=(ConnectivityManager)appContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo=connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG,nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost=Proxy.getHost(appContext); if (proxyHost == null) { proxyHost=Proxy.getDefaultHost(); } int proxyPort=Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort=Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy=new HttpHost(proxyHost,proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } }
Example 49
From project E12Planner, under directory /src/com/neoware/europlanner/.
Source file: ReadDataAsyncTask.java

@Override protected Boolean doInBackground(String... params){ try { HttpClient httpClient=new DefaultHttpClient(); HttpParams httpParams=httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams,30000); HttpConnectionParams.setSoTimeout(httpParams,30000); HttpGet get=new HttpGet(params[0]); mData=httpClient.execute(get,new BasicResponseHandler()); return true; } catch ( ClientProtocolException ex) { mErrorMessage=ex.getMessage(); } catch ( IOException ex) { mErrorMessage=ex.getMessage(); } return false; }
Example 50
From project fed4j, under directory /src/main/java/com/jute/fed4j/engine/component/http/.
Source file: HttpDispatcherImpl_Jakarta.java

public void run(HttpComponent component){ this.commponent=component; HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,component.connectTimeout); HttpConnectionParams.setSoTimeout(params,component.readTimeout); try { this.init(component); HttpClient httpclient=new MyHttpClient(getConnectionManager(params,component.enablePersistentConnection),params); if (component.enableProxy && "http".equals(component.proxyType)) { HttpHost proxy=new HttpHost(component.proxyHost,component.proxyPort,component.proxyType); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); } HttpUriRequest request=new HttpRequest(component.method,component.uri); MyHttpResponseHandler responseHandler=new MyHttpResponseHandler(component.responseCharset); String body=httpclient.execute(request,responseHandler); this.onResponse(component,responseHandler.code,body); } catch ( SocketTimeoutException e) { onException(component,-2," socket timeout error occurs: " + e.getMessage()); } catch ( ClientProtocolException e) { onException(component,-3," error resposed from server: " + e.getMessage()); } catch ( IOException e) { onException(component,-4," error occurs during dispatch: " + e.getMessage()); } catch ( Exception e) { onException(component,-5,"error occurs during parsing xml:" + e.getMessage()); } }
Example 51
From project Fotolia-API, under directory /java/libs/httpcomponents-client-4.1.2/examples/org/apache/http/examples/conn/.
Source file: OperatorConnectDirect.java

public static void main(String[] args) throws Exception { HttpHost target=new HttpHost("jakarta.apache.org",80,"http"); SchemeRegistry supportedSchemes=new SchemeRegistry(); supportedSchemes.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); HttpParams params=new SyncBasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params,false); ClientConnectionOperator scop=new DefaultClientConnectionOperator(supportedSchemes); HttpRequest req=new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1); req.addHeader("Host",target.getHostName()); HttpContext ctx=new BasicHttpContext(); OperatedClientConnection conn=scop.createConnection(); try { System.out.println("opening connection to " + target); scop.openConnection(conn,target,null,ctx,params); System.out.println("sending request"); conn.sendRequestHeader(req); conn.flush(); System.out.println("receiving response header"); HttpResponse rsp=conn.receiveResponseHeader(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers=rsp.getAllHeaders(); for (int i=0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); } finally { System.out.println("closing connection"); conn.close(); } }
Example 52
From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.
Source file: TwAjax.java

public DefaultHttpClient getNewHttpClient(){ if (ignoreSSLCerts) { try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new IgnoreCertsSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } } else { return new DefaultHttpClient(); } }
Example 53
From project Gaggle, under directory /src/com/geeksville/location/.
Source file: LeonardoUpload.java

/** * Upload a flight to Leonardo * @param username * @param password * @param postURL * @param shortFilename * @param igcFile we will take care of closing this stram * @return null for success, otherwise a string description of the problem * @throws IOException */ public static String upload(String username,String password,String postURL,int competitionClass,String shortFilename,String igcFile,int connectionTimeout,int operationTimeout) throws IOException { int i=shortFilename.lastIndexOf('.'); if (i >= 1) shortFilename=shortFilename.substring(0,i); String sCompetitionClass=String.valueOf(competitionClass); HttpParams httpParameters=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters,connectionTimeout); HttpConnectionParams.setSoTimeout(httpParameters,operationTimeout); HttpClient httpclient=new DefaultHttpClient(httpParameters); httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,false); HttpPost httppost=new HttpPost(postURL); List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("user",username)); nameValuePairs.add(new BasicNameValuePair("pass",password)); nameValuePairs.add(new BasicNameValuePair("igcfn",shortFilename)); nameValuePairs.add(new BasicNameValuePair("Klasse",sCompetitionClass)); nameValuePairs.add(new BasicNameValuePair("IGCigcIGC",igcFile)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response=httpclient.execute(httppost); HttpEntity entity=response.getEntity(); String resp=EntityUtils.toString(entity); if (resp.contains("flight scored")) resp=null; else { int bodLoc=resp.indexOf("<body>"); if (bodLoc >= 0) resp=resp.substring(bodLoc + 6); int probLoc=resp.indexOf("problem"); if (probLoc >= 0) resp=resp.substring(probLoc + 7); if (resp.startsWith("<br>")) resp=resp.substring(4); int markLoc=resp.indexOf('<'); if (markLoc >= 0) resp=resp.substring(0,markLoc); resp=resp.trim(); } return resp; }
Example 54
From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/service/.
Source file: SyncService.java

/** * Generate and return a {@link HttpClient} configured for general use,including setting an application-specific user-agent string. */ public static HttpClient getHttpClient(Context context){ final HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params,8192); HttpProtocolParams.setUserAgent(params,buildUserAgent(context)); final DefaultHttpClient client=new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( HttpRequest request, HttpContext context){ if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP); } } } ); client.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( HttpResponse response, HttpContext context){ final HttpEntity entity=response.getEntity(); final Header encoding=entity.getContentEncoding(); if (encoding != null) { for ( HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } } ); return client; }
Example 55
From project GraduationProject, under directory /G-Card/src/Hello/Tab/Widget/.
Source file: AppEngineClient.java

private HttpResponse makeRequestNoRetry(String urlPath,List<NameValuePair> params,boolean newToken) throws Exception { Account account=new Account(mAccountName,"com.google"); String authToken=getAuthToken(mContext,account); if (newToken) { AccountManager accountManager=AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type,authToken); authToken=getAuthToken(mContext,account); } DefaultHttpClient client=new DefaultHttpClient(); String continueURL=BASE_URL; URI uri=new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL,"UTF-8")+ "&auth="+ authToken); HttpGet method=new HttpGet(uri); final HttpParams getParams=new BasicHttpParams(); HttpClientParams.setRedirecting(getParams,false); method.setParams(getParams); HttpResponse res=client.execute(method); Header[] headers=res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return res; } String ascidCookie=null; for ( Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { String value=header.getValue(); String[] pairs=value.split(";"); ascidCookie=pairs[0]; } } uri=new URI(BASE_URL + urlPath); HttpPost post=new HttpPost(uri); UrlEncodedFormEntity entity=new UrlEncodedFormEntity(params,"UTF-8"); post.setEntity(entity); post.setHeader("Cookie",ascidCookie); post.setHeader("X-Same-Domain","1"); res=client.execute(post); return res; }
Example 56
From project gxa, under directory /annotator/src/main/java/uk/ac/ebi/gxa/annotator/loader/.
Source file: URLContentLoader.java

public File getContentAsFile(String url,File file) throws AnnotationException { HttpGet httpGet=new HttpGet(url); final HttpParams params=new BasicHttpParams(); HttpClientParams.setRedirecting(params,true); httpGet.setParams(params); FileOutputStream out=null; try { HttpResponse response=httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new AnnotationException("Failed to connect to: " + url + " "+ response.getStatusLine()); } HttpEntity entity=response.getEntity(); final long responseContentLength=entity.getContentLength(); out=new FileOutputStream(file); entity.writeTo(out); out.close(); final long actualLength=file.length(); if (actualLength < responseContentLength) { log.error("Not all data are loaded actual size {} expected size {}",actualLength,responseContentLength); throw new AnnotationException("Failed to download all annotation data from: " + url + " expected size="+ responseContentLength+ " actual="+ actualLength+ ". Please try again!"); } } catch ( IOException e) { throw new AnnotationException("Fatal transport error when reading from " + url,e); } finally { closeQuietly(out); } return file; }
Example 57
From project httpcache4j, under directory /resolvers/resolvers-httpcomponents-httpclient/src/main/java/org/codehaus/httpcache4j/resolver/.
Source file: HTTPClientResponseResolver.java

public HTTPClientResponseResolver(HttpClient httpClient,ResolverConfiguration configuration){ super(configuration); this.httpClient=httpClient; HTTPHost proxyHost=getProxyAuthenticator().getConfiguration().getHost(); HttpParams params=httpClient.getParams(); if (params == null) { params=new BasicHttpParams(); if (httpClient instanceof DefaultHttpClient) { ((DefaultHttpClient)httpClient).setParams(params); } } if (proxyHost != null) { HttpHost host=new HttpHost(proxyHost.getHost(),proxyHost.getPort(),proxyHost.getScheme()); params.setParameter(ConnRoutePNames.DEFAULT_PROXY,host); } params.setParameter(CoreProtocolPNames.USER_AGENT,getConfiguration().getUserAgent()); }
Example 58
From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/config/.
Source file: ApacheHCHttpCommandExecutorServiceModule.java

@Singleton @Provides HttpParams newBasicHttpParams(HttpUtils utils){ BasicHttpParams params=new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,true).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true).setParameter(CoreProtocolPNames.ORIGIN_SERVER,"jclouds/1.0"); if (utils.getConnectionTimeout() > 0) { params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,utils.getConnectionTimeout()); } if (utils.getSocketOpenTimeout() > 0) { params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,utils.getSocketOpenTimeout()); } if (utils.getMaxConnections() > 0) ConnManagerParams.setMaxTotalConnections(params,utils.getMaxConnections()); if (utils.getMaxConnectionsPerHost() > 0) { ConnPerRoute connectionsPerRoute=new ConnPerRouteBean(utils.getMaxConnectionsPerHost()); ConnManagerParams.setMaxConnectionsPerRoute(params,connectionsPerRoute); } HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); return params; }
Example 59
From project cmsandroid, under directory /src/com/zia/freshdocs/net/.
Source file: EasySSLSocketFactory.java

/** * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams) */ public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int connTimeout=HttpConnectionParams.getConnectionTimeout(params); int soTimeout=HttpConnectionParams.getSoTimeout(params); InetSocketAddress remoteAddress=new InetSocketAddress(host,port); SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket()); if ((localAddress != null) || (localPort > 0)) { if (localPort < 0) { localPort=0; } InetSocketAddress isa=new InetSocketAddress(localAddress,localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress,connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
Example 60
From project dreamDroid, under directory /src/net/reichholf/dreamdroid/helpers/.
Source file: EasySSLSocketFactory.java

/** * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams) */ public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int connTimeout=HttpConnectionParams.getConnectionTimeout(params); int soTimeout=HttpConnectionParams.getSoTimeout(params); InetSocketAddress remoteAddress=new InetSocketAddress(host,port); SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket()); if ((localAddress != null) || (localPort > 0)) { if (localPort < 0) { localPort=0; } InetSocketAddress isa=new InetSocketAddress(localAddress,localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress,connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
Example 61
From project httpcore, under directory /httpcore/src/main/java/org/apache/http/impl/.
Source file: AbstractHttpClientConnection.java

/** * Initializes this connection object with {@link SessionInputBuffer} and{@link SessionOutputBuffer} instances to be used for sending andreceiving data. These session buffers can be bound to any arbitrary physical output medium. <p> This method will invoke {@link #createHttpResponseFactory()}, {@link #createRequestWriter(SessionOutputBuffer,HttpParams)}and {@link #createResponseParser(SessionInputBuffer,HttpResponseFactory,HttpParams)}methods to initialize HTTP request writer and response parser for this connection. * @param inbuffer the session input buffer. * @param outbuffer the session output buffer. * @param params HTTP parameters. */ protected void init(final SessionInputBuffer inbuffer,final SessionOutputBuffer outbuffer,final HttpParams params){ this.inbuffer=Args.notNull(inbuffer,"Input session buffer"); this.outbuffer=Args.notNull(outbuffer,"Output session buffer"); if (inbuffer instanceof EofSensor) { this.eofSensor=(EofSensor)inbuffer; } this.responseParser=createResponseParser(inbuffer,createHttpResponseFactory(),params); this.requestWriter=createRequestWriter(outbuffer,params); this.metrics=createConnectionMetrics(inbuffer.getMetrics(),outbuffer.getMetrics()); }