Search in sources :

Example 1 with AuthenticationManager

use of com.vodafone360.people.service.transport.http.authentication.AuthenticationManager in project 360-Engine-for-Android by 360.

the class ConnectionManager method onLoginStateChanged.

@Override
public synchronized void onLoginStateChanged(boolean loggedIn) {
    HttpConnectionThread.logI("ConnectionManager.onLoginStateChanged()", "Is logged in: " + loggedIn);
    stopActiveConnection();
    if (loggedIn) {
        mConnection = getAutodetectedConnection(mService);
    } else {
        mConnection = new AuthenticationManager(mDecoder);
    }
    QueueManager.getInstance().addQueueListener(mConnection);
    mConnection.startThread();
}
Also used : AuthenticationManager(com.vodafone360.people.service.transport.http.authentication.AuthenticationManager)

Example 2 with AuthenticationManager

use of com.vodafone360.people.service.transport.http.authentication.AuthenticationManager in project 360-Engine-for-Android by 360.

the class HttpConnectionThread method run.

/**
 * <p>
 * Sends out synchronous requests (for authentication) to the API and
 * asynchronous calls to the RPG as soon as there are requests on the
 * request queue.
 * </p>
 * <p>
 * If there are no requests the thread is set to wait().
 * </p>
 */
public void run() {
    AuthenticationManager authMgr = null;
    authMgr = new AuthenticationManager(this);
    while (mIsConnectionRunning) {
        // loops through requests and sends them
        // out as needed
        // TODO move this out. this should be
        authMgr.handleAuthRequests();
        if (null != mPollThread) {
            if (mIsFirstTimePoll) {
                try {
                    mPollThread.invokePoll(PollThread.SHORT_POLLING_INTERVAL, PollThread.DEFAULT_BATCHSIZE, PollThread.ACTIVE_MODE);
                } catch (Exception e) {
                    // we do not do anything here as it is not a critical
                    // error
                    logI("RpgHttpConnection.run()", "Exception while doing 1st time poll!!");
                } finally {
                    mIsFirstTimePoll = false;
                }
            }
            List<Request> requests = QueueManager.getInstance().getApiRequests();
            if ((requests.size() > 0) && mPollThread.getHasCoverage()) {
                if (null == mRpgUrl) {
                    // once we have a proper authMgr
                    try {
                        mRpgUrl = new URL(SettingsManager.getProperty(Settings.RPG_SERVER_KEY) + LoginEngine.getSession().userID).toURI();
                    } catch (Exception e) {
                        logE("RpgHttpConnectionThread.run()", "Could not set up URL", e);
                    }
                }
                mRetryCount = 0;
                List<Integer> reqIds = new ArrayList<Integer>();
                try {
                    byte[] reqData = prepareRPGRequests(requests, reqIds);
                    if (null != LoginEngine.getSession()) {
                        synchronized (mSendLock) {
                            if (mIsConnectionRunning) {
                                if (Settings.sEnableProtocolTrace) {
                                    HttpConnectionThread.logI("RpgTcpConnectionThread.run()", "\n \n \nSending a request: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + HessianUtils.getInHessian(new ByteArrayInputStream(reqData), true));
                                }
                                HttpResponse response = postHTTPRequest(reqData, mRpgUrl, Settings.HTTP_HEADER_CONTENT_TYPE);
                                if (mIsConnectionRunning && SettingsManager.getBooleanProperty(Settings.ENABLE_RPG_KEY) && handleRpgResponse(response, reqIds)) {
                                    mPollThread.startRpgPolling();
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    // add error to the
                    addErrorToResponseQueue(reqIds);
                // response queue
                }
            }
        }
        try {
            synchronized (mRunLock) {
                mRunLock.wait();
            }
        } catch (InterruptedException ie) {
            LogUtils.logE("HttpConnectionThread.run() Wait was interrupted", ie);
        }
    }
}
Also used : AuthenticationManager(com.vodafone360.people.service.transport.http.authentication.AuthenticationManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(com.vodafone360.people.service.io.Request) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with AuthenticationManager

use of com.vodafone360.people.service.transport.http.authentication.AuthenticationManager in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testSignalConnectionManager.

/**
 * Test signalConnectionManager() from RemoteService.
 *
 * @throws Exception Any kind of mapping exception
 */
@MediumTest
public final void testSignalConnectionManager() throws Exception {
    /**
     * Setup test preconditions (i.e. remoteService running). *
     */
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    assertNotNull("RemoteService should not be NULL", remoteService);
    assertTrue("Expected mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertEquals("Expected mConnection to be AuthenticationManager class", AuthenticationManager.class, FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection").getClass());
    /**
     * Perform test (i.e. disconnect). *
     */
    remoteService.signalConnectionManager(false);
    /**
     * Test if signalConnectionManager() called
     * ConnectionManager.disconnect() and set mIsConnected to false.
     */
    assertFalse("Expecting mIsConnected to be FALSE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertFalse("Expected mDecoder not to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /**
     * Perform second test (i.e. connect). *
     */
    remoteService.signalConnectionManager(true);
    /**
     * Test if signalConnectionManager() called
     * ConnectionManager.connect(), kickWorkerThread() and set mIsConnected
     * to true.
     */
    assertTrue("Expecting mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertNotNull("Expecting workerThread not to be NULL", FrameworkUtils.get(remoteService, "mWorkerThread"));
}
Also used : RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

AuthenticationManager (com.vodafone360.people.service.transport.http.authentication.AuthenticationManager)2 Intent (android.content.Intent)1 MediumTest (android.test.suitebuilder.annotation.MediumTest)1 RemoteService (com.vodafone360.people.service.RemoteService)1 Request (com.vodafone360.people.service.io.Request)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HttpResponse (org.apache.http.HttpResponse)1