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 arequestDataobject. If you need additional processing, you can pass therequestDataobject to theexecutecallback. Otherwise, therequestDataobject is used to call the web service when theServiceobject is invoked. -
parseResponse: Gives theHTTPClientas its extra argument. Use to parse the response contained in theServiceobject.
FTP and SFTP Callbacks
For an FTP or SFTP service, pass inFTPService objects. -
createRequest: Required to create arequestDataobject. If you need additional processing, you can pass therequestDataobject to the execute callback. Otherwise, therequestDataobject is used to call the web service when theServiceobject is called. -
parseResponse: Gives theFTPClientas its extra argument. Use to parse the response contained in theServiceobject. -
execute: If thesetOperationmethod 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.portandwebreferences2object. -
createRequest: Required to create arequestDataobject. 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 theinitServiceClientcallback, 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 theServiceobject.
Generic Callbacks
Does not wrap any class. Used to define custom calls.
-
createRequest:Required to create arequestDataobject. If you need additional processing, you can pass therequestDataobject to the execute callback. Otherwise, therequestDataobject is used to call the web service when theServiceobject is called. - parseResponse: Use to parse the response contained in the
Serviceobject.
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
mockCallcallback 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();