1 / 16

Advanced Topics

Advanced Topics. BCIS 3680 Enterprise Programming. Overview. Cookies Mobile Apps Android SQLite. Cookie. A cookie is piece of textual data ( name-value pair) that is stored on the client hard drive.

lanai
Download Presentation

Advanced Topics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Topics BCIS 3680 Enterprise Programming

  2. Overview • Cookies • Mobile Apps • Android • SQLite

  3. Cookie • A cookie is piece of textual data (name-value pair) that is stored on the client hard drive. • The server saves a cookie to the client. In the future, when revisiting the same server, the client includes the cookie in its request for pages from the server. • Cookies can be set to persist for up to 3 years. • Browsers generally accept only 20 cookies from each site and 300 cookies in total. They can also limit each cookie to 4 KB. • A cookie is usually associated with the domain of the server that sets the cookie. But it can be set to associate to other domains.

  4. Pattern in Making a Cookie • Gather the info to store in the cookie (values of various properties of the cookie) • Create a Cookie object (needs cookie name and its value) • Set additional cookie attributes if necessary • Write cookie to the client

  5. Creating Cookies • With the exception of the session cookie, the programmer must create cookies manually. • Cookie is not an implicit object. To create a cookie, call the constructor of the Cookie class. Its signature is: Cookie(String cookieName, String cookieValue); • For example, Cookie c = new Cookie("Type", "Chocolate Chips"); • Neither the cookie name nor the cookie value should contain white space or any of the following characters: [ ] ( ) = , “ / ? @ : ;

  6. Setting Cookie Attributes • Before adding the cookie, you can set additional attributes of the cookie. • Typically attributes are maximum age, path, domain, etc. • To set an attribute, use its corresponding setter method: • setMaxAge(intmaxAgeInSeconds), e.g., c.setMaxAge(60*60*24*365); sets the age at 1 year. • setPath(String path), e.g., c.setPath("/") makes the cookie accessible anywhere in the entire application. • When you’re ready to write the cookie to the client, call the addCookie() method of the response object, for example: response.addCookie(c);

  7. Pattern in Reading a Cookie • Declare an array of Cookie objects • Retrieve all cookies from the client • Loop through array and compare the name of each cookie to that of the cookie you are looking for • Read attributes from the matching cookie

  8. Reading Cookies • All cookies are returned from the client as fields added to the HTTP request headers. • Before reading the cookies, first collect them all through the request object: request.getCookies(); • This method returns an array of Cookie objects that have been sent to client previously. • If there is no cookie in request, it returns null. • Before everything else, use an if statement to check whether cookies exist. • Proceed to steps in the next slide if array is not null.

  9. Reading Cookie Value and Attributes • Loop through the cookie array. • During each iteration, use the getName() method to retrieve the name of the cookie. • Compare the name of that cookie to the name of the cookie you’re looking for. • If found, use the getValue() method to retrieve the value stored in the cookie. • Use the proper get<Attribute>() method(s) to retrieve the value of additional cookie attribute(s) that is (are) of interest to you.

  10. Updating & Removing a Cookie • To update a cookie, write a cookie with the same name but the new value. • To remove a cookie, find the cookie in the cookies array, set its maximum age to 0.

  11. Mobile Apps • Android apps are Java applications. • An Android project includes, among other things: • An /src subfolder that contains source code files for the app. • The naming convention is the same for regular Java packages. So if an app is named edu.unt.Droid. The .java files for the app are then stored in /src/edu/unt/Droid. • A manifest file called AndroidManifest.xml, which contains configuration info for the app. Its function is similar to the manifest file in a JAR file.

  12. Developing Android Apps • Java SE JDK • Make sure it’s installed. • Android SDK • Makes use of the Java SE JDK. • Provides the API libraries and developer tools necessary to build, test, and debug apps for Android. • Download it from http://developer.android.com/sdk/index.html. • The ADT bundle contains a version of the Eclipse IDE pre-configured for Android development. • Eclipse IDE • If you already have the Eclipse IDE installed, you add a plug-in for the Android Developer Tools (ADT).

  13. SQLite • SQLite is an embedded DBMS. • Does not use the client-server architecture. • No independent service or process that manages the DBMS. • The DBMS engine is integrated in the application itself. • No network or server configuration is needed – less complex. • Uses one single file for a database. • Moving or backing up is as easy as copying the file. • Suited for embedded systems running limited OS. • Using the default configuration, the compiled SQLite library is less than 700 KB in size and requires less than 4 MB of memory to operate. Without advanced features, the size can decrease to 300 KB or less and the required memory to 256 KB.

  14. Traditional DBMS Architecture Source: Kreibich, J.A. Using SQLite, O’Reilly, 2010.

  15. SQLite Architecture Source: Kreibich, J.A. Using SQLite, O’Reilly, 2010.

  16. Programming SQLite • Although SQLite comes with a command line tool for running queries and performing administrative tasks, the native SQLite API is in C. • When building applications, use SQLite API and link to the SQLite DLLs. • When the apps runs and needs access to data, load the SQLite DLLs to interact with the database engine. • Extensions are available for scripting languages (e.g., JSP) to access the functionalities of the APIs. • A JDBC driver for SQLite can be obtained from https://bitbucket.org/xerial/sqlite-jdbc.

More Related