wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Majic Cookie Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Majic Cookie Value" Watch "B&S: Majic Cookie Value" New topic
Author

B&S: Majic Cookie Value

Muhammad Shafique
Ranch Hand

Joined: Sep 30, 2006
Posts: 59
Hi,
So far, I assume that end user is responsible to select correct db file.

Can we use majic cookie value as db id so that user should change this value before changing db file? It creates many parameters like knowing of majic cookie value before selecting a new db file, etc.

Pleas comment!!

Shafique
Tim Anlauf
Greenhorn

Joined: Oct 11, 2006
Posts: 22
I used the cookie value for validating the DB File.
If a file is loaded it checks if the cookie value is right.

If this fail a InvalidDBFile exeption is thrown and handled by the client.
Muhammad Shafique
Ranch Hand

Joined: Sep 30, 2006
Posts: 59
I did the same thing but after encountering some issues, I removed it.
If we hard code cookie value, it means our application can't load another file with same schema but with different cookie value. If we let user enter and change cookie value it means user should know this value in advance for all new files or we should provide some extra utility to read and display this value for each file.

To save user from this, I decided to check the first 4 bytes for valid digits but, again, some invalid file can have all digits in first 4 bytes.

The final decision is:
Application server loads all files but when a client tries to connect, it simply thorws an exception for client if file is invalid.

There could be another approach. Server should send loaded db schema information for each client on very first call and client should accommodate all changes in data and display - too complex and above all "not required".

I think we can leave this on user to select valid file. Am I right?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Shafique,
If we hard code cookie value, it means our application can't load another file with same schema but with different cookie value.
Ahhh - but what if the cookie identifies the schema?

Take a look at the JavaRanch SCJD FAQ entries for cookies - you will see examples of how schemas change with different versions of the assignment. And investigation by JavaRanch members indicates that the cookie value is tied to the assignment version.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Rudolph Jen
Ranch Hand

Joined: Nov 17, 2006
Posts: 37
I also check the db-File and I check not only the magic cookie. Column-count/Field-length/.. are checked also.

Of course I limit the possible db-Files to only that one with the expected schema, BUT that is exactly what I want! IMHO is everything else a risky little game, what you only can lose.


SCJP<br />SCJD (in progress)
Muhammad Shafique
Ranch Hand

Joined: Sep 30, 2006
Posts: 59
Thanks guys,
My app does implement a fixed schema file. Any other file is loaded by the server but when client connects to the server, it recveices an exception bucause of different schema. This is what I wrote in last email.

Tim:
If this fail an InvalidDBFile exeption is thrown and handled by the client.


Assume remote server user uploads a wrong file and he is not aware of this, all clients shall recieve exceptions after sending connection requiests.
I think we should check it when user selects the db file before running the server (server side check). We should keep our client away from this. This is what I did and then removed. But after this discussion, I am going to add this again.

Thanks,
Shafique
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Majic Cookie Value
 
Similar Threads
[B&S] Verify database format?
schema structure validation ?
Question on System Requirement Specification
Magic cookie value and database name
NX: DB File Location in suncertify.properties