How to use RESTful web service in my JSF project?

Since RESTful web services are url-based, they are not objects, we cannot call methods on them. I have a simple web service that has only one method: @GET . I saw one screencast and it used some javascript library to use the web service. But how can I use it in a JSF project? I can’t even enter it like a regular web service. Please help. I am new to REST. Can't I use it in my managed bean?

If the only way to consume a web service is through javascript, can anyone here give me detailed information on how to use it through jQuery?

Thanks in advance:)

+6
java rest jsf
source share
1 answer

You can use it in a managed bean without any problems. RESTful web services typically return JSON or XML format objects. You can call a soothing web service and, depending on the format of its response, parse it either with an XML parser or with a JSON parser, or it is even better to use matching to match the response to a Java object and use it elsewhere in your application.

The Java-JSON mapping libraries are discussed here ( screen capture here ).

You can use JAXB to display XML-Java: https://jaxb.dev.java.net/tutorial/

An XML converter maps an XML document to a Java object.

For example, if the response is from the web service you are using:

 <SampleResponse> <firstName>James</firstName> <lastName>Gosling</lastName> </SampleResponse> 

An XML converter can convert it to an instance of the following class:

 public class SampleResponse { private String firstName; private String lastName; // setters and getters } 

Thus:

 SampleResponse myResponseObj = mapper.fromXML(xmlRespnse); 

JSON manipulators work in a similar way.

+9
source share

All Articles