Java Client Stubs

The example illustrates how to call a web service by using a Java client stub.

Example: Calling the getContract web service by using a Java Client Stub.

import java.net.*;

import java.io.*;

import java.lang.*;

import java.math.*;

import java.util.*;

import com.dicarta.webservices.types.common.Credential;

import com.dicarta.webservices.types.common.Authentication;

import com.dicarta.webservices.services.contract.*;

import com.dicarta.webservices.types.domain.*;

import com.dicarta.webservices.faults.*;

public class GetContract {

public static void main(String[] args) throws Exception {

if (args.length != 1) {

usage();

}

String hostUrl = args[0];

getContract(hostUrl);

}

public static void getContract(String hostUrl) {

ContractServices_BindingStub binding = null;

/* The following code obtains the binding stub for a given webservice, for example, Contract or Organization:

*/

try {

java.net.URL endpoint;

/*This address must contain the host:port on which the diCarta Contracts service is deployed.

*/

String serviceAddress = hostUrl +

"/webservices/services/ContractServices";

endpoint = new java.net.URL(serviceAddress);

binding = (ContractServices_BindingStub)

new ContractServices_ServiceLocator

().getContractServices(

endpoint);

} catch (Exception e) {

e.printStackTrace();

System.exit(1);

}

//Time out after a minute.

binding.setTimeout(60000);

binding.setMaintainSession(false);

/*To maintain this session in order to make multiple webservice calls, set binding.setMaintainSession to true.

*/

//Make the webservice call:

try {

//Build the Authentication piece:

Credential credential = new Credential();

credential.setPassword("dicarta-user");

Authentication auth = new Authentication("intusr1", credential);//Build the request data piece:

ContractReference reference = new

ContractReference();

reference.setId("AContractUUID");

GetRequest request = new GetRequest();

request.setAuthentication(auth);

request.setRequestData(reference);

Contract contract = binding.get(request);

} catch (AuthenticationFault e) {

System.err.println ("Unable to authentication");

System.err.println ("Unable to authentication");

} catch (AuthorizationFault e) {

System.err.println ("Invalid security permission for operation");

} catch (ObjectNotFoundFault e) {

System.err.println ("Invalid contract specified");

} catch (SystemFault e) {

System.err.println ("Unknown fault occured");

} catch (Exception e) {

System.err.println ("Unknown error occured");

}

}

private static void usage() {

System.out.println ("Usage: java GetContract <hostUrl>");

System.exit(1);