Web Services Aggregation - Null Pointer Exception

Continuing the discussion from WebService After Rule - Returning The application script threw an exception: java.lang.NullPointerException: Null Pointer in Method Invocation BSF info:

Hello Guys !

I am facing the exact issue. The rule was working fine . All of a sudden it stopped working . The error returned is

sailpoint.connector.ConnectorException: Error: The application script threw an exception: java.lang.NullPointerException: Null Pointer in Method Invocation BSF info: Rule-name After at line: 0 column: columnNo

  • I have tried creating new source
  • I have tried creating a new rule with same code

Please let me know if you have any leads !

Thank you

@sidharth_tarlapally Can you try de-attaching the rule and attach it back and try again? Since you have mentioned it was working previously.

If it doesn’t work can you share us the code here? you need to make sure you are handling the null checks.

Regards,
Shekhar Das

import connector.common.JsonUtil;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.PrintStream;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import sailpoint.tools.GeneralException;
import sailpoint.connector.webservices.WebServicesClient;
import connector.common.JsonUtil;
import connector.common.JsonUtil.JsonParser;
import java.util.Iterator;
import connector.common.Util;

String Usr_UserName="";
	String username = (String) application.getStringAttributeValue("username");  
	log.info("---------------Username declaration--------");  
	String password = (String) application.getAttributeValue("password");  
	log.info("----------------password declaration------------------");  
	String baseUrl=(String) application.getAttributeValue("genericWebServiceBaseUrl");  
	String authenticationURL = baseUrl+"/auth";  
	log.info(authenticationURL);  
	log.info("----------Fetching headers from UI-------------------------");  
	Map headers = requestEndPoint.getHeader();   
	List allowedStatuses = new ArrayList();  
	log.info("------------------Allowed status----------------");  
	allowedStatuses.add("2**");  
	log.info(allowedStatuses);  
	String body = "{"+"\"username\":"+"\""+username+"\""+",\"password\":"+"\""+password+"\""+"}";
	String responseData = restClient.executePost(authenticationURL, body, headers, allowedStatuses);  
	log.info(responseData);
	log.info("------------------Map Creation---------------");  
	Map responseMap = JsonUtil.toMap(responseData);  
	String accessToken = responseMap.get("token");  
	String bearerToken = "Bearer "+accessToken;  
	headers.put("Authorization",bearerToken);  



List user_map_data =  new ArrayList();
List account_IDs = new ArrayList();
	
public List getUserIDs(Map headers,List allowedStatuses){
	
	List all_IDs = new ArrayList();
	String getIDs = "https://domain/admin/getAllUsers";
	String response_in_String = restClient.executeGet(getIDs,headers,allowedStatuses);
	Object response = JsonUtil.parseJson(response_in_String);
	for(int i=0;i<response.size();i++)
	{
		Map elements = response.get(i);
		String userId = elements.get("id") +"";
		all_IDs.add(userId);
	}
	return all_IDs;
}
account_IDs = getUserIDs(headers,allowedStatuses);

	log.info("Collected All Account IDs : List of IDS" + account_IDs);
	for(int i=0;i<account_IDs.size();i++)
	{	
		
			Map user = new HashMap();
			String userid =account_IDs.get(i);
			String getUser = "https://domain.com/admin/getUser?userId="+userid;
			log.info("executing end point " +getUser);
			String response_in_String = restClient.executeGet(getUser,headers,allowedStatuses);
			Object response = JsonUtil.parseJson(response_in_String);
			log.info("response of one user :"+response);
			String username = response.get("username");
			String id = response.get("id")+"";
			String firstName = response.get("firstName");
			String lastName = response.get("lastName");
			String email = response.get("email");
			String domain = response.get("domain");
			String winUserId = response.get("winUserId");
			String loginId = response.get("loginId");
			String empId = response.get("empId");
			String enabled = response.get("enabled")+"";
			List allRoles = new ArrayList();
			
			List roles = new ArrayList();
			roles=response.get("roles");
			if(!roles.isEmpty()){
				for(int j=0;j<roles.size();j++){
					Map role = roles.get(j);
					String roleId = role.get("roleId")+"";
					String role_name = role.get("name");
					String roleName = roleId+"__"+role_name;
					
					List companyList = new ArrayList();
					companyList = role.get("companyList");
					for(int k = 0; k < companyList.size();k++){
						Map company = companyList.get(k);
						String company_name = company.get("name");
						String companyId = company.get("id") + "";
						String companyName = companyId+"__"+company_name;
						
						List unitList = new ArrayList();
						unitList=company.get("units");
						for(int l = 0;l < unitList.size(); l++){
							Map unit =  unitList.get(l);
							String unitName = unit.get("name");
							String unitId = unit.get("id")+"";
							String companyUnit = companyName+"__"+unitId+"__"+unitName;
							String finalRoleName = roleName+"__"+companyUnit;
							allRoles.add(finalRoleName);
						}
						
					}
					
			}		}
			
			}
			
				Map user_map = new HashMap();
				user_map.put("username",username);
				user_map.put("id",id);
				user_map.put("firstName",firstName);
				user_map.put("lastName",lastName);
				user_map.put("email",email);
				user_map.put("domain",domain);
				user_map.put("winUserId",winUserId);
				user_map.put("loginId",loginId);
				user_map.put("empId",empId);
				user_map.put("enabled",enabled);
				user_map.put("roles",allRoles);
				user_map_data.add(user_map);
			
	}
