开发者

How to obtain data from a webservice in a JSF action method?

I'm trying to determine the correct API calls on FacesContext to do the following when processing a backing bean action:

  1. Within the action method construct a URL of dynamic parameters
  2. Send the constructed URL to service
  3. Parse the returned service response parameters
  4. Continue with action method processing based on reponse string from request.

Any suggestions on the highlevel API calls for steps 2 and 3 to send开发者_如何学Go me in the right direction would be very appreicated. Note, the service I'm calling is external to this application in a blackbox. Instructions are: send URL in specified format, parse response to see what happened.


This problem is not specific to JSF in particular, so you'll find nothing in JSF API. The standard Java API offers java.net.URL or, which allows more fine grained control, java.net.URLConnection to fire HTTP requests and obtain the response as an InputStream which you can then freely parse the usual Java way.

InputStream response = new URL("http://google.com").openStream();
// ...

Depending on the content type of the response, there may be 3rd party API's which ease the parsing. For example, Google Gson if it's JSON or Jsoup if it's HTML/XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