• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Communication between two web applications

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Prathy Maroor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic