aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Communication between two web applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Communication between two web applications" Watch "Communication between two web applications" New topic
Forums: Web Services Sockets and Internet Protocols
Author

Communication between two web applications

Prathy Maroor
Greenhorn

Joined: Jul 22, 2014
Posts: 14
Generally a web service talks to a remote database to fetch required data. In my case, I have a web service that gets the data from another web application (given the http url). Both are java based applications. How do I communicate with the remote web application ? via HttpUrlConnection? I need to send JSON Objects and receive JSON Arrays. Are there any code examples that I can refer to? Please guide me.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Prathy Maroor wrote:Generally a web service talks to a remote database to fetch required data. In my case, I have a web service that gets the data from another web application (given the http url). Both are java based applications. How do I communicate with the remote web application ? via HttpUrlConnection? I need to send JSON Objects and receive JSON Arrays. Are there any code examples that I can refer to? Please guide me.


Not sure if you want to just scrape a website (http url part of the question) or if you want to connect to a web service.

To do the first (scrape a website), you can just use the URL class -- which I can confirm works just as well as HttpClient. Or you can use the HttpClient from Apache, which is probably much easier to use, but needs a third party jar. So, the URL class is an option if you don't want another jar in your classpath.

To do the second (connect to a webservice), in the past (many years ago), I used Axis, which works really really well. Since then, Apache has added Axis2, which is supposedly based on a standard. And also, Java 6 has an API built in via JAX-WS. This last option is an option if you don't want another jar in your classpath.

Henry



Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Prathy Maroor
Greenhorn

Joined: Jul 22, 2014
Posts: 14
Let me rephrase the question:

The system actually works like this:

Client (say a mobile app) requests for data from Web service via HTTP GET URL. The web service in turn fetches data from another web application/server by sending the request as a json object. The data server that is listening on a port for the requests from web service, then responds with a json array. Should I use HTTPURLconnection to send request from web service to data server? If yes, should the connections be threaded? Or should I use just one connection per request?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Prathy Maroor wrote:
Client (say a mobile app) requests for data from Web service via HTTP GET URL. The web service in turn fetches data from another web application/server by sending the request as a json object. The data server that is listening on a port for the requests from web service, then responds with a json array. Should I use HTTPURLconnection to send request from web service to data server? If yes, should the connections be threaded? Or should I use just one connection per request?


Not sure why you are rephrasing the question. Was there something about the response that you didn't like? ...

Anyway, what HttpURLConnection class are you referring to? Are you referring to the one that is returned from the URL class? If so, see my previous post as I mentioned that the URL class is fine for webpage scraping.

Or are you referring to the HttpURLConnection class that is part of the Apache HttpClient library? If so, see my previous post as I also mentioned that the HttpClient class is fine for webpage scraping.

Or are you referring to some other HttpURLConnection class? If so, then you need to provide us with some more context.

Henry
Prathy Maroor
Greenhorn

Joined: Jul 22, 2014
Posts: 14
Thanks for your response. I am sorry, I thought I wasn't very clear with my question and the scenario description. I wanted to know if there are any other methods possible for the scenario.
Yes, I was referring to HTTPUrlConnection of the URL class. It works well in my situation. Now I am not sure if it should be threaded?
I have say 7 resources (so 7 classes) in my web services - each of which will open a new http connection. The http connection request and response is handled in a different class and I need some information to be returned and also need to access some variables in the http handler class.

RequestHandler Class:


This is the http connection handler. I would then call this from a different class this way:



but now I am not sure how to access "responseCode" and "responseJSONArray" from that class for that instance?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Communication between two web applications