Call an Internal SOAP Web Service from Groovy with Separate User Credentials over SSL

This example shows how to create a connection to a SOAP web service and call the web service from a Groovy script used in Application Composer. The web service uses a security scheme with separate user credentials and secure sockets layer (SSL).

For this example, the web service is used to calculate a custom field's default value.

The following table summarizes key decisions for this scenario:

Decisions to Consider

In This Example

What name will you use for the web service connection?

mathsws

What is the URL of the Web Services Description Language (WSDL) file that you will use?

https://internal-hosted:7102/MathsWS-Model-context-root/UsernameTokenOverSSLSecurity?wsdl

This WSDL file specifies the desired SSL authentication scheme.

Note: The URL shown here's an arbitrary example. You must obtain the real WSDL URL from the service provider.

Which credential key will you use?

mylogin

Where will the web service be called from?

From a Groovy script expression used to calculate a custom field's default value.

Which web service method will be called from the Groovy script?

getSum

This method returns the sum of two integer argument values.

Is it required to ignore the time stamp in the response from the web service?

Yes.

To ignore the time stamp, you select the Disable time stamp verification check box. This may be required to address interoperability issues.

To call a web service from a Groovy script that's secured with SSL, complete the following tasks:

  1. Create the web service connection.

  2. Add the web service call to the Groovy script, and verify that the call succeeds.

Prerequisites

Verify that you have completed the following prerequisite steps:

  1. Get details of the WSDL URL and the user credentials to use from the web service provider.

  2. Create a custom field for an object that has a calculated default value.

  3. Prepare the Groovy script for the expression used to calculate the field's default value. The Groovy code must prepare the argument values, which in this example are two values that are summed.

Creating the Web Service Connection

When you create a web service connection, you specify a name for the web service, the URL of the WSDL file, and the security scheme settings. The name is simply an identifier that's used in the list of web services in the Expression Builder in Application Composer.

  1. In Application Composer, select Web Services in the Common Setup pane.

  2. On the Web Services page, click the New icon, then click SOAP.

  3. On the Create SOAP Web Service Connection page, enter mathsws in the Name field.

    The name must not include periods.

  4. Enter https://internal-hosted:7102/MathsWS-Model-context-root/UsernameTokenOverSSLSecurity?wsdll in the WSDL URL field, and click Read WSDL.

  5. Click the New Key icon next to the Credential Key field.

  6. In the Create Key dialog box, enter a name in the Credential Key field, in this example, mylogin, enter the user name and password credentials supplied by the web service provider, and click OK.

  7. Select Disable time stamp verification so that the time stamp in the response header from the Web service is ignored.

  8. Click Save and Close.

    The web service connection is created and the name and WSDL URL are listed on the Web Services page.

Adding the Web Service Call to the Groovy Script

In the Expression Builder dialog that you see when you create or edit Groovy scripts, there is a Web Services tab that lists the web services for which you have created a connection. For each web service you can include calls to the available methods in your Groovy script.

  1. In Application Composer, edit the custom field that uses the expression that will contain the web service call.

  2. Click the Expression Builder icon.

  3. In the Expression Builder dialog, select the Web Services tab.

  4. Select mathsws from the Web Services list.

  5. Select getSum from the Functions list.

  6. Position the cursor at the place in the script where you want to insert the web service call.

  7. Click Insert to insert the code to call the web service method.

  8. Update the script so that two integer values are provided as arguments for the web service call.

  9. Click Submit.

  10. Verify that the web service call succeeds; in this example the custom field should have the expected default value.