Class ServiceCallback
Defines callbacks for use with the LocalServiceRegistry.
Note this class itself is not used directly, and is present only for documentation of the available callback methods.
These methods are called in sequence when a service is called:
- initServiceClient(Service)-- Creates the underlying client that will be used to make the call. This is intended for SOAP Services and optionally for setting configuration options on the HTTP client. Other client types will be created automatically. 2. createRequest(Service, Object...)-- Given arguments to the Service.call(Object...), configure the actual service request. This may include setting request headers, defining the message body, etc. 3. execute(Service, Object)-- Perform the actual request. At this point the client has been configured with the relevant credentials, so the call should be made. This is required for SOAP services. 4. parseResponse(Service, Object)-- Convert the result of the call into an object to be returned from the Service.call(Object...)method. If the service is mocked (see Service.isMock()), then mockFull(Service, Object...)takes the place of this entire sequence. If that is not implemented, then mockCall(Service, Object)takes the place of just the execute(Service, Object)method.
The URL, request, and response objects may be logged. To avoid logging sensitive data, filterLogMessage(String)and/or getRequestLogMessage(Object)and getResponseLogMessage(Object)must be implemented. If they are not implemented then this logging will not be done on Production environments.
There are some special considerations for the combination of service type and callback: | | Service Type | initServiceClient | createRequest | execute | parseResponse |
| --- |--- |--- |--- |--- |--- |
| HTTP | This is only required to use non-default options. It must return either a HTTPClient or a Map containing the HTTPClient.HTTPClient(Object) options. | Required unless execute is provided. The return value is expected to be either a String or array of HTTPRequestPart, which will be used as the request body | Not called unless a boolean "executeOverride
| Property | Description |
|---|---|
URL: String (read-only) | Allows overriding the URL provided by the service configuration. |
This class does not have a constructor, so you cannot create it directly.
| Method | Description |
|---|---|
| createRequest(Service, Object...) | Creates a request object to be used when calling the service. |
| execute(Service, Object) | Provides service-specific execution logic. |
| filterLogMessage(String) | Allows filtering communication URL, request, and response log messages. |
| getRequestLogMessage(Object) | Creates a communication log message for the given request. |
| getResponseLogMessage(Object) | Creates a response log message for the given request. |
| getURL() | Allows overriding the URL provided by the service configuration. |
| initServiceClient(Service) | Creates a protocol-specific client object. |
| mockCall(Service, Object) | Override this method to mock the remote portion of the service call. |
| mockFull(Service, Object...) | Override this method to mock the entire service call, including the createRequest, execute, and parseResponse phases. |
| parseResponse(Service, Object) | Creates a response object from a successful service call. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- URL: String
(read-only) Allows overriding the URL provided by the service configuration.
It is usually better to call Service.setURL(String) within createRequest(Service, Object...) because that allows you to modify the existing URL based on call parameters.
- createRequest(service: Service, params: Object...): Object
Creates a request object to be used when calling the service.
The type of the object expected is dependent on the service. For example, the HTTPService expects the HTTP request body to be returned.
This is required unless the execute method is implemented.
It is not recommended to have a service accept a single array or list as a parameter, since doing so requires some extra work when actually calling the service. See Service.call(Object...) for more details.
Parameters:
- service - Service being executed.
- params - Parameters given to the call method.
Returns:
- Request object to give to the execute method.
- execute(service: Service, request: Object): Object
Provides service-specific execution logic.
This can be overridden to execute a chain of FTP commands in the FTPService, or perform the actual remote call on a webservice stub in the SOAPService.
Parameters:
- service - Service being executed.
- request - Request object returned by createRequest(Service, Object...).
Returns:
- Response from the underlying call, to be sent to parseResponse(Service, Object).
Throws:
- Exception -
- filterLogMessage(msg: String): String
Allows filtering communication URL, request, and response log messages.
If not implemented, then no filtering will be performed and the message will be logged as-is.
Parameters:
- msg - Original log message.
Returns:
- Message to be logged.
- getRequestLogMessage(request: Object): String
Creates a communication log message for the given request.
If not implemented then the default logic will be used to convert the request into a log message.
Parameters:
- request - Request object.
Returns:
- Log message, or null to create and use the default message.
- getResponseLogMessage(response: Object): String
Creates a response log message for the given request.
If not implemented then the default logic will be used to convert the response into a log message.
Parameters:
- response - Response object.
Returns:
- Log message, or null to create and use the default message.
- getURL(): String
Allows overriding the URL provided by the service configuration.
It is usually better to call Service.setURL(String) within createRequest(Service, Object...) because that allows you to modify the existing URL based on call parameters.
Returns:
- URL to use. The default behavior is to use the URL from the service configuration.
- initServiceClient(service: Service): Object
Creates a protocol-specific client object.
This does not normally need to be implemented, except in the case of SOAP services.
It may also be used for HTTP services to override the default configuration.
Example SOAP service:
Example configuration override for an HTTP service:
Parameters:
- service - the Service object.
Returns:
- Client object
Throws:
- Exception -
- mockCall(service: Service, requestObj: Object): Object
Override this method to mock the remote portion of the service call.
Other callbacks like createRequest and parseResponse are still called.
Parameters:
- service - Service being executed.
- requestObj - Request object returned by createRequest(Service, Object...).
Returns:
- Mock response, to be sent to parseResponse(Service, Object).
Throws:
- Exception -
- mockFull(service: Service, args: Object...): Object
Override this method to mock the entire service call, including the createRequest, execute, and parseResponse phases.
Parameters:
- service - Service being executed.
- args - Arguments from the Service call method.
Returns:
- Object to return in the service call's Result.
Throws:
- Exception -
- parseResponse(service: Service, response: Object): Object
Creates a response object from a successful service call.
This response object will be the output object of the call method's Result.
Parameters:
- service - Service being executed.
- response - Service-specific response object. For example, the HTTPService service provides the underlying HTTPClient object that made the HTTP call.
Returns:
- Object to return in the service call's Result.