Thursday, March 02, 2006

Example client code

The article over at CETIS only explains how to code the difficult end of enterprise - the server. How do you implement a client?

Below is a code snippet that might shed some light. Its from an application that aggregates groups and resources from a range of sources, in this case this is the method it uses to get information about people who are members of a group.

The array of java objects returned by the call represent Persons (in this case), and you can do the usual sort of operations on them like getFormatName() and so on.

Pretty much any enterprise API call is coded in exactly the same fashion.

(Apologies for the lines scooting off the end of the page...)


/**
* Get the members of a group from the service
* @param id the id of the group to get members for
* @param url the location of the service
* @return a set of persons
* @throws PlexException
*/
public PersonDType[] readPersonsForGroup(IdentifierDType id, String url) throws PlexException{
_readPersonsRequest = new _readPersonsForGroupRequest();
_responseHolder = new _readPersonsForGroupResponseHolder();
_responseHeaderInfoHolder = new _syncResponseHeaderInfoHolder();
try {
_readPersonsRequest.setGroupSourcedId(id);
_requestHeaderInfo = HeaderInfoHelper.newRequestHeaderInfo();
PersonManagementServiceSyncLocator loc = new PersonManagementServiceSyncLocator();
PersonManagementServiceSyncSoapStub svc = (PersonManagementServiceSyncSoapStub)loc.getPersonManagementServiceSyncSoap(new java.net.URL(url));
svc.readPersonsForGroup(_readPersonsRequest,_requestHeaderInfo,_responseHolder,_responseHeaderInfoHolder);
_status = _responseHeaderInfoHolder.value.getStatusInfo();
_persons = _responseHolder.value.getPersonSet();
}catch (Exception e){
throw new PlexException("There was a problem connecting to the remote service");
}
if (_persons == null || _status.getCodeMajor().getValue().equals("failure")){
throw new PlexException("There was a problem with the remote service ("+_status.getDescription()+")");
}
if (_status.getCodeMajor().getValue().equals("unsupported")){
throw new PlexException("The remote service doesn't support this type of request");
}
return _persons.getPerson();
}

1 Comments:

At 5:08 PM, Blogger Carol said...

Thanks for posting this, it's useful.

 

Post a Comment

<< Home