Java Reference
In-Depth Information
WebTarget webTarget = client.target(" http://localhost:8080/IntroToJavaEE7/rest/simplerest " );
Response res = webTarget.request("text/plain").get();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_INFO, "Invoked test client",
"Invoked test client"));
setClientOutput(res.toString());
}
/**
* @return the clientOutput
*/
public String getClientOutput() {
return clientOutput;
}
/**
* @param clientOutput the clientOutput to set
*/
public void setClientOutput(String clientOutput) {
this.clientOutput = clientOutput;
}
}
Web Resource Targets
The first step toward invoking a web resource is to make a call to a target. This can be done in a couple of ways. The
previous example demonstrated the use of the Client target method, which accepts a URI and returns a WebTarget .
WebTarget myTarget = client.target(" http://somehost.com/service " );
Once the target has been obtained, a number of things can be done with it. A request can be made against it, as in
the RestClientOne example, by invoking the target's request method. A target can also be further qualified by calling
its path method and passing the next sequence in a URI path.
WebTarget myTarget =
client.target(" http://somehost.com/service").path("one " );
A path can also contain dynamic content in the form of URI template parameters. To include a template
parameter, wrap the dynamic portion of the path in curly brackets, as in { } , and then chain a call to the pathParam
method, passing the name-value pair of the parameter.
WebTarget myTarget =
client.target(" http://somehost.com/service").path("one").path("{code } ")
.pathParam("code","100375");
 
Search WWH ::




Custom Search