Possible to interact with webpage and Console - java

I want to create little Java application which can interact with secured website.
We have Railway site (https://irctc.co.in)
I want to create a console application from which I can send the usename and password to site as web post method and the result can be converted into console format.
Instead of opening the site in web browser, i would like to make it simpler using console window by avoiding other web elements and ads etc..
is it possible to do in Java? Please guide me.

I see two ways to do that. The first one is to implement java app based on top of HTTP request-respond engine. In this way you do not have to make any changes in your web-site but processing HTTP responds could be complicated due to design features. The second one is to create simple front-end service on Rails for special cases and interact with in your console app. For message format you can use JSON for example. This way IMHO is more suitable. Both way suggests use of HTTP libs stack, Apache has it there http://projects.apache.org/projects/commons_httpclient.html

Related

How to create a Java application that can input data into a Browser

I have recently started to learn Java and I have a created my first desktop application using Swing. I now however, want to start my own little project that involves creating a desktop application that can retrieve and input data on a webpage.
Ideally, I would want to input and retrieve data from a webpage that is open and visible in a web browser (preferably Chrome), rather than doing it all behind the scenes where it cant be seen. I need my program to have a GUI written in Swing, which takes values and then inputs them onto the webpage; I need to be able to take values from the open webpage as well as be able to press buttons - all through my desktop app.
In conclusion you can say I need to create an application that automates a web browser, however it needs to be able to do it to an already open browser/webpage. What should I do and use to achieve this?
You can achieve this by applet programming in Java which can send request data to server web page. Additional to this you can use Web Service mechanism to where you can get data from your swing form and bind the request in any appropriate transfer method like XML or Json and you can post it on to server endpoint. For example in JAVA you can use Jersey rest implementation for this.

Search indexing of AngularJS application in Java

I have AngularJS application already in production and I need to make it Google-friendly. I have read about Ajax crawling mechanism and I have following two problems:
1. Since I have backend written in Java, I have tried HtmlUnit to make static snapshots, but it didn't work well with AngularJS. How can I serve snapshots of my AngularJS pages using Java?
2. As I have mentioned, application is already published and it uses simple hash without !. E.g.: /#/about, /#/home. Is it possible to keep this scheme? Change to /#!/ would require modifications of all links and would break all existing links (posted on web).
Thanks in advance!
The SEO is always an issue with single-page application.
I suggest you make a quick implementation of Phantom.js to display already rendered page to google bots. Check out this link for more informations.
Phantom.js will be a gateway to which you redirect every indexing bot request, it will then render your app like a normal user will do, and then send back the rendered page to the bot.
Also, it would be better to change your /#/ to only /, it's better for your users and also SEO. You just need to redirect every request to the index.html page and to use '/#/' as fallback for old browser which doesn't support pushState.
You also have some paid solution like https://prerender.io/ which works beautifuly.

Wish to create desktop app that combines facebook and email accounts all in one go - stuck at the first hurdle?

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)

Communicate with web pages

I want to create an application that uses a shipping calculator on an external web page (http://www.bring.no/page?id=4994) to calculate a shipping.
The scenario will be that a user will fill out the fields, then he will have to submit, which will use the page's shipping calculator, then get the value (the shipping fee).
So basically what I want to make is a swing application that looks similar to the existing shipping calculator, pass arguments to it, and retrieve the result.
I have no idea how to do this. So any tips or hints would be highly appreciated! :)
Look at Apache HttpClient for communicating with websites and webservices from your Java Swing application.
You have to do an HTTP POST with the field names on the web page.
HttpClient mentioned by Jonas is fine and very good for complicated tasks because it is almost web browser. It supports sessions, cookies, HTTP headers etc. But in your case the task seems very simple and it is enough to use URL + URLConnection from JDK.

How to make data from a database accessible from other web applications

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.

Categories