Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Once you create a REST type custom connector, you need to add Implementation Package for this custom connector. The document describes how to create an Implementation Package for a connector.

Content of Implementation Package

An Implementation Package contains the below files:

  • ConnectorListener.class
  • ConnectorHandler.class

You need to bundle these classes with the package structure into the following jars, put them in a single zip, and then upload the zip file:

  • ConnectorNameListener.jar
  • ConnectorNameHandler.jar

Follow the below steps to create an Implementation Package, considering the name of Connector as 'Sample'

  1. Create ConnectorListener Java class

    1. Create a file named ConnectorListener.java. For example, for Connector "Sample" create file "SampleListener.java" and write class definition as shown below.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      // The package name should always start with custom.beans.apps prefix followed by dot connector name in lower case.
       
       
      package custom.beans.apps.sample;
       
       
      public class SampleListener {
       
      }


    2. Add Component and Scope annotation to the class.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       /*
        * The class needs to be annotated
        * with @Component(org.springframework.stereotype.Component) annotation
        * as @Component({ConnectorName}Listener)
        * and @Scope(org.springframework.context.annotation.Scope) annotation
        * as @Scope("prototype").
        * For example: @Component("sampleListener")
        * @Scope("prototype")
        */
       
       
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener {
       
      }


    3. Extend the AbstractListener(com.adeptia.indigo.event.AbstractListener) class and override the "public Vector execute(JobDataMap dataMap, Date nextFireTime,Scheduler scheduler) throws Exception" method.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import java.util.Date;
      import java.util.Vector;
       
      import org.quartz.JobDataMap;
      import org.quartz.Scheduler;
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      import com.adeptia.indigo.event.AbstractListener;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener {
       
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              return null;
          }
       
      }


    4. Implement the AdapterEvent(com.adeptia.indigo.event.oauth.AdapterEvent) interface and provide definition for the "public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException" method.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import java.util.Date;
      import java.util.Vector;
       
      import javax.security.auth.Subject;
       
      import org.quartz.JobDataMap;
      import org.quartz.Scheduler;
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      import com.adeptia.indigo.event.AbstractListener;
      import com.adeptia.indigo.event.oauth.AdapterEvent;
      import com.adeptia.indigo.event.oauth.OAuthEvent;
      import com.adeptia.indigo.services.ServiceException;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              // TODO Auto-generated method stub
               
          }
      }


    5. Add Connector Name and Connector Display Name fields.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import java.util.Date;
      import java.util.Vector;
       
      import javax.security.auth.Subject;
       
      import org.quartz.JobDataMap;
      import org.quartz.Scheduler;
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      import com.adeptia.indigo.event.AbstractListener;
      import com.adeptia.indigo.event.oauth.AdapterEvent;
      import com.adeptia.indigo.event.oauth.OAuthEvent;
      import com.adeptia.indigo.services.ServiceException;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          String connectorDisplayName = "Sample";
       
          String connectorName = "sample";
           
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              // TODO Auto-generated method stub
               
          }
       
      }


    6. Provide definition for activateEvent method as shown below.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import com.adeptia.indigo.helper.ListenerHelper;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          String connectorDisplayName = "Sample";
       
          String connectorName = "sample";
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              ListenerHelper listenerHelper = new ListenerHelper(this.connectorName, this.connectorDisplayName);
              listenerHelper.activateEvent(_subject, event, this.getClass());
          }
      }


    7. Provide definition for execute method as shown below.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import com.adeptia.indigo.utils.ListenerHelper;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          String connectorDisplayName = "Sample";
       
          String connectorName = "sample";
       
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              // Get Listener Helper
              ListenerHelper listenerHelper = new ListenerHelper(connectorName, connectorDisplayName, dataMap);
       
              // Event Logging : Do Start Event Logging
              listenerHelper.postEventExecutionStart();
       
              // Execute Event
              return executeEvent(listenerHelper, dataMap);
          }
       
          private Vector executeEvent(ListenerHelper listenerHelper, JobDataMap dataMap){
              return null;
          }
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              ListenerHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName);
              listenerHelper.activateEvent(_subject, event, this.getClass());
          }
       
      }


    8. Provide definition for executeEvent method

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import static com.adeptia.indigo.event.EventConstants.ENTITY_NAME;
      import static com.adeptia.indigo.services.webservice.WebServiceConstants.RESPONSE;
       
      import java.io.InputStream;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Vector;
       
      import javax.security.auth.Subject;
      import javax.ws.rs.core.MediaType;
      import javax.ws.rs.core.MultivaluedHashMap;
      import javax.ws.rs.core.Response;
       
      import org.quartz.JobDataMap;
      import org.quartz.Scheduler;
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      import com.adeptia.api.rest.utils.RestUtils;
      import com.adeptia.indigo.event.AbstractListener;
      import com.adeptia.indigo.event.oauth.AdapterEvent;
      import com.adeptia.indigo.event.oauth.OAuthEvent;
      import com.adeptia.indigo.services.ServiceException;
      import com.adeptia.indigo.utils.ListenerHelper;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          String connectorDisplayName = "Sample";
       
          String connectorName = "sample";
       
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              // Get Listener Helper
              ListenerHelper listenerHelper = new ListenerHelper(connectorName, connectorDisplayName, dataMap);
       
              // Event Logging : Do Start Event Logging
              listenerHelper.postEventExecutionStart();
       
              // Execute Event
              return executeEvent(listenerHelper, dataMap);
          }
       
          private Vector executeEvent(ListenerHelper listenerHelper, JobDataMap dataMap) throws ServiceException {
              Vector vector = null;
              try {
                  // Pagination Mechanism
                  boolean condition = false;
                  Map<String, Object> inputMap = null;
                  do {
                      // Hit API to get Response
                      Response response = listenerHelper.getResponseObject(getRequestMediaType(), getResponseMediaType(),
                              getHeadersMap(), getQueryParamsMap(), getRequestBody());
                      if (isValidResponseStatusCode(response)) {
                          // Validate the response and Take Action
                          if (isValidResponse(response)) {
                              inputMap = new HashMap<String, Object>();
                              inputMap.put(RESPONSE, response.readEntity(String.class));
                              inputMap.put(ENTITY_NAME, dataMap.getString(ENTITY_NAME));
                              inputMap.put("ListenerHelper", listenerHelper);
                              listenerHelper.submitTask(Thread.currentThread(), inputMap);
                          }
                      } else {
                          // Response is not valid
                          listenerHelper.throwResponseCodeNotValidException(response);
                      }
                  } while (condition);
                  vector = listenerHelper.logResultAndgetExecutionVector(Thread.currentThread());
              } catch (Exception ex) {
                  listenerHelper.logAndThrowListenerException(ex);
              } finally {
                  listenerHelper.cleanUp();
              }
              return vector;
          }
           
          private boolean isValidResponseStatusCode(Response response) {
              return RestUtils.isValidStatusCode(response.getStatus());
          }
       
          private boolean isValidResponse(Response response) {
              return true;
          }
       
          private MultivaluedHashMap<String, Object> getHeadersMap() {
              MultivaluedHashMap<String, Object> headersMap = new MultivaluedHashMap<String, Object>();
              return headersMap;
          }
       
          private MultivaluedHashMap<String, String> getQueryParamsMap() {
              MultivaluedHashMap<String, String> queryParamsMap = new MultivaluedHashMap<String, String>();
              return queryParamsMap;
          }
       
          private InputStream getRequestBody() {
              return null;
          }
       
          private String getRequestMediaType() {
              return MediaType.APPLICATION_JSON;
          }
       
          private String getResponseMediaType() {
              return MediaType.APPLICATION_JSON;
          }
       
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              ListenerHelper listenerHelper = new ListenerHelper(connectorName, connectorDisplayName);
              listenerHelper.activateEvent(_subject, event, this.getClass());
          }
       
      }


    9. Save this listener class. See the complete SampleListner class below.

      Code Block
      languagejava
      titleSampleListener
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import static com.adeptia.indigo.event.EventConstants.ENTITY_NAME;
      import static com.adeptia.indigo.services.webservice.WebServiceConstants.RESPONSE;
       
      import java.io.InputStream;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Vector;
       
      import javax.security.auth.Subject;
      import javax.ws.rs.core.MediaType;
      import javax.ws.rs.core.MultivaluedHashMap;
      import javax.ws.rs.core.Response;
       
      import org.quartz.JobDataMap;
      import org.quartz.Scheduler;
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      import com.adeptia.api.rest.utils.RestUtils;
      import com.adeptia.indigo.event.AbstractListener;
      import com.adeptia.indigo.event.oauth.AdapterEvent;
      import com.adeptia.indigo.event.oauth.OAuthEvent;
      import com.adeptia.indigo.services.ServiceException;
      import com.adeptia.indigo.utils.ListenerHelper;
       
      @Component("sampleListener")
      @Scope("prototype")
      public class SampleListener extends AbstractListener implements AdapterEvent {
       
          String connectorDisplayName = "Sample";
       
          String connectorName = "sample";
       
          @Override
          public Vector execute(JobDataMap dataMap, Date nextFireTime, Scheduler scheduler) throws Exception {
              // Get Listener Helper
              ListenerHelper listenerHelper = new ListenerHelper(connectorName, connectorDisplayName, dataMap);
       
              // Event Logging : Do Start Event Logging
              listenerHelper.postEventExecutionStart();
       
              // Execute Event
              return executeEvent(listenerHelper, dataMap);
          }
       
          private Vector executeEvent(ListenerHelper listenerHelper, JobDataMap dataMap) throws ServiceException {
              Vector vector = null;
              try {
                  // Pagination Mechanism
                  boolean condition = false;
                  Map<String, Object> inputMap = null;
                  do {
                      // Hit API to get Response
                      Response response = listenerHelper.getResponseObject(getRequestMediaType(), getResponseMediaType(),
                              getHeadersMap(), getQueryParamsMap(), getRequestBody());
                      if (isValidResponseStatusCode(response)) {
                          // Validate the response and Take Action
                          if (isValidResponse(response)) {
                              inputMap = new HashMap<String, Object>();
                              inputMap.put(RESPONSE, response.readEntity(String.class));
                              inputMap.put(ENTITY_NAME, dataMap.getString(ENTITY_NAME));
                              inputMap.put("ListenerHelper", listenerHelper);
                              listenerHelper.submitTask(Thread.currentThread(), inputMap);
                          }
                      } else {
                          // Response is not valid
                          listenerHelper.throwResponseCodeNotValidException(response);
                      }
                  } while (condition);
                  vector = listenerHelper.logResultAndgetExecutionVector(Thread.currentThread());
              } catch (Exception ex) {
                  listenerHelper.logAndThrowListenerException(ex);
              } finally {
                  listenerHelper.cleanUp();
              }
              return vector;
          }
           
          private boolean isValidResponseStatusCode(Response response) {
              return RestUtils.isValidStatusCode(response.getStatus());
          }
       
          private boolean isValidResponse(Response response) {
              return true;
          }
       
          private MultivaluedHashMap<String, Object> getHeadersMap() {
              MultivaluedHashMap<String, Object> headersMap = new MultivaluedHashMap<String, Object>();
              return headersMap;
          }
       
          private MultivaluedHashMap<String, String> getQueryParamsMap() {
              MultivaluedHashMap<String, String> queryParamsMap = new MultivaluedHashMap<String, String>();
              return queryParamsMap;
          }
       
          private InputStream getRequestBody() {
              return null;
          }
       
          private String getRequestMediaType() {
              return MediaType.APPLICATION_JSON;
          }
       
          private String getResponseMediaType() {
              return MediaType.APPLICATION_JSON;
          }
       
       
          @Override
          public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException {
              ListenerHelper connectorHelper = new ListenerHelper(connectorName, connectorDisplayName);
              listenerHelper.activateEvent(_subject, event, this.getClass());
          }
       
      }


  2. Create ConnectorHandler java class

    1. Create a file named ConnectorHandler.java. For example for Connector "Sample" create file "SampleHandler.java" and write class definition as shown below.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      public class SampleHandler {
       
      }


    2. Add Component and Scope annotation to the class.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
       
      @Component("sampleHandler")
      @Scope("prototype")
      public class SampleHandler {
       
      }


    3. Extend the ResponseHandler class.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import java.io.IOException;
      import java.util.HashMap;
      import java.util.Map;
       
      import javax.ws.rs.core.MultivaluedHashMap;
      import javax.ws.rs.core.Response;
      import javax.xml.parsers.ParserConfigurationException;
       
      import org.springframework.context.annotation.Scope;
      import org.springframework.stereotype.Component;
      import org.xml.sax.SAXException;
       
      import com.adeptia.api.rest.adapter.AdapterModel;
      import com.adeptia.api.rest.adapter.Trigger;
      import com.adeptia.indigo.event.oauth.filter.Filters;
      import com.adeptia.indigo.exception.SystemException;
      import com.adeptia.indigo.services.webservice.rest.ResponseHandler;
      import com.adeptia.indigo.system.Context;
       
      @Component("sampleHandler")
      @Scope("prototype")
      public class SampleHandler extends ResponseHandler {
       
          @Override
          public String fetchTestData(String url, Trigger trigger, String signatureMethod, String accountId,
                  AdapterModel model, MultivaluedHashMap<String, String> queryMap) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public StringBuilder fetchPaginationData(HashMap<String, Object> inputMap, String URL, String responseContentType,
                  String requestContentType, MultivaluedHashMap<String, Object> headerMap,
                  MultivaluedHashMap<String, String> queryParameterMap, String accountId, String securityPolicyId,
                  String operation, Context context, String encoding, String signatureMethod, int connectTimeout,
                  int readTimeout) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public String getErrorMessage(Response response, String errorXPath) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public Map<String, Object> processData(Thread runningThread, Filters filters, Map<String, Object> inputMap,
                  String chunkFileName) throws IOException, SystemException, SAXException, ParserConfigurationException {
              // TODO Auto-generated method stub
              return null;
          }
       
      }


    4. Implement RequestHandler Interface.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import com.adeptia.indigo.services.webservice.rest.RequestHandler;
      import com.adeptia.indigo.services.webservice.rest.ResponseHandler;
       
      @Component("sampleHandler")
      @Scope("prototype")
      public class SampleHandler extends ResponseHandler implements RequestHandler {
       
       
       
          @Override
          public InputStream processRequest(String entityName, String encoding, String URL, String responseMediaTypeString,
                  String requestMediaTypeString, MultivaluedHashMap<String, Object> headerMap,
                  MultivaluedHashMap<String, String> queryParameterMap, String accountId, String securityPolicyId,
                  String partName, String fileName, String multipartRequestBody, String multipartRequestBodyType,
                  String operation, InputStream inputstream, Context _context, String signatureMethod, int connectTimeout,
                  int readTimeout, String postQueryString) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
      }


    5. Implement ReferenceHandler Interface.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
      import com.adeptia.indigo.services.webservice.rest.ReferenceHandler;
      import com.adeptia.indigo.services.webservice.rest.RequestHandler;
      import com.adeptia.indigo.services.webservice.rest.ResponseHandler;
       
      @Component("sampleHandler")
      @Scope("prototype")
      public class SampleHandler extends ResponseHandler implements RequestHandler , ReferenceHandler{
       
          @Override
          public String getReference(AdapterModel adapterModel, HashMap<String, Object> inputMap, String url,
                  String contentType, String operation) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
          @Override
          public List<Map<String, Object>> getRefFldList(String referenceTo, String refIdFld, String refNameFld, Map jsonMap)
                  throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
       
      }


    6. Implement LookupProcessor Interface.

      Code Block
      languagejava
      titleSampleHandler
      linenumberstrue
      collapsetrue
      package custom.beans.apps.sample;
       
       
      import com.adeptia.api.utils.LookupProcessor;
      import com.adeptia.indigo.services.webservice.rest.ReferenceHandler;
      import com.adeptia.indigo.services.webservice.rest.RequestHandler;
      import com.adeptia.indigo.services.webservice.rest.ResponseHandler;
       
      @Component("sampleHandler")
      @Scope("prototype")
      public class SampleHandler extends ResponseHandler implements RequestHandler , ReferenceHandler, LookupProcessor{
       
       
          @Override
          public String lookup(String entityName, String lookupField, String targetFieldName, String operator,
                  String accountId, String searchValue, Map parameters) {
              // TODO Auto-generated method stub
              return null;
          }
      }