1 /*******************************************************************************
2 * Copyright © Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
4 * This file is part of the work and learning management system Pentila Nero.
6 * Pentila Nero is free software. You can redistribute it and/or modify since
7 * you respect the terms of either (at least one of the both license) :
8 * - under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
12 * License, or any later version
13 * - the GNU Lesser General Public License as published by the
14 * Free Software Foundation, either version 3 of the license,
15 * or (at your option) any later version.
17 * There are special exceptions to the terms and conditions of the
18 * licenses as they are applied to this software. View the full text of
19 * the exception in file LICENSE-PROJECT.txt in the directory of this software
22 * Pentila Nero is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * Licenses for more details.
27 * You should have received a copy of the GNU Affero General Public License
28 * and the CeCILL-C and the GNU Lesser General Public License along with
29 * Pentila Nero. If not, see :
30 * <http://www.gnu.org/licenses/> and
31 * <http://www.cecill.info/licences.fr.html>.
32 ******************************************************************************/
33 package com.pentila.entSavoie.mobileNotification.androidUtils;
34 import java.security.KeyStore;
36 import org.apache.http.HttpVersion;
37 import org.apache.http.client.HttpClient;
38 import org.apache.http.conn.ClientConnectionManager;
39 import org.apache.http.conn.scheme.PlainSocketFactory;
40 import org.apache.http.conn.scheme.Scheme;
41 import org.apache.http.conn.scheme.SchemeRegistry;
42 import org.apache.http.conn.ssl.SSLSocketFactory;
43 import org.apache.http.impl.client.DefaultHttpClient;
44 import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
45 import org.apache.http.params.BasicHttpParams;
46 import org.apache.http.params.HttpParams;
47 import org.apache.http.params.HttpProtocolParams;
48 import org.apache.http.protocol.HTTP;
50 //import com.myor.c2dm.socket.EasySSLSocketFactory;
54 public class HTTPUtils {
55 @SuppressWarnings("deprecation")
56 public static HttpClient getNewHttpClient() {
58 KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
59 trustStore.load(null, null);
61 SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
62 sf.setHostnameVerifier(
63 SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
65 HttpParams params = new BasicHttpParams();
66 HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
67 HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
69 SchemeRegistry registry = new SchemeRegistry();
70 registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
71 registry.register(new Scheme("https", sf, 443));
73 ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
75 return new DefaultHttpClient(ccm, params);
76 } catch (Exception e) {
77 return new DefaultHttpClient();