- Created by Avinash Kumar on Oct 27, 2021
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
Version 1 Current »
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
Follow the below steps to create an Implementation Package, considering the name of Connector as 'Sample'
Create ConnectorListener Java class
Create a file named ConnectorListener.java. For example, for Connector "Sample" create file "SampleListener.java" and write class definition as shown below.
SampleListener Expand source// 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 { }
Add Component and Scope annotation to the class.
SampleListener Expand sourcepackage 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 { }
Extend the AbstractListener(com.adeptia.indigo.event.AbstractListener) class and override the "public Vector execute(JobDataMap dataMap, Date nextFireTime,Scheduler scheduler) throws Exception" method.
SampleListener Expand sourcepackage 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; } }
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.
SampleListener Expand sourcepackage 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 } }
Add Connector Name and Connector Display Name fields.
SampleListener Expand sourcepackage 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 } }
Provide definition for activateEvent method as shown below.
SampleListener Expand sourcepackage custom.beans.apps.sample; import com.adeptia.indigo.utils.ConnectorHelper; @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 { ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName); connectorHelper.activateEvent(_subject, event, this.getClass()); } }
Provide definition for execute method as shown below.
SampleListener Expand sourcepackage custom.beans.apps.sample; import com.adeptia.indigo.utils.ConnectorHelper; @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 Connector Helper ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName, dataMap); // Event Logging : Do Start Event Logging connectorHelper.postEventExecutionStart(); // Execute Event return executeEvent(connectorHelper, dataMap); } private Vector executeEvent(ConnectorHelper connectorHelper, JobDataMap dataMap){ return null; } @Override public void activateEvent(Subject _subject, OAuthEvent event) throws ServiceException { ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName); connectorHelper.activateEvent(_subject, event, this.getClass()); } }
Provide definition for executeEvent method.
SampleListener Expand sourcepackage 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.ConnectorHelper; @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 Connector Helper ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName, dataMap); // Event Logging : Do Start Event Logging connectorHelper.postEventExecutionStart(); // Execute Event return executeEvent(connectorHelper, dataMap); } private Vector executeEvent(ConnectorHelper connectorHelper, 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 = connectorHelper.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("ConnectorHelper", connectorHelper); connectorHelper.submitTask(Thread.currentThread(), inputMap); } } else { // Response is not valid connectorHelper.throwResponseCodeNotValidException(response); } } while (condition); vector = connectorHelper.logResultAndgetExecutionVector(Thread.currentThread()); } catch (Exception ex) { connectorHelper.logAndThrowListenerException(ex); } finally { connectorHelper.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 { ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName); connectorHelper.activateEvent(_subject, event, this.getClass()); } }
Save this listener class. See the Complete SampleListner Class below.
SampleListener Expand sourcepackage 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.ConnectorHelper; @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 Connector Helper ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName, dataMap); // Event Logging : Do Start Event Logging connectorHelper.postEventExecutionStart(); // Execute Event return executeEvent(connectorHelper, dataMap); } private Vector executeEvent(ConnectorHelper connectorHelper, 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 = connectorHelper.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("ConnectorHelper", connectorHelper); connectorHelper.submitTask(Thread.currentThread(), inputMap); } } else { // Response is not valid connectorHelper.throwResponseCodeNotValidException(response); } } while (condition); vector = connectorHelper.logResultAndgetExecutionVector(Thread.currentThread()); } catch (Exception ex) { connectorHelper.logAndThrowListenerException(ex); } finally { connectorHelper.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 { ConnectorHelper connectorHelper = new ConnectorHelper(connectorName, connectorDisplayName); connectorHelper.activateEvent(_subject, event, this.getClass()); } }
Create ConnectorHandler java class
Create a file named ConnectorHandler.java. For example for Connector "Sample" create file "SampleHandler.java" and write class definition as shown below.
SampleHandler Expand sourcepackage custom.beans.apps.sample; public class SampleHandler { }
Add Component and Scope annotation to the class.
SampleHandler Expand sourcepackage custom.beans.apps.sample; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @Component("sampleHandler") @Scope("prototype") public class SampleHandler { }
Extend the ResponseHandler class.
SampleHandler Expand sourcepackage 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; } }
Implement RequestHandler Interface.
SampleHandler Expand sourcepackage 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; } }
Implement ReferenceHandler Interface.
SampleHandler Expand sourcepackage 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; } }
Implement LookupProcessor Interface.
SampleHandler Expand sourcepackage 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; } }
- No labels