Executepost method is not giving response in before webservices rule

Hi,

Can some one suggest/ assist regarding the below issue.

I am facing the strange issue when trying to fetch the access token in before rule of webservices connector. As i can see the logic when i try to execute on iiq it’s giving access token but in ISC from logs i can see it is stooping at executepost call /exact post request call. I tried with below 2 codes which have no issue in code and able to get token from iiq but in ISC they are getting stopping at executepost call.

Can some one suggest do i need to do any settings even i tried to increase timedout but no luck…

Code 1: Using executePost

WebServicesClient client = new WebServicesClient();
      Map args = new HashMap();
      args.put(WebServicesClient.ARG_URL, url);
      client.configure(args);
      List allowedStatuses = new ArrayList();
      allowedStatuses.add("2**");
      Map headerMap = new HashMap();
      headerMap.put("Content-Type", "application/x-www-form-urlencoded");
      
      Map payLoad = new HashMap();
      payLoad.put("username", ".........");
      payLoad.put("grant_type", "password");
      payLoad.put("password", "........");
      String response = client.executePost(url, payLoad, headerMap, allowedStatuses);    -----> **code execution is stopping here in logs not able to get success message as if it is exception it's throwing exception**

Code 2: Which is working in iiq but in ISC it is not executing connect
‘’’

String POST_PARAMS = "userName=emailvalue&password=passwordvalue&grant_type=password";
URL obj = new URL(tokenUrl);Preformatted text
HttpURLConnection httpURLConnection = (HttpURLConnection) obj.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
  httpURLConnection.connect();  ---- *Its getting stopping here. In logs i am not able to get any logs post this*
OutputStream os = httpURLConnection.getOutputStream();
  os.write(POST_PARAMS.getBytes());
  os.flush();
  os.close();
  log.error(LOG_PREFIX + "After URL method:: ");  
  int responseCode = httpURLConnection.getResponseCode();
  log.error(LOG_PREFIX + "Response code:::"+responseCode);

‘’’

Hi @guttays,

When working with ISC, it’s important to be aware of certain nuances. Not everything that works in IIQ will function the same way in ISC. We must carefully consider the allowed objects, methods, and classes as specified in the ISC Javadoc.

You can try the approach below to perform executePost:

//Base URL and API Token 
String BASE_URL = (String) application.getAttributeValue("genericWebServiceBaseUrl");
String ACCESS_TOKEN = (String) application.getAttributeValue("accesstoken");
String API_URL_TO_HIT = BASE_URL+"<specific context url you want to hit>";

//API headers 
Map headers = (Map) requestEndPoint.getHeader();
String accesstoken = "Bearer "+ACCESS_TOKEN; 
headers.put("Authorization",accesstoken);
headers.put("Content-Type", "application/x-www-form-urlencoded");
 
//Define Payload
Map payLoad = new HashMap();
payLoad.put("<key>", "<value>");

//API allowed status 
List allowedstatus = new ArrayList(); 
allowedstatus.add("2**"); 

String response = restClient.executePost(API_URL_TO_HIT, headers, payload, allowedstatus);

Also, FYI, you can go through the below references while working with web services before operation rules in ISC:

Thanks,
Arshad.

Hi Arshad,

sure I am planning to get the token from post url instead of passing it in source configuration.

I tried the same process but don’t know why it is not going through executePost in logs, i am not able to see any exceptions also

WebServicesClient client = new WebServicesClient();
      Map args = new HashMap();
      args.put(WebServicesClient.ARG_URL, url);
      client.configure(args);
      List allowedStatuses = new ArrayList();
      allowedStatuses.add("2**");
      Map headerMap = new HashMap();
      headerMap.put("Content-Type", "application/x-www-form-urlencoded");
      
      Map payLoad = new HashMap();
      payLoad.put("username", ".........");
      payLoad.put("grant_type", "password");
      payLoad.put("password", "........");
      String response = client.executePost(url, payLoad, headerMap, allowedStatuses);    -----> **code execution is stopping here in logs not able to get success message as if it is exception it's throwing exception**

‘’’

@guttays, It is because you are reinitializing a new object for WebServicesClient and using that instead of using the connector provided object.

Do not re-initialize a new object, instead use restClient. I’ve provided the updated code below:

//WebServicesClient client = new WebServicesClient();
Map args = new HashMap();
args.put(WebServicesClient.ARG_URL, url);
restClient.configure(args);
List allowedStatuses = new ArrayList();
allowedStatuses.add("2**");
Map headerMap = new HashMap();
headerMap.put("Content-Type", "application/x-www-form-urlencoded");

Map payLoad = new HashMap();
payLoad.put("username", ".........");
payLoad.put("grant_type", "password");
payLoad.put("password", "........");
String response = restClient.executePost(url, payLoad, headerMap, allowedStatuses);

The first line must be removed from the rule, hence I’ve commented it and made some other changes in the rule.

Thanks,
Arshad.

No Arshad i have replaced client with restClient and removed re-initialize a new object But still the same issue it’s not passing the executePost call.

Can you share the entire code to see if there’s something else that’s breaking the execution of the rule?

Hi @guttays

I checked the code you have provided and see that in body you are passing grant type as password which is not correct and it should be client_credential.

Can you please try that and let me know if it works.

Thank You.
Regards
Vikas

@guttays why are you using a before operation rule .you can also achieve this using custom authentication as well.

Hi Vikas,

grant type as password is valid one as vendor wants this grant_type. If we keep grant_type as client_credential it’s failing from postman also…

Hi Shantanu,

Can you please suggest if you have any reference docs.

Hi @guttays

Are you trying to retrieve the access token for ISC or is it for some other application ? If it is the other application , can you please share the screenshot from the postman where it is working so I can suggest further.

Thank You.

I am trying it for other application to get token and use that token in other operations.

Hi ,

this issue was resolved as it is due to network issue.

Now i am facing another issue when calling the GET API call as i have body as raw json . When i am passing the jsonbody as json raw using Custom Authentication. in the webservices call it’s not accepting the body.

Can anyone suggest how to make the GET call with json body type. Even i kept header as application/json

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.