Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Linkage error in Exact target with AEM6.1

Avatar

Community Advisor

Hi,

I have followed all the steps given in the document and able to successfully connect via Exact Target through AEM.

But, issue is when i'm calling the Exact Target API method of AEM.

Please find the JAVA code for the same:

package com.test.test2;     

import java.io.IOException;
import java.rmi.ServerException;

import javax.servlet.ServletException;

import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;

import com.day.cq.mcm.exacttarget.ExactTargetService;
import com.day.cq.mcm.exacttarget.ExactTargetException;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference; 
import java.util.HashMap;
import java.util.Map;
import com.day.cq.mcm.exacttarget.client.Subscriber;
import com.day.cq.mcm.exacttarget.client.SubscriberList;
import com.day.cq.mcm.exacttarget.client.SubscriberStatus;


@SlingServlet(paths="/bin/exactTarget/createSub", methods="POST", metatype=true)

public class ExactTargetServlet extends SlingAllMethodsServlet {

    private static final long serialVersionUID = 155466L;

    private static final Logger log = LoggerFactory.getLogger(ExactTargetServlet.class);
    
    @Reference
    private ExactTargetServiceInt ext;
    
    @Override
    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServerException, IOException  {

            log.info("Inside doPost");
            try {
            ExactTargetServiceInt exactTargetInt = getServiceReference(ExactTargetServiceInt.class);
            //EmailService  exactTargetService = exactTargetInt.getExactTargetServiceInt();
            ExactTargetService  exactTargetService = exactTargetInt.getExactTargetServiceInt();
            ConfigurationManager etConfigMgr = exactTargetInt.getConfigurationManagerInt();
            Configuration configMgr = etConfigMgr.getConfiguration("/content/crizal/us/en");        

            Subscriber subscriber = new Subscriber();
            subscriber.setEmailAddress(request.getParameter("email"));
            
            SubscriberList list = new SubscriberList();
            list.setStatus(SubscriberStatus.Active);
            list.setID(12345);
            subscriber.setLists(new SubscriberList[]{list});
            
            Map<String, Object> map =new HashMap<String, Object>();
            map.put("subscriber", subscriber);
            //exactTargetService.execute(EmailServiceActions.ADD_SUBSCRIBER, map, config);

            
            exactTargetService.addSubscriberToList(configMgr, subscriber);
            log.info("Inside doPost end");    
            }
            catch(ExactTargetException ex) {
                log.error("Exact Target Exception " + ex);
            }
            catch(Exception e) {
                log.error("General Exception " + e);
            }

    }

    /**
     * Gets the service reference either from BundleContext.
     *
     * @param <T>
     *            the generic type
     * @param serviceClass
     *            the class whose reference has to be returned.
     * @return T the service reference
     */
    public static <T> T getServiceReference(Class<T> serviceClass) {
        BundleContext bundleContext = FrameworkUtil.getBundle(serviceClass).getBundleContext();
        ServiceReference<T> osgiRef = bundleContext.getServiceReference(serviceClass);
        return bundleContext.getService(osgiRef);
    } 
}

Let, me know how to resolve it.

2 Replies