Package org.jboss.aerogear.unifiedpush.message.helper

Examples of org.jboss.aerogear.unifiedpush.message.helper.ChromePackagedAppTokenCache


     */

    protected String fetchAccessToken(ChromePackagedAppVariant chromePackagedAppVariant) {
        HttpURLConnection accessTokenConn = null;
        JSONParser jsonParser = new JSONParser();
        ChromePackagedAppTokenCache accessTokenObject = null;
        String accessToken = null;
        long expireTime = 0; // in milliseconds

        try {
            // Not good practice to always get a new access token. so only get one if it is expired or null
            accessTokenObject = accessTokenMap.get(chromePackagedAppVariant.getClientId());

            if( accessTokenObject != null ) {
                accessToken = accessTokenObject.getAccessToken();
                expireTime = accessTokenObject.getExpiresIn();
            }

            if( accessToken == null || expireTime < new Date().getTime() ) {
                accessTokenConn = refreshAccessToken(chromePackagedAppVariant);
                String stringResponse = getString(accessTokenConn.getInputStream());
                accessToken = ((JSONObject)jsonParser.parse(stringResponse)).get("access_token").toString();
                String expiresIn = ((JSONObject)jsonParser.parse(stringResponse)).get("expires_in").toString();

                // Convert to millis
                long ex = Long.parseLong( expiresIn );
                expireTime = new Date().getTime() + (ex * 1000);

                if( accessTokenObject == null ) {
                    accessTokenObject = new ChromePackagedAppTokenCache();
                }

                accessTokenObject.setAccessToken(accessToken);
                accessTokenObject.setExpiresIn(expireTime);

                accessTokenMap.put(chromePackagedAppVariant.getClientId(),accessTokenObject);
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Error during Post execution to GCM for Chrome Network For access token refresh", e);
View Full Code Here


     */

    protected String fetchAccessToken(ChromePackagedAppVariant chromePackagedAppVariant) {
        HttpURLConnection accessTokenConn = null;
        JSONParser jsonParser = new JSONParser();
        ChromePackagedAppTokenCache accessTokenObject = null;
        String accessToken = null;
        long expireTime = 0; // in milliseconds

        try {
            // Not good practice to always get a new access token. so only get one if it is expired or null
            accessTokenObject = accessTokenMap.get(chromePackagedAppVariant.getClientId());

            if( accessTokenObject != null ) {
                accessToken = accessTokenObject.getAccessToken();
                expireTime = accessTokenObject.getExpiresIn();
            }

            if( accessToken == null || expireTime < new Date().getTime() ) {
                accessTokenConn = refreshAccessToken(chromePackagedAppVariant);
                String stringResponse = getString(accessTokenConn.getInputStream());
                accessToken = ((JSONObject)jsonParser.parse(stringResponse)).get("access_token").toString();
                String expiresIn = ((JSONObject)jsonParser.parse(stringResponse)).get("expires_in").toString();

                // Convert to millis
                long ex = Long.parseLong( expiresIn );
                expireTime = new Date().getTime() + (ex * 1000);

                if( accessTokenObject == null ) {
                    accessTokenObject = new ChromePackagedAppTokenCache();
                }

                accessTokenObject.setAccessToken(accessToken);
                accessTokenObject.setExpiresIn(expireTime);

                accessTokenMap.put(chromePackagedAppVariant.getClientId(),accessTokenObject);
            }
        } catch (IOException e) {
            logger.severe("Error during Post execution to GCM for Chrome Network For access token refresh", e);
View Full Code Here

     */

    protected String fetchAccessToken(ChromePackagedAppVariant chromePackagedAppVariant) {
        HttpURLConnection accessTokenConn = null;
        JSONParser jsonParser = new JSONParser();
        ChromePackagedAppTokenCache accessTokenObject = null;
        String accessToken = null;
        long expireTime = 0; // in milliseconds

        try {
            // Not good practice to always get a new access token. so only get one if it is expired or null
            accessTokenObject = accessTokenMap.get(chromePackagedAppVariant.getClientId());

            if( accessTokenObject != null ) {
                accessToken = accessTokenObject.getAccessToken();
                expireTime = accessTokenObject.getExpiresIn();
            }

            if( accessToken == null || expireTime < new Date().getTime() ) {
                accessTokenConn = refreshAccessToken(chromePackagedAppVariant);
                String stringResponse = getString(accessTokenConn.getInputStream());
                accessToken = ((JSONObject)jsonParser.parse(stringResponse)).get("access_token").toString();
                String expiresIn = ((JSONObject)jsonParser.parse(stringResponse)).get("expires_in").toString();

                // Convert to millis
                long ex = Long.parseLong( expiresIn );
                expireTime = new Date().getTime() + (ex * 1000);

                if( accessTokenObject == null ) {
                    accessTokenObject = new ChromePackagedAppTokenCache();
                }

                accessTokenObject.setAccessToken(accessToken);
                accessTokenObject.setExpiresIn(expireTime);

                accessTokenMap.put(chromePackagedAppVariant.getClientId(),accessTokenObject);
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Error during Post execution to GCM for Chrome Network For access token refresh", e);
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.unifiedpush.message.helper.ChromePackagedAppTokenCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.