REST Web Services: Sample client code

This Java™ example makes use of the Apache Wink REST Client API. For more information about Wink, see the link at the end of this topic.

// simple getPerson request
String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<TCRMService xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
  	xmlns=\"http://www.ibm.com/mdm/schema\"
  xsi:schemaLocation=\"http://www.ibm.com/mdm/schema MDMDomains.xsd\">
   <RequestControl>
      <requestID>100129</requestID>
      <DWLControl>
         <requesterName>test</requesterName>
         <requesterLanguage>100</requesterLanguage>
         <userRole> </userRole>
      </DWLControl>
   </RequestControl>
      <TCRMInquiry>
         <InquiryType>getPerson</InquiryType>
         <InquiryParam>
            <tcrmParam name=\"PartyId\">999</tcrmParam>
            <tcrmParam name=\"InquiryLevel\">1</tcrmParam>
         </InquiryParam>
      </TCRMInquiry>
</TCRMService>";		

try{
	ClientConfig config = new ClientConfig();
	// setup basic authentication
	BasicAuthSecurityHandler basicAuthHandler = new BasicAuthSecurityHandler();
	basicAuthHandler.setUserName("mdmadmin");
	basicAuthHandler.setPassword("mdmadmin");
	basicAuthHandler.setSSLRequired(false);
	config.handlers(basicAuthHandler);
	
	RestClient rc = new RestClient(config);
	
	Resource r =  rc.resource("http://myserver.com:9080/com.ibm.mdm.server.ws.restful/resources/MDMWSRESTful");

	// optional MDM headers
	r.header("TargetApplication", "");
	r.header("RequestType", "");
	r.header("Parser", "");
	r.header("ResponseType", "");
	r.header("Constructor", "");
	r.header("OperationType", "");
	r.header("ASI_Request", "");
	r.header("ASI_Response", "");	
	
	// submit put request of the xml payload.
	String response = r.contentType("application/xml").accept("application/xml").put(String.class, payload);
	System.out.println(response);
}
catch(ClientWebException ce){
	System.out.println(ce.getResponse().getMessage());
}
catch(Exception e){			
	e.printStackTrace();
}