Script: Class dw.svc.ServiceCallback

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:

  1. initServiceClient(Service) -- Creates the underlying client that will be used to make the call. This is intended for SOAP Services. 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
HTTP
HTTPForm
SOAP
FTP
GENERIC

Properties

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.

Constructor Summary

This class does not have a constructor, so you cannot create it directly.

Method Summary

createRequest(service : Service, params : Object...) : Object

Creates a request object to be used when calling the service.

execute(service : Service, request : Object) : Object

Provides service-specific execution logic.

filterLogMessage(msg : String) : String

Allows filtering communication URL, request, and response log messages.

getRequestLogMessage(request : Object) : String

Creates a communication log message for the given request.

getResponseLogMessage(response : Object) : String

Creates a response log message for the given request.

getURL() : String

Allows overriding the URL provided by the service configuration.

initServiceClient(service : Service) : Object

Creates a protocol-specific client object.

mockCall(service : Service, requestObj : Object) : Object

Override this method to mock the remote portion of the service call.

mockFull(service : Service, args : Object...) : Object

Override this method to mock the entire service call, including the createRequest, execute, and parseResponse phases.

parseResponse(service : Service, response : Object) : Object

Creates a response object from a successful service call.

Methods inherited from class Object

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

Method Detail

createRequest

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

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

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

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

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

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

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.

Example declaration:

initServiceClient: function( svc:SOAPService ) { }

Parameters:

service - the Service object.

Returns:

Client object

Throws:

- Exception


mockCall

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

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

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.