0

I am writing a java application which invokes a web service and uses its response text. (i.e.) it invokes a URL like http://web-server.com/item/3455

That URL would return a response text (string) like "nexus".

For implementing the above functionality, is there any readily available framework that we can make use of? Or should I code the functionality from scratch.

Thanks.

saravana_pc
  • 2,349
  • 10
  • 36
  • 63

3 Answers3

2

Even if the API is not strictly RESTful, you can use spring-web's RestTemplate like so:

RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject("http://web-server.com/item/3455", String.class);
WA Hunt
  • 487
  • 3
  • 10
1

Based on url, it seems you are doing REST call. You may use HTTPURLConnection API.

Community
  • 1
  • 1
kosa
  • 63,683
  • 12
  • 118
  • 157
  • thanks. Could we use this for non-rest web services as well? For example, if the URL is like http://web-server.com/item?id=3455 – saravana_pc Jul 17 '12 at 14:13
1

All you need is a simple HTTP client to do what you're talking about. The HttpClient project from Apache is a popular choice and would certainly work for what you're trying to do.

Mike Deck
  • 17,069
  • 15
  • 62
  • 89