0


I have to create a desktop client to previously made web application.
Problem is that this application uses ajax to communicate and I have no clue how to communicate with servlet from standalone java app.
Can you give info on how to start ?

4 Answers 4

5

Basically, it's all HTTP. AJAX is just a fancy term to describe asynchronous HTTP calls made from Javascript. Any HTTP Library will aid you to access the data you need, like the Apache HTTPComponents.

Sign up to request clarification or add additional context in comments.

Comments

3

You should take a look at the commons HttpClient library. It's made to be used for programatically making calls to http services.

1 Comment

Thanks, started from first try. Before I was trying using standard Java IO and cannot get response from the server.
1

If you have access to the server part of the application, it would be interesting to consider rebuilding around XML or JSON, better than using HTML and parsing it.

If you don't have access to it, then @Malax is right (+1) and then you should consider using apache jericho for parsing.

Regards, Stéphane

2 Comments

Since when does "ajax" imply "using HTML and parsing it"?
Unfortunatelly no $$ on this. And it would require client to make again acceptance tests on delivered part.
1

You can establish a HTTP connection to a remote server with a given URL from your desktop client. Here's a small code fragment which demonstrates one way of doing it. The connection uses a session cookie, which may or may not be required in your case.

private void createConnectionToServerWithSessionCookie(String URLStr) throws IOException {
    URL managerURL = new URL(URLStr);
    URLConnection connection = managerURL.openConnection();
    connection.setRequestProperty("Cookie", sessionId);
    connection.connect();
    managerReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
}

Also look here for more information

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.