JavaScript callback support in httpClient is not working

Hi,

I'm trying httpClient in JavaScript policy to make mock target call with below snippet

function onComplete(response, error) {
  print("inside onComplete",response);
  print("error",error);
  if (response) {
    context.setVariable('example.status', response.status);
  } else {
    context.setVariable('example.error', 'Woops: ' + error);
  }
}

print("before hitting mock server");

// Function callback allowed as an argument. 
httpClient.get("http://mocktarget.apigee.net/json",onComplete);

Callback is not happening with above snippet, Can you please help on this?

If i make a call using waitForComplete() then i was able to see the response. The snippet used in this case is below

var ex1 = httpClient.get("http://mocktarget.apigee.net/json");
ex1.waitForComplete();
if (ex1.isSuccess()) {
  response1 = ex1.getResponse();
  print("response after waitForComplete",response1.content);
  context.setVariable('example.status',response1.status);
} else {
  error = ex1.getError();
  context.setVariable('example.error','Woops: ' + error);
}
1 8 1,225
8 REPLIES 8

Hi @vinod kumar reddy y,

I experienced the same behavior when I tried this code on my org, however when I tried on other newly created evaluation org, it works! It seems the update - https://docs.apigee.com/release/notes/180608-apigee-edge-public-cloud-release-notes has not been pushed to your org as well as mine, I suggest you to get in touch with Apigee Support to fix this.

Hi Kuldeep,

Thanks for your reply, I had a try with new one as well but not able to view callback triggered

Managing your own Edge instance? Or using SaaS?

Hi Dino,

its a SaaS version.

Hey I'm facing this same thing and my request isn't getting any response and times out post router timeout 

Using private cloud version 4.19.0 which has callback support in it

 

Hi Venkatesh, Can you upgrade to OPDK 4.50?  

@dchiesa1 Upgrading to new version would be difficult, as its shared by multiple tenants
any specific reason for need to upgrade? any bugfix/defect fix?
please let me know

any specific reason for need to upgrade? any bugfix/defect fix?

Yes! 4.19.xx is going out of support imminently! You should upgrade or have a plan to upgrade, quickly.

And also, yes, there are various fixes that we have put into the httpClient since 4.19.xx.