Saturday, 22 April 2017

Integrate AEM with Docusign - Part 1

Integrate AEM with Docusign to get Docusign account information

What is Docusign?

DocuSign® is The Global Standard for Digital Transaction Management. Accessible anytime, anywhere on any device, global enterprises, business departments, individual professionals, and consumers in all industries solve their paper problems by replacing manual, paper-based methods with DocuSign. The result is accelerated transactions that increase speed to results, reduce costs, improve visibility and control, and delight customers. DocuSign helps you keep business digital with the easiest, fastest, most secure way to send, sign, manage and store documents in the cloud.

Why Docusign?

Sample servlet code to get Docusign account information.

package com.kishore.salesforce.docusign;

 * Docusign integration

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(name = "com.kishore.salesforce.docusign.GetDocusignAccountInfo", label = "AEM Docusign - GetDocusignAccountInfo", immediate = true, metatype = true)
@Properties({ @Property(name = "service.description", value = "Get Docusign Account Info"),
        @Property(name = "service.vendor", value = "AEM Quickstart"),
        @Property(name = "docuserviceurl", value = ""),
        @Property(name = "docuusername", value = "[email protected]"),
        @Property(name = "docupassword", value = "XXXXXX"), 
        @Property(name = "sling.servlet.paths", value = "/services/docusign/GetDocusignAccountInfo", propertyPrivate = true),
        @Property(name = "sling.servlet.methods", value = "POST"),
        @Property(name = "integratorkey", value = "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx") })
public class GetDocusignAccountInfo extends SlingAllMethodsServlet implements Serializable{

    /** The log. */
    private Logger log = LoggerFactory.getLogger(GetDocusignAccountInfo.class);

    private static final long serialVersionUID = 1L;

    private String serviceUrl;
    private String serviceBaseUrl;
    private String userName;
    private String password;
    private String integratorkey;
    private String proxyurl;
    private String proxyport;
    private String accountid;

    protected void doGet(SlingHttpServletRequest request,
               SlingHttpServletResponse response) throws ServletException
              doPost(request, response);
    public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException {"doPost Started");"serviceUrl :" + serviceUrl);"userName" + userName);"password " + password);"integratorkey:" + integratorkey);"serviceBaseUrl: "+serviceBaseUrl);
        JSONObject obj = new JSONObject();
        String finalUrl=null;
        try {
            obj.put("Username", userName);
            obj.put("Password", password);
            obj.put("IntegratorKey", integratorkey);
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet getRequest = new HttpGet(serviceUrl);
            HttpHost proxy = new HttpHost(proxyurl, Integer.parseInt(proxyport));
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            getRequest.addHeader("X-DocuSign-Authentication", obj.toString());
            HttpResponse responseHttp = httpClient.execute(getRequest);
  "Status Code" + response.getStatusLine().getStatusCode());
            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer result = new StringBuffer();
            String line = "";
            while ((line = rd.readLine()) != null) {
  "Docusgin Account details: "+result);

        } catch (JSONException e) {
            log.error("Json Exception details :"+ e.toString());
        } catch (Exception e) {
            log.error("Exception details :"+ e.toString());
        }"doPost Ended");


     * default activate method.
     * @param context
     *            the context
     * @throws Exception
     *             the exception
    protected void activate(ComponentContext context) throws Exception {"activate method called");
        Dictionary properties = context.getProperties();
        serviceUrl = (String) properties.get("docuserviceurl");     
        userName = (String) properties.get("docuusername");
        password = (String) properties.get("docupassword");
        integratorkey = (String) properties.get("integratorkey");


Sample Response:

          "loginAccounts": [
              "name": "AEM Quickstart",
              "accountId": "XXXXX",
              "baseUrl": "",
              "isDefault": "true",
              "userName": "kishore polsani",
              "userId": "XXXX-XXXX-XXXXX-XXXXX",
              "email": "[email protected]",
              "siteDescription": ""

1 comment :

  1. I recognize the author for his dazzling work for creation this extraordinarily helpful and instructive content to guide us.
    salesforce integration