Search in sources :

Example 1 with DecoderThread

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

the class PollThread method startConnection.

/**
 * Starts the connection.
 */
protected synchronized void startConnection(DecoderThread decoder) {
    mDecoder = decoder;
    setHttpClient();
    mIsConnectionRunning = true;
    try {
        URL url = new URL(SettingsManager.getProperty(Settings.RPG_SERVER_KEY) + LoginEngine.getSession().userID);
        mUrl = url.toURI();
        mHeader = new RpgHeader();
        mMode = ACTIVE_MODE;
        Thread t = new Thread(this);
        t.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RpgHeader(com.vodafone360.people.service.io.rpg.RpgHeader) URL(java.net.URL) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DecoderThread(com.vodafone360.people.service.transport.DecoderThread)

Example 2 with DecoderThread

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

the class RemoteService method onCreate.

/**
 * Creation of RemoteService. Loads properties (i.e. supported features,
 * server URLs etc) from SettingsManager. Creates IPeopleServiceImpl,
 * NetworkAgent. Connects ConnectionManager creating Connection thread(s)
 * and DecoderThread 'Kicks' worker thread.
 */
@Override
public void onCreate() {
    LogUtils.logV("RemoteService.onCreate()");
    SettingsManager.loadProperties(this);
    mIPeopleServiceImpl = new PeopleServiceImpl(this, this);
    mNetworkAgent = new NetworkAgent(this, this, this);
    // Create NativeContactsApi here to access Application Context
    NativeContactsApi.createInstance(getApplicationContext());
    EngineManager.createEngineManager(this, mIPeopleServiceImpl);
    mNetworkAgent.onCreate();
    mIPeopleServiceImpl.setNetworkAgent(mNetworkAgent);
    /**
     * The service has now been fully initialised. *
     */
    mIsStarted = true;
    kickWorkerThread();
    final MainApplication mainApp = (MainApplication) getApplication();
    mainApp.setServiceInterface(mIPeopleServiceImpl);
    if (VersionUtils.is2XPlatform()) {
        mAccountsObjectsHolder = new NativeAccountObjectsHolder(((MainApplication) getApplication()));
    }
    final UserDataProtection userDataProtection = new UserDataProtection(this, mainApp.getDatabase());
    userDataProtection.performStartupChecks();
}
Also used : NetworkAgent(com.vodafone360.people.service.agent.NetworkAgent) UserDataProtection(com.vodafone360.people.service.utils.UserDataProtection) MainApplication(com.vodafone360.people.MainApplication)

Example 3 with DecoderThread

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

the class HeartbeatSenderThreadTest method testSendHeartbeat_valid.

@MediumTest
public void testSendHeartbeat_valid() {
    byte[] header = { (byte) 0xFF, (byte) 0xFF, (byte) 0x64 };
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
    null);
    AuthSessionHolder authHolder = new AuthSessionHolder();
    authHolder.userID = 007;
    authHolder.sessionID = "SESS_ID";
    authHolder.sessionSecret = "SESS_SECRET";
    authHolder.userName = "James_Bond";
    LoginEngine.setTestSession(authHolder);
    hbSender.setOutputStream(baos);
    try {
        hbSender.sendHeartbeat();
    } catch (Exception e) {
        fail("sendHeartbeatTest() should not throw an Exception here " + e.toString());
    }
    try {
        baos.flush();
        baos.close();
    } catch (IOException ioe) {
    }
    byte[] payload = baos.toByteArray();
    if (null != payload) {
        boolean isHeaderOk = false, isEndingOk = false, isPayloadLenOk = false;
        if ((header[0] == payload[0]) && (header[1] == payload[1]) && (header[2] == payload[2])) {
            isHeaderOk = true;
        } else {
            fail("RPG Header was malformed!");
        }
        if (payload[payload.length - 1] == ((byte) 0x7A)) {
            isPayloadLenOk = true;
        } else {
            fail("Message End was malformed! Char was: " + payload[payload.length - 1]);
        }
        int payloadSize = byteArrayToInt(new byte[] { payload[11], payload[12], payload[13], payload[14] }, 0);
        if (payloadSize == (payload.length - 16)) {
            isEndingOk = true;
        } else {
            fail("Payload length is not okay: " + payloadSize + " vs. " + (payload.length - 16));
        }
        assertTrue((isHeaderOk && isEndingOk && isPayloadLenOk));
    } else {
        fail("HB-Payload was null!");
    }
}
Also used : AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with DecoderThread

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

the class HeartbeatSenderThreadTest method testSendHeartbeat_exception.

@MediumTest
public void testSendHeartbeat_exception() {
    MockByteArrayOutputStream baos = new MockByteArrayOutputStream();
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
    null);
    AuthSessionHolder authHolder = new AuthSessionHolder();
    authHolder.userID = 007;
    authHolder.sessionID = "SESS_ID";
    authHolder.sessionSecret = "SESS_SECRET";
    authHolder.userName = "James_Bond";
    LoginEngine.setTestSession(authHolder);
    hbSender.setOutputStream(baos);
    try {
        baos.close();
    } catch (IOException ioe) {
    }
    // IOException Test
    try {
        hbSender.sendHeartbeat();
    } catch (IOException ioe) {
        // we succeed because we expect an IOE to be thrown here!
        assertTrue(true);
    } catch (Exception e) {
        fail("We should not have received a generic exception, but an IOException!");
    }
    baos = null;
    // NullPointerException Test
    hbSender.setOutputStream(null);
    try {
        hbSender.sendHeartbeat();
    } catch (IOException ioe) {
        fail("We should not have received an IOException, but a generic (NP-)Exception!");
    } catch (Exception e) {
        // we succeed because we expect an IOE to be thrown here!
        assertTrue(true);
    }
}
Also used : AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) DecoderThread(com.vodafone360.people.service.transport.DecoderThread) IOException(java.io.IOException) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with DecoderThread

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

the class HeartbeatSenderThreadTest method testStopConnection.

@Suppress
@MediumTest
public void testStopConnection() {
    DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream());
    MockTcpConnectionThread connThread = new MockTcpConnectionThread(new DecoderThread(), null);
    MockHeartbeatSenderThread hbSender = new MockHeartbeatSenderThread(connThread, null, // QUICKFIX: Not sure about this value
    null);
    hbSender.setOutputStream(dos);
    hbSender.startConnection();
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }
    hbSender.stopConnection();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    assertNotNull(hbSender.getConnectionThread());
    if (null != hbSender.getConnectionThread()) {
        assertFalse(hbSender.getConnectionThread().isAlive());
        try {
            dos.write(1);
            fail("Should not be able to write here!");
        } catch (IOException e) {
            assertTrue(true);
        }
    }
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

MediumTest (android.test.suitebuilder.annotation.MediumTest)11 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)11 IOException (java.io.IOException)7 Suppress (android.test.suitebuilder.annotation.Suppress)6 MockTcpConnectionThread (com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread)4 BufferedInputStream (java.io.BufferedInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 Intent (android.content.Intent)1 MainApplication (com.vodafone360.people.MainApplication)1 RemoteService (com.vodafone360.people.service.RemoteService)1 NetworkAgent (com.vodafone360.people.service.agent.NetworkAgent)1 RpgHeader (com.vodafone360.people.service.io.rpg.RpgHeader)1 HttpConnectionThread (com.vodafone360.people.service.transport.http.HttpConnectionThread)1 UserDataProtection (com.vodafone360.people.service.utils.UserDataProtection)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1