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:
- Within the action method construct a URL of dynamic parameters
- Send the constructed URL to service
- Parse the returned service response parameters
- 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.
精彩评论