Creating Service Callbacks
When you use dw.svc.Service.call(Object...)
to invoke a web service,
the service framework checks whether the call exceeds either the rate limiter or circuit breaker
thresholds and, if not, makes the call. When making a call, the framework invokes the callbacks
you implemented in your service instance.
Each callback corresponds to one of the callback methods defined by the
dw.svc.ServiceCallback
class. These methods are called in the following
order:
-
initServiceClient(Service)
― Creates the underlying client used to make the call. Required only for SOAP Services. Other client types are created automatically. -
createRequest(Service, Object...)
― Given arguments to theService.call(Object...)
, configure the actual service request. This may include setting request headers, defining the message body, and so on. -
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. -
parseResponse(Service, Object)
― Convert the result of the call into an object to be returned from theService.call(Object...)
method.
Some callback methods may be optional, depending on the type of service.
Every callback method requires a Service
object (for a generic service) or one of its subclasses
(FTPService
, HTTPFormService
,
HTTPService
, or SOAPService
).
HTTP and HTTP Form Callbacks
For an HTTP
service, pass in HTTPService
objects. For an HTTP form,
pass in HTTPFormService
objects.
-
createRequest
: Required to create arequestData
object. If you need additional processing, you can pass therequestData
object to theexecute
callback. Otherwise, therequestData
object is used to call the web service when theService
object is invoked. -
parseResponse
: Gives theHTTPClient
as its extra argument. Use to parse the response contained in theService
object.
FTP and SFTP Callbacks
For an FTP or SFTP service, pass inFTPService
objects. -
createRequest
: Required to create arequestData
object. If you need additional processing, you can pass therequestData
object to the execute callback. Otherwise, therequestData
object is used to call the web service when theService
object is called. -
parseResponse
: Gives theFTPClient
as its extra argument. Use to parse the response contained in theService
object. -
execute
: If thesetOperation
method isn't called in the web service script, operations defined in the execute callback are executed when the web service is invoked. You can use the execute method to perform multiple operations in sequence.
SOAP Callbacks
For any SOAP service, pass in a
SOAPService
object.
-
initServiceClient
: Implement to return adw.ws.port
andwebreferences2
object. -
createRequest
: Required to create arequestData
object. This object must be passed to the execute method. -
execute
: Specifies additional processing for the web service request.Note: If you get your port in this step, instead of in theinitServiceClient
callback, any timeouts you set will override those set in the service configuration. This isn't recommended. -
parseResponse
: Use this method to parse the response in theService
object.
Generic Callbacks
Does not wrap any class. Used to define custom calls.
-
createRequest:
Required to create arequestData
object. If you need additional processing, you can pass therequestData
object to the execute callback. Otherwise, therequestData
object is used to call the web service when theService
object is called. - parseResponse: Use to parse the response contained in the
Service
object.
Mock Callbacks
You can mock web service responses in two ways.
First, you can the web service to use mock responses:
- In Business Manager, select Administration > Operations > Services. For the Service Mode, select Mocked.
- Provide a
mockCall
callback handler. For example, in your web service script:
mockCall: function(svc:HTTPService, client:HTTPClient){
return {
statusCode: 200,
statusMessage: "Success",
text: "MOCK RESPONSE (" + svc.url + ")"
};
}
result = service.setMock().call();