A basic description of the service implementation is as follows,
The name of the service is GXModelExampleAPI, this class extends the WsiServiceBaseAPI
The service methods use the GX Model of the Guidewire User Entity. Additionally, base the GX Model on the “User” entity and select Contact.FirstName, Contact.LastName, Credential.Username, PublicID to run this example successfully.
There are 2 service methods exposed within the service implementation, they are
exampleGxModelGetUserWsiService: This service method takes in an instance of type User in the GX Model that is based on the Guidewire User entity, as input parameter. Using the public id defined in the input PublicID field queries the DB and for the sake of simplicity returns an instance of the same type with all the other fields in the GX Model populated.
exampleGxModelGetAllUsersWsiServiceNoInputArrayOutput: This service method does not take in any input at all. The implementation returns an array of the GX Model User entity representing all the users configured in the system.
The name of the logger is based on the name passed in to the constructor “GXModelExampleAPI” and is defined by the logger category “Integration.GXModelExampleAPI”. The behavior of the logger is defined and controlled in logging.properties file.
Using GX Model Code Sample1 lets take a look at the service method exampleGxModelGetUserWsiService and break down it’s implementation. The method invokes wsiExecute base class method (note that this method invokes the wsiExecute instead of wsiExecuteAndReturnArray as this method returns a single instance of the GX Model based User entity). There are two parameters to this method
An anonymous GOSU block is passed as the first parameter. This GOSU block receives as input the input parameter passed into the service method and calls the processExampleGxModelGetUserWsiService method that ultimately provides the implementation of the business functionality of returning the user information. This anonymous GOSU block will be invoked by the base WsiServiceBaseAPI class.
The second parameter is the input ‘pInput’ to the service method itself that is in turn passed to the block by the WsiServiceBaseAPI class when the block in invoked.
The process processExampleGxModelGetUserWsiService implements the business specific logic – this example queries the system for the user by the public id specified in the input and populates the response GX Model based User object with information defined in the GX Model User entity. In a real life scenario the business functionality will be implemented here.
GX Model Code Sample2 shows the service method exampleGxModelGetAllUsersWsiServiceNoInputArrayOutput that now takes no inputs from the service client consuming this service and returns an array. The method invokes wsiExecuteAndReturnArray base class method now since we are meaning to return multiple instances as opposed to a single instance above. There are two parameters to the wsiExecuteAndReturnArray as well
An anonymous GOSU block is passed as the first parameter. This GOSU block receives as array input the input parameter passed into the service method, in this case we don’t have an input parameter so null will be passed in, and calls the processExampleGxModelGetAllUsersWsiServiceNoInputArrayOutput method that ultimately provides the implementation of the business functionality. This anonymous GOSU block will be invoked by the base WsiServiceBaseAPI class.
The second parameter is null in this case since there is no input passed in by the calling service client that is in turn passed to the block by the WsiServiceBaseAPI class when the block in invoked.
The process processExampleGxModelGetAllUsersWsiServiceNoInputArrayOutput implements the business specific logic – this example queries for and returns all the users configured in the system by populating an array of GX Model User entities. In a real life scenario the business functionality will be implemented here.
Sample Log File Output
The following sample log information for a single service call as logged in the server is provided, by default
In DEBUG logging mode there are two debug statements that log the input before processing and the output after processing
In INFO logging mode there is an info statement that logs the time taken, in milliseconds, to process the service and the status of the service (if an exception was thrown by the service implementation).
[java] 2013-01-01 12:00:49,939 DEBUG WsiServiceBaseAPI[GXModelExampleAPI]]:internalWsiExecute() – Processing – [<?xml version=”1.0??>
[java] <ats:User xmlns:ats=”http://guidewire.com/xx/gx/atsynthesize.suite.integration.service.example.gxmodel.gxuser” xmlns:gxm=”http://atsynthesize.com/gw/ws/atsynthesize/integration/service/example/gxmodel/GXModelExampleAPI” xmlns:soap=”http://guidewire.com/ws/soapheaders” xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”>
[java] 2013-01-01 12:00:50,084 DEBUG WsiServiceBaseAPI[GXModelExampleAPI]]:internalWsiExecute() – Processed – [<?xml version=”1.0??>
[java] <User xmlns=”http://guidewire.com/cc/gx/atsynthesize.suite.integration.service.example.gxmodel.gxuser”>
[java] 2013-01-01 12:00:50,084 INFO WsiServiceBaseAPI[GXModelExampleAPI]]:internalExecute() – Time: Processed Service – Success:[true] – [atsynthesize.suite.integration.service.example.gxmodel.gxuser.User instance]
SOURCE CODE: All the source code discussed within this blog is provided @ GitHub – Codebase. You are free to download, extend and send me comments on how you used it. If you want the extensions/changes to be incorporated into the code for others to use or alternatively would like to be part of the group that updates this GitHub project repository, send me a request and we will certainly get back to you. [Link: https://github.com/harikanangi/custom-gosu]