We have successfully implemented REST
Service in Pega. Now let’s implement a REST Connector to invoke the
service!
The normal way of creating a REST
connector is to use the Wizard. To do that, navigate as follows:
Designer Studio > Integration
> Connectors
> Create
REST Integration, as shown below:
Figure 59: Launching the "Create REST Integration" Wizard
You will now be presented with the wizard
as shown below:
Figure 60: "Create REST Integration"
Wizard
By following the 4 steps, you will be
guided by the wizard to create the REST Connector. At the end of it,
the wizard will automatically generate the required class structures of both
the request
message and response message for you.
Another useful capability is that you can
test the invocation directly using the provided tool within the Wizard as shown
below.
Using the Wizard Tool for Testing
In Step 3 of the wizard, you can invoke
the testing tool by clicking on the “Add a REST response” link, as shown
below:
Figure 61: Add a REST Response to Invoke the Wizard Tool for Testing
In the opened dialog, you can choose the method to use.
💡
|
Note: The list of choices available in the “Choose method” dropdown list was selected in Step 2 (Resource methods)!
|
Figure 62: Select a Method for Testing the REST Invocation
Testing the REST GET Method
Let’s test the REST GET method first by
selecting the “GET” method, followed by clicking on the “Run” button.
The following shows the output:
Figure 63: Testing the REST GET Method
Testing the REST POST Method
Now let’s change the method to “POST”.
Notice that we are now provided with a “Request text area” for us to enter
the message data, with the “Content type” initialised to “JSON”
for us.
Figure 64: Sample REST POST Method Screen
Let’s enter the earlier test JSON, followed
by clicking the “Run” button.
{
"name": "Debunkum
Beaver"
}
|
As expected, we will get the Response
JSON with the “WelcomeMsg” and the “YourName”,
as shown below.
Figure 65: Testing the REST POST Method
Remember that we had done simple checks for
invalid Request message data? So, let’s test that too!
To do that, let’s go back to the “Request”
tab, and change the input to some invalid JSON, such as this, after
that, click the “Run” button.
{
"name": "Debunkum
Beaver"
This
is not JSON anymore...
}
|
As expected, we now have both the “Status”
and “errorMessage”
entries, with the “Status” having a value of “false” while “errorMessage” contains
the actual reason for the failure.
Figure 66: Testing the REST POST Method Using an Invalid JSON Input
💡
|
Note: The invalid JSON input should have return a code of 500
instead of 200, however, this is expected since we had hardcoded it as such!
We will address this in the Master Beaver Edition.
|
Generally, using the “REST Connector Wizard” to
create a REST Connector is very simple, intuitive, and useful.
However, there are 3 situations that would
cause potential problems:
- Different REST responses for different scenario
- REST Service is in development and would be changed later
- Limitation of the length of the identifier
Different REST responses for different scenario
If the target REST Service returns
different structure of responses for different outcome, it would not be
feasible to provide all the possibilities or generate all the different outcome
using the “REST Connector Wizard”.
REST Service is in development and would be changed later
If you are in parallel developments, or if
the REST interface changed during development, going through the wizard again and
again or manually adding / deleting those changed attributes would be
horrendous!
Limitation of the length of the identifier
In Step 4 of the Wizard, the identifier for
the generated rules is limited to 25 characters, as shown below.
Figure 67: Identifier Is Limited to 25 Characters
You may not realise the implication of this
problem now, but if you need to group various integrations into related
classes, you will soon be forced to use very weird names!
Therefore, let’s do it differently!
No comments:
Post a Comment