Example usage for android.net SSLSessionCache SSLSessionCache

List of usage examples for android.net SSLSessionCache SSLSessionCache

Introduction

In this page you can find the example usage for android.net SSLSessionCache SSLSessionCache.

Prototype

public SSLSessionCache(Context context) 

Source Link

Document

Create a session cache at the default location for this app.

Usage

From source file:fast.simple.download.http.DownloadHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 * /*from  w  w w . j av  a2s . com*/
 * @param userAgent
 *            to report in your HTTP requests
 * @param context
 *            to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static DownloadHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller. Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    //HttpClientParams.setRedirecting(params, true);

    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https",
            SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new DownloadHttpClient(manager, params);
}

From source file:com.iframe.source.publics.download.AndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 * //w  w  w  .  ja va2s. c o  m
 * @param userAgent
 *            to report in your HTTP requests
 * @param context
 *            to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller. Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https",
            SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}

From source file:com.example.xoeracustomer.service.volley.toolbox.AndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests
 * @param context to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 *///from w  ww . j  a  v  a2s .c  o  m
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    /* schemeRegistry.register(new Scheme("https",SSLCertificateSocketFactory.getHttpSocketFactory(
        SOCKET_OPERATION_TIMEOUT, sessionCache), 443));*/

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}

From source file:com.android.mms.service.http.NetworkAwareHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests
 * @param context to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 *//*from w ww  . j a  va2s. c  o  m*/
public static NetworkAwareHttpClient newInstance(String userAgent, Context context, NameResolver resolver,
        boolean shouldUseIpv6) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https",
            SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));

    /*
     * CHANGE FOR MmsService: using a different ClientConnectionManager which
     * uses a custom name resolver and can specify address type
     */
    ClientConnectionManager manager = new NetworkAwareThreadSafeClientConnManager(params, schemeRegistry,
            resolver, shouldUseIpv6);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new NetworkAwareHttpClient(manager, params);
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i("XMPPService", "Service started");

    getApplication().registerActivityLifecycleCallbacks(mActivityCallbacks);

    this.ownPresenceStanzaFactory = new OwnPresenceFactoryImpl();
    this.dbHelper = DatabaseHelper.getInstance(this);
    this.connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    this.dataRemover = new DataRemover(this.dbHelper);

    SSLSessionCache sslSessionCache = new SSLSessionCache(this);
    this.sslSocketFactory = SSLCertificateSocketFactory.getDefault(0, sslSessionCache);

    this.rosterProvider = new RosterProviderExt(this, dbHelper, new RosterProviderExt.Listener() {
        @Override//w  ww .j a  v  a 2  s .com
        public void onChange(Long rosterItemId) {
            Uri uri = rosterItemId != null ? ContentUris.withAppendedId(RosterProvider.ROSTER_URI, rosterItemId)
                    : RosterProvider.ROSTER_URI;

            Log.i(TAG, "Content change: " + uri);
            getApplicationContext().getContentResolver().notifyChange(uri, null);

        }
    }, "roster_version");
    rosterProvider.resetStatus();

    this.mobileModeFeature = new MobileModeFeature(this);

    this.presenceHandler = new PresenceHandler(this);
    this.messageHandler = new MessageHandler(this);
    this.chatProvider = new org.tigase.messenger.jaxmpp.android.chat.ChatProvider(this, dbHelper,
            new org.tigase.messenger.jaxmpp.android.chat.ChatProvider.Listener() {
                @Override
                public void onChange(Long chatId) {
                    Uri uri = chatId != null ? ContentUris.withAppendedId(ChatProvider.OPEN_CHATS_URI, chatId)
                            : ChatProvider.OPEN_CHATS_URI;
                    getApplicationContext().getContentResolver().notifyChange(uri, null);
                }
            });
    chatProvider.resetRoomState(CPresence.OFFLINE);
    this.mucHandler = new MucHandler();
    this.capsCache = new CapabilitiesDBCache(dbHelper);

    IntentFilter screenStateReceiverFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenStateReceiverFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenStateReceiver, screenStateReceiverFilter);

    registerReceiver(presenceChangedReceiver, new IntentFilter(CLIENT_PRESENCE_CHANGED_ACTION));

    registerReceiver(connReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));

    multiJaxmpp.addHandler(
            StreamManagementModule.StreamManagementFailedHandler.StreamManagementFailedEvent.class,
            new StreamManagementModule.StreamManagementFailedHandler() {
                @Override
                public void onStreamManagementFailed(final SessionObject sessionObject,
                        XMPPException.ErrorCondition condition) {
                    if (condition != null && condition.getElementName().equals("item-not-found")) {
                        XMPPService.this.rosterProvider.resetStatus(sessionObject);
                    }
                }
            });
    multiJaxmpp.addHandler(DiscoveryModule.ServerFeaturesReceivedHandler.ServerFeaturesReceivedEvent.class,
            streamHandler);
    multiJaxmpp.addHandler(JaxmppCore.LoggedInHandler.LoggedInEvent.class, jaxmppConnectedHandler);
    multiJaxmpp.addHandler(JaxmppCore.LoggedOutHandler.LoggedOutEvent.class, jaxmppDisconnectedHandler);
    // multiJaxmpp.addHandler(SocketConnector.ErrorHandler.ErrorEvent.class,
    // );
    //
    // this.connectorListener = new Connector.ErrorHandler() {
    //
    // @Override
    // public void onError(SessionObject sessionObject, StreamError
    // condition, Throwable caught) throws JaxmppException {
    // AbstractSocketXmppSessionLogic.this.processConnectorErrors(condition,
    // caught);
    // }
    // };
    multiJaxmpp.addHandler(PresenceModule.ContactAvailableHandler.ContactAvailableEvent.class, presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.ContactUnavailableHandler.ContactUnavailableEvent.class,
            presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.ContactChangedPresenceHandler.ContactChangedPresenceEvent.class,
            presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.SubscribeRequestHandler.SubscribeRequestEvent.class,
            subscribeHandler);

    multiJaxmpp.addHandler(MessageModule.MessageReceivedHandler.MessageReceivedEvent.class, messageHandler);
    multiJaxmpp.addHandler(MessageCarbonsModule.CarbonReceivedHandler.CarbonReceivedEvent.class,
            messageHandler);
    multiJaxmpp.addHandler(ChatStateExtension.ChatStateChangedHandler.ChatStateChangedEvent.class,
            messageHandler);
    multiJaxmpp.addHandler(AuthModule.AuthFailedHandler.AuthFailedEvent.class,
            new AuthModule.AuthFailedHandler() {

                @Override
                public void onAuthFailed(SessionObject sessionObject, SaslModule.SaslError error)
                        throws JaxmppException {
                    processAuthenticationError((Jaxmpp) multiJaxmpp.get(sessionObject));
                }
            });

    multiJaxmpp.addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.MessageErrorHandler.MessageErrorEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.YouJoinedHandler.YouJoinedEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.StateChangeHandler.StateChangeEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.PresenceErrorHandler.PresenceErrorEvent.class, mucHandler);

    IntentFilter filterAccountModifyReceiver = new IntentFilter();
    filterAccountModifyReceiver.addAction(LoginActivity.ACCOUNT_MODIFIED_MSG);
    filterAccountModifyReceiver.addAction(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
    registerReceiver(accountModifyReceiver, filterAccountModifyReceiver);

    startKeepAlive();

    updateJaxmppInstances();
    // connectAllJaxmpp();
}