Java Reference
In-Depth Information
* over HTTP.
*/
public class SaajRestClient {
public static void main(String[] args) throws Exception {
new SaajRestClient().call();
}
public void call() throws Exception {
//these can be any value here, as we're not NS qualified
//I leave them to illustrate usage in other contexts
URI nsURI = new URI("urn:emps");
QName serviceName = new QName("empsSvc",nsURI.toString());
QName portName = new QName("empsPort",nsURI.toString());
Service s = Service.create(serviceName);
String address = "http://localhost:8080/restexamples/resources/
emps/1";
s.addPort(portName, HTTPBinding.HTTP_BINDING, address);
Dispatch<Source> d = s.createDispatch(portName,
Source.class, Service.Mode.PAYLOAD);
Map<String, Object> requestContext = d.getRequestContext();
requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "GET");
//no body in this example. you would build it here if necessary
Source result = d.invoke(null);
if (result != null) {
//got result, so drill down to find data.
DOMResult domResult = new DOMResult();
Transformer trans =
TransformerFactory.newInstance().newTransformer();
trans.transform(result, domResult);
printResult(domResult);
} else {
System.out.println("No result.");
}
}
//use XPath to drill down to data we want
private void printResult(DOMResult domResult)
Search WWH ::




Custom Search