How to Configure SSL/TLS info in javascript while making parallel invocation to two backend URLs?

Am trying to do two parallel concurrent calls to two different back end URLs using JavaScript policy. I was able to do using the code snippet below, but my new back end URLs need SSL/TLS info to be configured. I’ve the created it in keystore and am using it in the JavaScript policy as shown down below. But am not getting any response and it’s failing at the line “var responsepay1= exchange1.getResponse().content;” and am unable to get the response.

Could you please help?

<Javascript timeLimit="200" name="JavaScript-1">
  <DisplayName>JavaScript 1</DisplayName>
  <Properties>
  </Properties>
  <SSLInfo>
    <Enabled>true</Enabled>
    <ClientAuthEnabled>true</ClientAuthEnabled>
    <KeyStore>myKeyStore </KeyStore>
    <KeyAlias>keyStore</KeyAlias>
  </SSLInfo>
  <ResourceURL>jsc://myCode.js </ResourceURL>
</Javascript>

myCode.js

=========

var myrequest1 = new Request(URL1,’GET’, headers);
var calloutresponse1 = httpClient.send(myrequest1);
context.session[‘calloutresponse1’] = calloutresponse1;
var exchange1= context.session[‘calloutresponse1’];
exchange1.waitForComplete(2000);
var responsepay1= exchange1.getResponse().content;
var myrequest2 = new Request(URL2,’GET’, headers);
var calloutresponse2 = httpClient.send(myrequest2);
context.session[‘calloutresponse2’] = calloutresponse2;
var exchange2= context.session[‘calloutresponse2’];
exchange2.waitForComplete(2000);
var responsepay2= exchange2.getResponse().content;
0 3 929
3 REPLIES 3

Something is preventing the call from succeeding.

First thing to check: you have timeLimit="200" on the JS policy, but in the JS code you use exchange.waitForComplete(2000). The waitForComplete(2000) will never wait 2000ms because the policy itself is set to finish within 200ms. This means if the backend server takes more than 200ms, the policy will just stop. It will be interrupted.

If that is not the problem, then I suggest that you simplify the situation. Break it down and solve the problem iteratively.

You want to do parallel asynchronous invocations to 2 backend systems, and one (or both?) of the two backend systems has a specific requirement for 2-wayTLS.

ok, let's break it down.

  1. First, solve the TLS connection. Just do it synchronously, with a single server. Set up the TrustStore and Keystore. invoke the URL1. Make sure you can get the response as expected. If this doesn't work, then you need to sort this connection out. Try different approaches. Maybe try it with nodejs or with ServiceCallout or with a regular HTTPTargetConnection .
  2. Then add the asynchronous part.
  3. Then add the 2nd server

BTW, I think you cannot use a single JS script to invoke one backend that is 2-way TLS and one that is 1-way TLS. The SSLInfo you have stipulates that ClientAuth will be enabled for all httpClient outbound calls. So if you need to do this, you may want to break it up into multiple JS modules, each with a different SSLInfo configuration. Or do it in nodejs.

good luck.

Hi Dino, I've taken care of the time limit, but it's still giving the same error.

ok, and did you try any of the other 5 things I suggested?