Persisting XML parsed object - java

I am using an xml parser to parse the login response from a request to a server. The xml content returns me sensitive data that uniquely identifies a client so i can fetch more details about the client in other part of my app later on.
In iOS, i would just create an object from the parsed values to hold the clientAuthenticationDetails and access it from anywhere else in the app using the appDelegate instance.
Is there a way for me to do the same in Android? I have read up on SharedPreferences but i am not sure if that is how others implement this sort of functionality or how secure it is since i do have sensitive client data in the response.

The easy option is to use Shared Preferences and write up some sort of method that will encrypt/decrypt the values in the preferences. Usually something like a DES encoder/decoder. you can find samples of using cypher anywhere.
The Harder option which usually doesn't make sense to implement is to store the account and credentials in the android AccountManager. I suggest going with the Shared Preferences option. Its enough in my opinion.

Related

Combine two http responses into one

Is it possible to send extra data attached to a http response via Java or Php?
My Website is a homework-platform: One User enters homeworks into a database, and all users can then see the homeworks on the website. The current load is very inefficient, as the browser makes two requests for eveything to load: One for the index file and one for the homeworks. For the homeworks request the client also sends settings of the user to the server, based on which the returned homeworks are generated by a Php script.
Now, I wonder, if it is possible, to combine those two requests into one? Is it maybe possible to detect the http request with Java or Php on the server, read the cookies (where the settings are saved), then get the homeworks from the database and send the data attached to the http response to the client? Or, even better, firstly only return the index file and as soon as possible and the homework data afterwards as a second response, because the client needs some time to parse the Html & build the DOM-tree when it can't show the homeworks anyway.
While browsing the web I stumbled across terms like "Server-side rendering" and "SPDY", but I don't know if those are the right starting points.
Any help is highly appreciated, as I'm personally very interested in a solution and it would greatly improve the load time of my website.
A simple solution to your problem is to initialize your data in the index file.
You would create a javascript object, and embed it right into the html, rendered by your server. You could place this object in the global namespace (such as under window.initData), so that it can be accessed by the code in your script.
<scipt>
window.initData = {
someVariable: 23,
}; // you could use json_encode if you use php, or Jackson if you use java
</script>
However, it is not a huge problem if your data is fetched in a separate server request. Especially when it takes more time to retrieve the data from the database/web services, you can provide better user experience by first fetching the static content very quickly and displaying a spinner while the (slower) data is being loaded.

Methods for storing data in java

In my software I want to store some data, that later they will be used. Something like a database to hold data:
Date, source path, destination path, and an array of file names.
Also another table to hold information about ftp connection:
Host, port, username and password
I need to know what methods are available to store and parse these data. I noticed there is a file type called .csv, is this an option for me? And is there any other option?
I think this depends a lot on how much data you want to store and how you need to access it.
If your application is going to be collecting a lot of structured data, such as user profiles, or product information, ie, if your application is all about a database then, yes as others have commented some sort of SQL database would make sense.
If your needs are more along the lines of just storing some "session" information, maybe like the last state of a GUI form for example, you might want to just serialize the data and write it to a simple text file.
One simple way to do that would be to serialize the data in a human readable format such as JSON and then write the text to a file, and then read it back and deserialize it when you need to restore it from storage.
If this is what you are looking for take a look at gson (from google), it provides a very easy what to convert a java object to JSON and back again.
JSON, is just text, so you can just read and write it to a simple text file.

How to parse big data (XML) in GWT

In my GWT application I am retrieving the XML data from a REST server. I am using Piriti XML parser https://code.google.com/p/piriti/wiki/Xml for deserializing the object and display in a table. As long as we are returning upto 1000 records everything is fine but with the big result it just hang and gives user message to stop the java script running in the back. Could someone please help me to find the best way to handle big data in GWT OR more precisely the best approach to parse big XML file in GWT.
Thanks a lot for all your suggestions.
The problem is that parsing a big XML document slows down the browser. And you need enough memory to hold the whole DOM plus your mapped objects in memory. The only solution is to avoid such situation. You have to adapt your REST service to be able to send only small chunks of data to the browser. So if you already have a paged table you only retrieve the data for the first page at the beginning. If the user wants to change the page you do another REST call to retrieve the data for the next page.
If you cannot change the the REST service itself you can create another server side service (on a server controlled by you) as a proxy. At first access you call the original REST service, store the XML at your own server and allow the client to retrieve only parts of that XML.

How to get URL in Java using the Remember The Milk API?

I want to write an Android application that uses the Remember the Milk API, but I can't figure out how to use the API's app authentication scheme. How do I generate the URL to authenticate my application with RTM?
I was looking for this too, and seems it was right in front of me. https://www.rememberthemilk.com/services/api/request.rest.rtm is where it explains the format.
Basically it's https://api.rememberthemilk.com/services/rest/ and then whatever you want to send.
So it would seem you'd start by getting the frob using https://api.rememberthemilk.com/services/rest/?method=rtm.auth.getFrob&api_key=123456789
Then when you get the frob back you'd use it to get a token with https://api.rememberthemilk.com/services/rest/?method=rtm.auth.getToken&api_key=123456789&frob=0a56717c3561e53584f292bb7081a533c197270c
Of course you'd replace that random key and frob with your actual key and whatever you get back from getFrob.
I'm about to try using this myself, so I'll try and post back if anything needs to be changed.

Java - store sensitive data

I develop application with Java.
I need to store some initial configuration data in some kind of file.
I want my app to be able to read this data, but I don't want user to do so.
Example : application loads IP from encrypted file. User sees like "dsda##21da#" so he won't bother doing anything :)
How should I do such a thing?
Thanx!
Are we talking about standard users or IT-savvy users?
For standard users i'd recommend to store the string base64 encoded. Or Just in an undefined binary format.
Otherwise... encryption with a hardcoded key?
If (as you say) you manage user passwords, you should not store them at all. Clear text, static keys, custom keys, it doesn't matter - someone with access to the data store and your program will always be able to retrieve them. What you do instead is use salt and a good hash function and store/compare only the hash values.
Possibly OT, but since you mentioned it is configuration data; I know I'd be a little peeved to have gibberish shown to me by an application. Either allow the users to see the data, and modify it at their risk ... or do not allow the configuration to be visible at all.
As a rule of thumb, if it is sensitive data ... don't store it in your application.

Categories