Test Connection through Rule

HI all,

Can someone help me with a code snippet to test connection through a rule/

Thanks in advance

Hi Rishav,
Can you please be more elaborate about what kind of application connection you would like to test? Is the application you would like to test already on-boarded?

Thanks,
@SivaLankapalli

@SivaLankapalli yes the applications are on-boarded.

Just need a code where I put the app name as input and the code return the test connection result

Hi @rishavghoshacc ,
You can try this code. It explains how to specify the application name.

public String testApplicationConnection(Application app) {				
    Connector conn = null;
    String connStatus = null;
    try {
      if(app!=null){
        conn = sailpoint.connector.ConnectorFactory.getConnector(app, null);
        
        if(app!=null){
          conn.testConfiguration();
          connStatus  = app.getName()+ " connection is success";
        }
      }
    }
    catch(Exception e){
    connStatus  = app.getName()+ " connection is failed";
    }
  return connStatus;
  }

Thanks,
@SivaLankapalli

1 Like

@SivaLankapalli Getting below error

It appears that you may be missing some imports based on the error you encountered.

 import sailpoint.connector.Connector;
 import sailpoint.object.Application;

Thanks,
@SivaLankapalli

1 Like

@rishavghoshacc try not to do any development for test connection,

See the thread recommended by sailpoint employee,

Testing many application connectors at once - Compass

Solved: Re: Re: How to automate step Application/Test Connection? - Compass

Here is a rule you can use with a rule runner task. Gives success or error in the task result and it is color coded :slight_smile:

‘’’
import sailpoint.object.TaskResult;
import java.util.List;
import java.util.ArrayList;
import sailpoint.connector.Connector;
import sailpoint.connector.ConnectorFactory;
import sailpoint.connector.;
import sailpoint.object.Application;
import sailpoint.object.TaskItemDefinition;
import sailpoint.object.TaskItemDefinition.ProgressMode;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Message;
import sailpoint.tools.Util;
import sailpoint.api.SailPointContext;
import sailpoint.object.
;
import java.lang.reflect.Constructor;
import java.util.*;

//Set app type if desired. Use query instead of null in getObjects statements and getConnector.
String appType = “DelimitedFile”;
//Run Test Connection?
boolean testConnect = true;
String disabled = “-1”;
// List results = new ArrayList();
//Application app = context.getObject(Application.class, “Extended Form”);
// return me;
//Query options for applications
QueryOptions query = new QueryOptions();
// Filter filter = Filter.ignoreCase(Filter.eq(“type”, appType));
Filter filter = Filter.ignoreCase(Filter.notnull(“maintenanceExpiration”));
query.addFilter(filter);
public Message msg(String s) {
return new Message(s,null); }
List apps = context.getObjects(Application.class, query);
// return apps;
if (testConnect) {
Iterator It = context.getObjects(Application.class, null).iterator();
while (It.hasNext()) {
Application app = It.next();
String name = app.getName();
Boolean me = app.isInMaintenance();
if (me == false) {
try {
Connector connector = sailpoint.connector.ConnectorFactory.getConnector(app, null);
connector.testConfiguration();
taskResult.addMessage(name+“: Test Connection Successful”);
} catch (Exception e) {
taskResult.addMessage(Message.error("Error- “+name+”: ! "+e.getMessage()));
log.error(e);
}
}
}
}
if(taskResult!=void) {
return “Success”; }

‘’’