Background: I am creating an Android app that will get data from a web page (that will be created by me) and parse it. This data can be in XML or JSON format. I would personally prefer JSON but if there is an easy way to achieve it with XML, I would most certainly use it. The app is a Live Score app. So, my page would have XML or JSON with the current score, the current time and minute by minute commentary.
Progress so far: My app is able to read and parse JSON data using the HttpGet and HttpResponse methods alongwith the JSONObject. My concern however is that I am unable to create a dynamic web page. I tried to create and host a page using Google App Engine and Python. The problem was that everytime I'd make changes to the JSON file, I would need to re-deploy the program from the Google App Engine to ensure that the changes are reflected on the URL. I felt this was relatively time consuming.
My Questions:
1.) Is there any way to host a dynamic web page? Preferably with Eclipse and Java. One that I can add the commentary to, as and when an event occurs and it is reflected on the page.
2.) I am not good with Web Services but would GET and POST be a better alternative as opposed to deploying my JSON file with the GAE? If so, how can I go about with that?
3.) Is GCM a good alternative for all this? I tried reading up some of the documentation but it seemed really complex to me.
Thanks.
Sure, it's called AJAX. It requires client-side (browser) javascript code making a request and server-side java code making a response. See: How to use Servlets and Ajax?
Yes, you should use POST and GET to create/retrieve data on server. Your server-side java code should receive data on POST, save it to datastore, and then serve it back on GET. I'd suggest using objectify library for storing data, and GSON for converting java objects to JSON.
GCM is an asynchronous way to notify Android apps (aka notifications) when apps are not running. While with GCM it's possible to send data both ways, it's more complex then plain POST/GET and also only works on Android devices with Google Play.
Related
I would like to program a WebService embedded on my android device (not the client part).
I've been evaluating Restlet Framework (Restlet) but i don't know if I go on the right way.
What do you think? Is that framework viable for my goal?
Any suggestion is welcome!
Thank you so much!
Regards.
You should check whether Restlet is compliant with android,
not just from server side code, but also from client side code (respectively).
This means for example that every JAR that Restlet framework depends on has to contain code that is compliant with Android.
An alternative approach would be to run a simple HTTP server on your device, for example the following nano http server I read about.
Another interesting project you should check is jetty for android which will hopefully give you support for servlet API as well.
Yes, you will have to spend some time on developing mapping requests and building resource handling logic, but that task is not that difficult:
A. You already have Android code for JSON processing -
For example, look here
B. Using the Java URL object you can analyze the URL of the request and understand which resource you should handle (i.e - add resource to collection, fetch collections, etc).
C. After performing the CRUD operation (i.e - store your resource in some SQLIte table), you can send back a response, and once again, composing JSON if needed is easy.
Im currently creating a custom surveillance application. And i was curious is it possible to take the live stream and and redirect it to a webpage via an ajax request. If so whats an example of how the ajax request would look. I'm working on the video feed aspect with java and was planning on using a servlet to push video feed to a request by the user whos on the appropriate webpage.
Only by using ajax + servlet you can not do that, but you need to have a media streaming server to generate the streaming and you can use servlet (and ajax) to redirect it to the custom page.
one good open source media streaming server I can suggest is the Red5 server developed with Java. They have a special module called red5-web which you can simply used for your requirement with a few configurations. It uses RTP/RTMP protocols to do that.
refer HERE for nice tutorial.
And also you can refer to HTTP streaming also using VLCJ.
A very good example can be found HERE
I hope you can get a help through those links.
this is my first post on stackoverflow.
I am quite good at Java SE and client side Java Programming, but new to Java web development.
When I search for Java webframeworks, a huge amount of framework are offered, but nothing really seems to fit my needs.
What I actually want is a dumb server and a smart client.
I want the client to ask for certain information and the server to return the requested information in a xml or json format, so that the client itself manages the data.
In most cases the webframeworks render the html pages etc. on the server side, but I just want for example to use AJAX or the android xml parser to get the information and then fill the UI on the clientside.
I am not sure, if Webservices are the right thing for me, because I want to make several async requests to the server.
Or should I simply use servlets, which just return the right xml on request.
A second thing is how to handle the authorization and authentication of the users, which send the request to the webserver.
I do not want to allow everyone to receive the xml or json, which is generated by the server.
In short:
Is there a java based webframework, which can handle authorization and authentication of users and just returns xml or json to a smart client?
Which java based webframework fits best to my needs?
On the following webpage my aim is described, but unfortunately there is no hint how to implement such a "dumb" server...
http://seng130.wordpress.com/lectures-2/web-application-architecture/
You will likely need to use multiple frameworks. Spring-Security to handle your url intercept based on authority. Then use Servlet with Spring-MVC to handle the request within the Controller methods. Tutorial here: http://static.springsource.org/spring-security/site/tutorial.html You can have those methods return string values of JSON or XML. I would suggest using Jackson to convert your objects to a JSON form on the fly and the javax libraries for XML.
Example of Spring-MVC with Jackson:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
Example with Jersey servlet and Jackson
http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
first poster :)
As the title says, I am looking to create a desktop app which will notify me of changes on facebook and new emails, and the facebook part (the first part I've tried) is baffling me. I've never worked with an api before, and have no idea how to integrate facebook's api with this desktop helper I want to create. I will be using java to create this desktop helper.
Thanks in advance!
Here are few pointers for you to get started. Please feel free to ask for clarifications and I will edit my answer accordingly:
For facebook, you can actually pull all those info via their API. There are a lot of types for API, but Facebook specifically use REST API over http.
To simplify, think of it as making an http call with specific parameters and you will be getting an output back.
In order to use facebook API you need to understand their protocol including authentication/login and how to request for things that you want. This would require some reading to their documentation which is pretty complete and available at http://developers.facebook.com/docs/.
For the description of their API URL and the input/output documentation, you could directly jump to Graph API Documentation http://developers.facebook.com/docs/reference/api/.
In order to call their API via HTTP from Java, you could leverage HttpClient library from Apache Http Components project http://hc.apache.org/. They have plenty of tutorial and examples for how to make http call using HttpClient
For combining with all other emails accounts (per your question), you need to deal with SMTP or IMAP (whichever email protocol that you are planning to combine with Facebook). This is already built-in to Java via their Java Mail API collection
You then can poll this data on interval basis to get an update from Facebook and your mails
Once you have figured out how to get the data, the rest is just following a good MVC framework. That means separating out your presentation, data and controller (application logic). Make sure that you are separating the classes for #1 and #2 and each of them put their data to normalized data format that then get feed to your View (presentation layer)
I have a database from which I want to expose data.
Ideally I would like to be able to just add a URL into some other web page and that URL would then call the correct datum using the web app I use to interact with the database.
Would a web service be the best option?
Looks to me like a perfect job for ODATA:
The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today. OData does this by applying and building upon Web technologies such as HTTP, Atom Publishing Protocol (AtomPub) and JSON to provide access to information from a variety of applications, services, and stores.
See it action (showing query results in a browser is just one way to use ODATA).
A URL-based solution as you describe would only work if:
a) the web app framework you use can resolve the URL automatically as it parses and sends the HTML to the browser, or
b) the browser resolves the URL (e.g. the IMG element)
If the web app framework you use can resolve the URL (or if you can extend it so that it does), then you still need something that listens at that URL and retrieve the correct element from the database.
The approach here depends on whether you are doing Ajax style web pages or simple HTML, where each UI update refreshes the whole page.
The latter, a traditional page by page web site, it probably the simplest thing. For this explore JSP technologies. The idea is that you write what looks like an HTML page, but embed in it references to Java objects (or even Java code). In this case you should read up on simple frameworks such as Struts. The broad-brish idea is that you get this sequence of processing
Request arrives from Broswer, interpret it to figure out what the user wants to see
Some Java code talks to the Database gets data puts it in a Java Object
A JSP is chosen, that JSP picks items from the Java Object we just prepared
The JSP renders HTML which is sent to the Browser
In the case of Ajax, JavaScript in the Browser decides to display some data and calls a service to get it. So here, yes a "Web Service" of some kind is needed. Usually we use REST services, which return a payload in JSON format, effectively the data is transferred as JavaScript.
There are plenty of libraries for creating RESTful Web Services, for example Apache Wink.