Pega mashup / IAC troubleshooting : "PRGateway Exception: error response from PRPC" when preview Gadget
I am working on a proof of concept for a customer in Germany, and the customer requires a Pega Mashup: a PRPC work object to be embedded into their corporate webpage.
As is often the case at a security-conscious customer site, access to the customer's servers is going to be very restricted. Therefore we wish to create a proof of concept, a pilot installation of the mashup ahead of the actual implementation in order to determine and then document precisely all the configuration needed.
To do this, we are using a 'VMWare' PRPC instance running on a laptop, and on the same laptop a 'Tomcat' servlet container to run Pega Composite Gateway 'prgateway.war', and later on we will be using an Apache webserver instance to serve a mockup of the customer's webpage with our embedded Gadget inside it. The Gadget can be tested just using Tomcat - for detailed instructions to do this, see below.
The problem is, PRGateway can generate my Gadget successfully but I cannot run the gadget connecting via PRGateway; my gadget will only run as a standalone file connecting directly to prpc. If I open the Gadget using the PRGateway 'Preview' button at the bottom of the Gadget Setup screen, I get "PRGateway Exception: error response from PRPC".
There are NO errors in the Pega logs. There is infact nothing in the Pega logs to indicate the connection was even attempted.
The PRGateway logs are in Tomcat, files in the tomcat\temp directory 'PRPCGateway-2016-Apr-08_0_0.log, after setting the PRGateway log details level to 'CONFIG', I am seeing an entry "INFO: Response Status=400" and I assume this is the standard http code 'Bad Request'.
Downloading and editing the Gadget files in a new directory, we can set the pega.web.config.gatewayURL to connect directly to the PRPC instance instead of via PRGateway (line 8 in the Gadget html file) and then open the file using, say, Firefox. This works beautifully, and the Gadget displays exactly as hoped. However we must use PRGateway in the real installation as it performs the task of a reverse-proxy server for PRPC, and the customer's network design requires this.
Does anybody have any suggestions for troubleshooting this?
Oops almost forgot: Instructions to setup PRPC on VMware and local Tomcat to use as test environment:
There is a lot of detailed documentation on PDN and in various Academy courses on Pega Mashup/IAC, but after going through it all it was found that getting started with an example Pega in a gadget is surprisingly quick and easy. Proceed as follows:
Obtain a Pega VMWare PVS system (I used the one from the Pega Academy SSA course, which is Pega 7.1.6). Obtain the Pega Composite Gateway .war file for that version of Pega - I phoned GCS in Reading to request it, and they emailed it to me. Start the VMWare system and log on to its console (username 'architect', password 'password'). Type 'ifconfig' on the command line, and record the ip address that the VMware instance is serving, in my case 192.168.184.188. To make life easier, map this IP address to 'prpc' in your hosts file (add the line " 192.168.184.188 prpc " to the bottom of the text file C:\Windows\System32\drivers\etc\hosts ).
Determine PRPC task to embed in the mashup, and configure PRPC for this. Run the VMWare system, and log on to it with a browser (http://prpc:8080/prweb/PRServlet username='admin@sae', password='rules'). The Application on my system is called 'HRServices', and it has a case called 'Candidate' which is the process for a potential employee to register with name and address etc. I wish to embed this process in my mashup.
The ruleset 'Pega-IAC:07-10-14' must be added to the Application 'HRServices' we are going to use. This ruleset is present ootb on PRPC 7, but it will not be in the Application stack by default, it must be added.
Identify both the class and the starting flow of the Case we are to embed in the mashup. In this case, it is 'SAE-HRServices-Work-Candidate.pyStartCase'.
Create an operator for the mashup to use - just do a SaveAs of the 'admin@sae' operator you are using, I called mine 'operatorIAC@sae', and set its password to be 'rules7'.
We need to add the line '<env name="Authentication/RedirectGuests" value="false"/>' into the Pega prpc 'prconfig.xml' file. I suggest you use a proper tty emulation rather than the VMWare console (PuTTY is good), the command 'find / -name 'prconfig.xml -print' will show you where it is, and use 'su' to select root account, password is 'password' and then use vi to add the entry. Reboot Pega, using the 'shutdown -h now' command and restarting VMWare afterward.
All the rest of the configuration (the IAC Authentication Service, the IAC servlet etc.) is already present ootb, in Pega-7.
Install Tomcat on your laptop. There are lots of ways for doing this but the easiest is 'xampp' which can be downloaded for free and its installer will install it. Choose a directory, I installed mine in directory 'C:\xampp'. To make life easier, choose a directory name without space chars in it. Use the xampp console to start tomcat.
Install Pega Composite Gateway onto tomcat. This couldn't be easier, just copy your file 'prgateway.war' into the directory 'C:\xampp\tomcat\webapps', stop and restart tomcat. By default tomcat will be serving on 'localhost', so log on to the Pega Composite Gateway using http://localhost:8080/prgateway and you should see the Pega IAC Gateway Configuration Console. (Note, the prgateway console has a very Pega-6.2 look to it; this is normal, I have found only the Pega 7.19 version of prgateway looks like its Pega-7.)
Configure a Mashup Gadget. In prgateway, we first configure a Host, then setup a Gadget, then Preview it.
Click 'Host Configuration', enter a name for your connection e.g. 'PVSprpc', enter its host URL e.g. http://prpc:8080/prweb/PRServlet then enter its Auth Servlet http://prpc:8080/prweb/IAC , this Auth servlet is configured ootb in Pega 7. Hit 'Test Connection', you should get 3 green lights; hit 'Save Connection'.
Click 'Gadget Setup', select the Host you have just configured, 'PVSprpc'. Enter the username and password of the prpc account to use 'operatoriac@sae', 'rules7' and Submit. Then wait a while! First-Use Assembly takes a surprising long time for the IAC rules. Eventually, the 'Gadget Generation' section appears.
Configure your Gadget. Enter a name for it 'CandidateEntry', select Pega Action 'Create a new work object (createNewWork). Enter your class name 'SAE-HRServices-Work-Candidate', Display Model 'empty', Flow name 'pyStartCase'. In 'Advanced Settings', select Gadget Target '_self'. And that’s it. Note, open 'User Defined parameters', you should see the username you entered and the Password, encoded in base64. Use an online decoder, to decode the password and then verify that it IS the password for the user account you set up.
Preview the Mashup Gadget. Click the 'Preview' button. The preview window opens. In my case it contains "PRGateway Exception: error response from PRPC". To test your gadget without using prgateway, click 'Download Web Files' button, you are prompted to save a zip file containing your Gadget 'CandidateEntry.zip'. Save this file into a new directory elsewhere in your filesystem, 'C:\temp'.
Open the 'CandidateEntry.zip' zipfile and extract the contents to disk, there are three files: 'CandidateEntry.html', 'PegaInternetApplicationComposer.js', and 'PegaInternetApplicationComposerLog.js'.
Open 'CandidateEntry.html' using a text editor e.g. 'notepad++'. Un-comment the 5th line <script src="PegaInternetApplicationComposerLog.js"></script> note this is html-style commenting. Comment out the prgateway URL on line 7, and comment in the direct prpc URL on line 8, we want the value pega.web.config.gatewayURL = "http://prpc:8080/prweb/PRServlet"; to be executed, note inside the <script> tag this is Java-style commenting.
Save the file. Right-click on the file in the directory, and in the RH mouse menu select 'Open With … Firefox'.
And your gadget opens, with the embedded new Candidate work object. A popup window also opens (check Firefox popups are enabled) containing the Gadget logging.
PRPCgateway is needed because of same origin policy used by browsers for security reasons. This means the AJAX request coming from a browser cannot have response coming from different domain. When you integrate a gadget in customer Portal , the Portal is usually in a different domain than where the PRPC instance would be running. So gateaway is required in this "real-life" case.
Additionally this gateway can also hide IP details of PRPC instance (which is called reverse proxy) offering additional security benefits.
Thanks, I am aware of this. I know that PRPCGateway performs two very important functions for us:
2. Secondly at run-time, it performs the function of a 'reverse proxy', to serve the Pega system to the gadget to be used by the outside world without exposing the Pega system itself, so allowing the Pega system to run behind a firewall in the customer's intranet.
My problem is that my gadget will run perfectly well as a flat file, where browser connects directly to PRPC. But if I try to use exactly the same html code via PRGateway, I just get "PRGateway Exception: error response from PRPC" and no further indication anywhere, in Pega logs, PR Gateway logs, etc, as to what problem is except in PRGateway log we see "INFO: Response Status=400" which is http response code for "Bad request". But that is it; no further information.
I need something for Show and Tell next week. As generation of Gadget code works Ok, I am experimenting with using something else to perform the reverse proxy function instead of PRGateway, a 3rd-party reverse proxy from SourceForge called "j2EP" on Tomcat.
I wish there was a better solution, I really want PRGateway to work and perform function 2. above properly.
Thanks for your reply. I have tried your suggestion of using directly the IP address in my Host Connection from prgateway instead of the 'prpc' mapping that I have created on my C:\windows\system32\drivers\etc\hosts file, unfortunately this makes no difference I am still getting "PRGateway Exception: error response from PRPC".
I think my prgateway is connecting to prpc successfully; because when I click 'Test Connection' after creating the host connection I get 3 green lights, and also when I select 'Gadget Setup' and commence filling out the Gadget details, in the 'Pega Action' dropdown I select 'Create a new Work Object' and the Auto-Complete controls for Class Name and Flow name appear. These auto-complete controls are fully populated - I just type in "SAE" in the autocomplete and I get a list of all relevant classes, and I type "py" in the Flow name autocomplete and I can see and select my 'pyStartCase' flow.
For these auto-complete controls to function as they do, the connection with prpc must have been successful.
3. The PRPC Auth Servlet. Now this is where I went wrong: I entered the entire URL here "http://XX.XX.XX.XX:9080/prweb/IAC" however what is actually needed is ONLY the name of the servlet "IAC", the prgateway generates the full url from this.
The consequence of that was that the URL being accessed by PRGateway was malformed, and the Tomcat instance on which prpc runs was returning http:400; the connection was not getting to Pega which is why there was nothing in the Pega logs.
It is worth noting that, when configuring a Host in PRGateway, the 'Test Connection' functionality calls a SOAP service in Pega, it is not done via http; so it is quite possible for the host to be configured Ok and the Test Connection to report everything is good; but PRGateway does not have http access to the PRPC server so the gadget cant run. H/T: Tim Senior.
Thanks everyone, and sorry to bother you with what was, in the end, a silly mistake.