processedResponseObject.addAll(user_map_data);

@sidharth_tarlapally Are you sure whether this rule was working previously?

Few observations:

  1. Please read the document and example given as to what you need to set and return. (I do not see you are returning anything)
    IdentityNow Rule Guide - Web Services After Operation Rule - Compass (sailpoint.com)
  2. Not sure why are you not using parent child configuration to get user data like in aggregation1 - you will get all Id’s and in aggregation2 - you will get the attributes of those ids (assuming you are not getting all the attributes in first call). Then you can use a rule to edit role info in a after rule.
  3. Use a method to generate a token.
public String getNewToken() throws GeneralException
	{
		log.debug("Entering Example_BeforeOperation_Rule: getNewToken method");

		OkHttpClient client = null;
		Response response = null;
		String newToken = null;
		
		try
		{
			String baseUrl = (String) application.getAttributeValue("genericWebServiceBaseUrl");
			String loginUrl = "/authentication/Login";
			String finalUrl = baseUrl + loginUrl;
			
			String bodyContent = "{\r\n    \"username\": \""+ application.getAttributeValue("username") +"\",\r\n    \"password\": \""+ application.getAttributeValue("password") +"\"\r\n}";

			client = new OkHttpClient().newBuilder().build();
			MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
			RequestBody body = RequestBody.create(mediaType, bodyContent);
			Request request = new Request.Builder().url(finalUrl).method("POST", body).addHeader("Content-Type", "application/x-www-form-urlencoded").build();
			response = client.newCall(request).execute();

			if (!response.isSuccessful())
			{
				throw new IOException("Unexpected code in getNewToken()" + response + " || " + response.body().string());
			}

			// Get response body
			log.debug("Retrieving new toekn fromt he response...");
			String res = response.body().string();
			JSONObject jObject = new JSONObject(res);
			newToken = jObject.getString("sessionId");
		}
		catch (Exception e)
		{
			log.error("Error while generating new token...." + e.getMessage());
			throw new GeneralException("Error while generating new token...." + e.getMessage());

		}
		finally
		{
			if (null != response)
			{
				response.body().close();
			}
		}

		log.debug("Exiting Example_BeforeOperation_Rule : getNewToken method");
		return newToken;
	}

Regards,
Shekhar Das

1 Like

Could you please provide the whole log of the exception so we can see what Line it ends on?

It could be that there is an account or anything on the endpoint that the rule is trying to call but is no longer present in either the endpoint or in ISC itself. It may be best to remove the rule, complete an aggregation and look for any changes, then rebuild the rule based off of those changes.

Hello everyone , the issue is resolved . I have included null checks in every code block and it worked.
Thank you

1 Like

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