Java Reference
In-Depth Information
public void close() {
client.destroy();
}
}
As we can see, NetBeans generates wrapper methods for each of the methods in our
RESTful web service. NetBeans generates two versions of each method, one that
produces and/or consumes XML, and another one that produces and/or consumes
JSON (JavaScript Object Notation). As we can see, each method uses generics so that
we can set the return type of these methods at run time.
The easiest and most straightforward way of using these methods is to use Strings,
for example, we can invoke the ind_XML(Class<T> responseType, String id) as
follows:
public class Main {
public static void main(String[] args) {
NewJerseyClient newJerseyClient = new NewJerseyClient();
String response = newJerseyClient.find_XML(
String.class, "1");
System.out.println("response is: " + response);
newJerseyClient.close();
}
}
The above invocation will return a String containing an XML representation of the
values in the row with ID of 1 in the database, executing the above code we should
see the following output:
response is: <?xml version="1.0" encoding="UTF-8" standalone
="yes"?><customer><customerId>1</customerId><email>bnorris@
example.com</email><firstName>Bruce</firstName><lastName>Norris</
lastName><middleName></middleName></customer>
We can then parse and manipulate this XML as usual.
Additionally, we can send data to our web service in XML format, all we need to
do is create a String with the appropriate XML and pass it to one of the generated
methods. For example, we could insert a row into the database by using the
following code:
package com.ensode.glassfishbook.jaxrsclient;
public class Main1 {
public static void main(String[] args) {
NewJerseyClient newJerseyClient = new NewJerseyClient();
 
Search WWH ::




Custom Search