Fetch data from other Website [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I make a raw HTTP request in Java?
I am monitoring a website which updates transaction data every few seconds, so for having better performance I need to store those data and analyze them (like plotting, etc.).
My question is how I can make a request to that server by Java EE and get the values which are available in a table in that site?
I should add that I do not search a solution by .net or php, and I have tried by JQuery, java HTTPRequest but I did not found the solution.
Any idea will be appreciated.

If they provide some sort of API/webservice that is best way to communicate,
if not and if the source site doesn't have any issue with the data you are taking from them you could use HTTP requests to get HTML response and parse the portion you want using JSoup

Have you actually tried anything yourself yet? SO is not a code generation tool.
That being said, this seems to be of interest: How do I make a raw HTTP request in Java?

Related

Which approach is better to handle HTTP (rest PHP+MYSQL structure) with Android (Java)? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have started a new personal project in which I am doing an app for Android with database handling. I am currently doing the login process and I have a few questions before starting to code.
I read that using a RESTful service is the best way to handle databases, at least is was said to be the safest. Java makes the HTTP connection with the PHP file in my server and the PHP file executes the MYSQL sentence. Is this true? Are there more safe options?
At the time of making the HTTP requests, I saw few options: Volley library, Retrofit library, RxJava with Retrofit and using Asynctask with Java and Apache basic libraries (as it can be seen in this tutorial: https://www.tutorialspoint.com/android/android_php_mysql)
I also saw in a Volley tutorial that the data is converted to JSON. Let's say I am not fetching entire rows or column. It is useless then to use JSON? I know that for the sake of future JSON object would be something accesible for everyone, but given is a personal project I could even make a split(",") script to retrieve the data.
For example; if I make a JSON object I would have to write "[key] Result: [pair] fail/ok" if I make a simple retrieve of the String object I would get "Failed" or "Success" directly.
Does it make sense what I am trying to ask?
Firstly you need to make sure you understand what is web service before you create your own web service.
The web service can be achieved by many efficient micro frameworks. For example do some research on Slim PHP, Laravel's lumen, etc. This will process the request sent from Android App, process the data & sends back response to the App. While processing, you will have to fetch data or make changes in the database.
Considering android app, you can choose default http client or third party libraries like Okhttp3, retrofit, volley etc. These are the clients to call the web service & get the response from the server.

Next part is to choose request &response body. This can be JSON, XML etc. JSON is recommended. To handle this JSON response, you default JSON parser to use GSON library.
Have a look at the Weather API by Yahoo, it's a free web service you can call, and is quite well documented. You can find the web service calls & JSON examples here. https://developer.yahoo.com/weather/documentation.html
You have quite a broad set of requirements in your question, please try what I've recommended then come back with refined further questions
Good luck!

How to retrieve contents on a web page using Java [duplicate]

This question already has answers here:
Using Java to pull data from a webpage?
(5 answers)
Closed 5 years ago.
Can anyone suggest me a way to retrieve contents on a web page page using java?
I need to redirect to a web page, expand a block, and copy certain strings under it. Now I need to feed part of that string into another text box on a different page. How can this be done using java?
You should use Selenium (http://www.seleniumhq.org/). You can look up a tutorial on how to properly implement it for pulling data from websites. Assuming this is your own website, however, you can use a Socket.IO connection to communicate data.
Have you looked at Jsoup? https://jsoup.org/ it is a nice library for getting documents, parsing, etc.

How to use Java in PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to use WordPress for my web development, which is PHP written, including the database connection to MySql. The whole thing is PHP. But I need to use Java to back-end data processing and a number of existing Java open source libraries.
A google search shows that PHP/Java Bridge is a way to go. Is that bridge best way to go? If everything is PHP with WordPress, is still a way to use J2EE technologies, inlcuding JSP, Servelet, etc?
edit
Java is needed becaue I need to run machine learning algorithms, libraries for which are only available for Java. Also, PHP may run into efficiency issues when it's used to process large amount of data.
A good example of libraries in Java I am going to use is those processing Big Data, which are mainly Java, like Hadoop.
The very simple answer here is don't
PHP is designed to, at every page request start up, execute a small series of scripts as a single operation, output the data associated with those scripts and then immediately die after generating the output. It literally does not have time to wait for your Java programs and libraries to do their thing, so don't try to put one in the other, which is why PHP scripts that rely on databases tend to have heavily optimised databases for immediate retrieval, instead of general databases that rely on joins and selects that take a few seconds to form the correct data response. Neither PHP or users browsing websites have time for that.
What you could do is wrap your java tools in Java Servlets and have them running on the same server/host that your PHP instance is running from, so that your scripts can access the Servlets as http://127.0.0.1:7254/... as it would any other restful API it needs to use while generating your script output, as long as you make damn sure that you're not going to make PHP wait: if it has to send data to your tools, that is a post-and-forget operation, PHP should not be getting any response back other than an immediate "data accepted" or "data rejected" before the data is then actually handled by your tools. If you need to post data and then get a result back, you're going to have to use two calls. One to post the data, and then a second call to request the result of that posting.
For instance:
web page generation chain: WordPress CMS based on PHP -> your database
web input for processing: WordPress CMS based on PHP -> Java Servlets for machine learning
data processing chain: Java Servlets for machine learning -> your database
So you build pages only based on what's in your data base, you post data to your java Servlets only to get them to start doing something and you don't wait for a response, their result will end up in your database and you'll get it for pages once it's in, and your java programs do what they need to do independently of your WordPress setup.
And if you're going to do that, you should probably write that functionality as a WordPress plugin that can talk to your Java Servlets.
And now you have a second project you need to work on: turning your java programs into web servers. Not terribly complex, but definitely something you're going to lose some time on doing right (because you'll need to wrap with servlets, as well as make sure you can have those running without crashing on the same server as your wordpress instance, which is always fun)

How to consume a JSON web service in Java [duplicate]

This question already has answers here:
Parsing JSON from URL
(8 answers)
Closed 8 years ago.
I have a web service exposed to me which returns a json object.
I've been provided with a url http://address.to.web.service:8080/game
If enter this in any browser i get a json output.
In my code, I've already implemented logic to populate a web page but using a local json file.
I now need to wire it up with the output of the web service.
Can someone help me understand what might be the simplest way to go for this problem?
You need to connect to your webservice, read the full response and convert it to a JSON array. You do not specify which part of the problem you're having problems with.

How to get started on making an http server? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Implementation of a web-server
I am trying to make an http server in java that can handle http requests. if the user types in http://www.example.com/Weather/94901 i want the program to be able to get the string "Weather/94901" then have my application process that and then display to results in the text of the webpage.
Why would you write a web server for that? In PHP, for example, you could use $_SERVER['PATH_INFO'] or in JSP request.getPathInfo()
Or if you really must, start with Jetty for example, an already existing Java HTTP server

Categories

Resources