Calling Web Services from within Redwood Server
You can call web services in Redwood Server via process definitions. Web services can be imported into Redwood Server using a wizard, the created process definitions are of type RedwoodScript.
These process definitions allow you to:
- Use RedwoodScript, which is a powerful Java-based scripting language, in your requests
- Use parameters in your requests, which adds all the benefits of parameters (scripting, user interaction, constraints and a lot more)
- Easy schedule of the requests
- Add basic authentication to the request; if authentication is not required, you leave the User and Password fields of the wizard empty in which case a credential with the Real User
{redwood}:nocredential
is created for you.
These process definitions can then be customized and published as new web services, which can then be called by third party applications. Notes can be added to processes submitted via the published web service so you can differentiate them easily.
To create a process definition based on a web service, you will need the URL to the WSDL
. The default process definition that gets created will have parameters for each parameter of the request.
Web service process servers require the following key
- WebServices.OutboundServer.limit - the total number of distinct web service credential endpoints
You should always specify the FQDN for each server in a credential endpoint.
Prerequisites
- a free slot in
WebServices.OutboundServer.limit
andProcessServerService.External.limit
for a credential to the third-party web service. The number of soap credentials for a given endpoint you can create is limited by theWebServices.OutboundServer.limit
andProcessServerService.External.limit
license keys; when you have both license keys, the most restrictive applies. Note that theProcessServerService.External.limit
license key is also used by other process server types such as platform agents and SAP connectors. - a credential for the third-party web service
Editing the Process Definition
The default process definition is designed to help you tailor it to your own needs. The process will print both the request and the answer into the output file of the process, by default.
To change this, you have to change the following:
jcsOut.println("Request:");
jcsOut.println(message);
jcsOut.println("Response:");
jcsOut.println(answer);
You would usually only have the following jcsOut.println(answer)
; to write the entire response to an output file. You might want to set the format of the process definition to XML
.
Processing the Returned Response
The process will retrieve the response with the following code:
answer = SOAP.formatXML(req.getResponseXML());
. The response will thus be a standard XML document. You can use the getStringByXPath
method to retrieve given values inside the response.
For example, you want to retrieve the price from the following response:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<xsd:getPrice xmlns:xsd="http://prices.example.com/xsd">
<xsd:return>42.0</xsd:return>
</xsd:getPrice>
</soap:Body>
</soap:Envelope>
Using the following code, you can retrieve the price value of 42.0
and store it in the variable price
:
// [...]
answer = req.getResponseXML();
if (answer != null )
{
answer = SOAP.formatXML(req.getResponseXML());
jcsErrLog.debug(answer);
// Set the namespace
req.setNamespace("http://prices.example.com/xsd");
// retrieve the value of the specific XPath and store it in the variable price
String price = req.getStringByXPath("soap:Envelope/soap:Body/xsd:getPrice/xsd:return");
//Optional, but good; print the result to the ErrLog file when the process is run in debug mode
jcsErrLog.debug(price);
}
//[...]
If you followed the example above, you might want to store the price in an Out
parameter, such as: retailPrice
jcsSetJobOutputParameter("retailPrice", price);
Special Parameters
You can use the following special parameters for process definitions that call web services:
SOAP_HEADER_<header>
- set the SOAP header named<header>
SOAP_URL
- use an alternate URL to the one in theWSDL
SOAP_Action
- use an alternate action to the one in theWSDL
JCS_USER
- the username required for the requestJCS_PASSWORD
- the password required for the request; ifJCS_USER
is set and notJCS_PASSWORD
, then Redwood Server will look for the password in the credential associated with the soap protocol, endpoint, and username (matching the value ofJCS_USER
)
note
You always need to have a credential for each outbound web service, even if you specify the JCS_PASSWORD
parameter.
Credentials
The soap credential protocol is not only used to store username, password, and endpoint combinations; it is also used to enforce license restrictions. Each and every web service you call from Redwood Server needs a valid credential, even if the call itself does not require authentication.
When a web service is called, a valid credential must exist for the remote server, the lookup is performed on the endpoint in the following order:
<server>:<port>
.<server>
.
If no authentication is required and a credential matching the server has been found, the process will be submitted.
If authentication is required, the JCS_USER
and JCS_PASSWORD
parameters will be evaluated:
JCS_USER | JCS_PASSWORD | Authentication Details Used |
---|---|---|
<user> | not set | <user>-<server>[:<port>]-soap |
{virtual}:<v_user> | <user>-<server>[:<port>]-soap that has Virtual User set to <v_user> | |
<user> | <password> | <user>/<password> |
not set | not set | none, if process requires authentication, process will fail |
To prevent authentication headers to be sent to the web service, you can use the {redwood}:nocredential
syntax in the Run As User field; in your process definition source, you can also use req.setAuthentication(SOAPRequest.REDWOOD_NOCREDENTIAL, null)
; to this effect.
See Also
- Using the RedwoodScript Definition Type
- Using RedwoodScript in Processes
- RedwoodScript
- Integrating Redwood Server with Web Services
- Connecting Web Services with Redwood Server
- Asynchronous Web Services
- Credentials
webservice