Implement Browsing support
Browsing has two phases: getting the list of available objects, and getting the definition of a specific object. These examples demonstrate how to set up browsing for an UPDATE operation so that the request and response objects to the connector operation are the individual object types (e.g., the "Contact" object).
Getting the available object types
Ideally, the available object types are discoverable from the WSDL (especially if the WSDL is user-specific). If this is not the case, you may need to hard-code the available object types into the connector implementation. For the following example, assume that every object type has a getter method of the form "get<typeName>".
- Extend the
WSBrowserclass and override thegetOtherObjectTypes()method. This method is called to get the object types for all operations except EXECUTE.
Code sample
@Override
protected ObjectTypes getOtherObjectTypes()
{
ObjectTypes types = new ObjectTypes();
List<ObjectType> typeList = types.getTypes();
for(String opName : WSDLUtil.getWSOperations(getConnection().getCache().getDefinition())) {
// search for operations that start with "get"if(opName.startsWith("get")) {
// remove "get" from the operation name to get the object type name
String objectTypeName = opName.substring("get".length());
ObjectType ot = new ObjectType();
ot.setId(objectTypeName);
typeList.add(ot);
}
}
// always a good idea to provide an ordered list to the user
Collections.sort(typeList, BrowseUtil.OBJECT_TYPE_COMPARATOR);
return types;
}
Getting the object type definition
Caveats similar to those previously mentioned for getting the object types are also assumed here. In this case, you get the object definition for an UPDATE operation. Assume that every object type has an update method of the form "update<typeName>".
- Extend the
WSBrowserclass and override thegetOtherObjectDefinitions()method. This method is called to get the object definitions for all operations except EXECUTE.
Code sample
@Override
protected ObjectDefinitions getOtherObjectDefinitions(String objectTypeId, Collection<ObjectDefinitionRole> roles)
{
// determine the operation prefix based on the operation
String opNamePrefix = null;
switch(getContext().getOperationType()) {
case UPDATE:
opNamePrefix = "update";
break;
}
// construct operation name from the object type and operation type prefix
String opName = opNamePrefix + objectTypeId;
// grab the webservice operation definition for the desired operation
Definition wsdl = getConnection().getCache().getDefinition();
WebServiceOperation op = WSDLUtil.getWSOperation(wsdl, opName);
if(op == null) {
thrownew ConnectorException("Could not find wsdl operation " + opName);
}
return getObjectDefinitions(op, roles, WSDLUtil.loadSchemas(wsdl));
}
- Override the
getOperationRequestElementName()method. This method is called bygetObjectDefinitions()to determine the element name of the request object definition. Since the operation implementation will be handling the wrapping/unwrapping, this should return the object type name (e.g. "Contact").
Code sample
@Override
protectedString getOperationRequestElementName(WebServiceBindingOperation bindingOp, SchemaMap schemaDocMap)
throws SchemaModelException
{
if(getContext().getOperationType() == OperationType.EXECUTE) {
// use default implementation forthis operation type
return super.getOperationRequestElementName(bindingOp, schemaDocMap);
}
// for all other operation types, the object type id is the element name (e.g. "Contact")
return getObjectTypeId();
}
- Override the
getOperationResponseElementName()method for the same reasons mentioned in the previous step.
Code sample
@Override
protectedString getOperationResponseElementName(WebServiceBindingOperation bindingOp, SchemaMap schemaDocMap)
throws SchemaModelException
{
if(getContext().getOperationType() == OperationType.EXECUTE) {
// use default implementation forthis operation type
return super.getOperationResponseElementName(bindingOp, schemaDocMap);
}
// for all other operation types, the object type id is the element name (e.g. "Contact")
return getObjectTypeId();
}