Skip to content

Commit ee8489c

Browse files
committed
2 parents 8892be3 + defd8bd commit ee8489c

10 files changed

Lines changed: 266 additions & 10 deletions

File tree

.factorypath

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<factorypathentry kind="VARJAR" id="M2_REPO/org/glassfish/jaxb/txw2/2.3.6/txw2-2.3.6.jar" enabled="true" runInBatchMode="false"/>
4444
<factorypathentry kind="VARJAR" id="M2_REPO/com/sun/istack/istack-commons-runtime/3.0.12/istack-commons-runtime-3.0.12.jar" enabled="true" runInBatchMode="false"/>
4545
<factorypathentry kind="VARJAR" id="M2_REPO/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar" enabled="true" runInBatchMode="false"/>
46-
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar" enabled="true" runInBatchMode="false"/>
46+
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.24/lombok-1.18.24.jar" enabled="true" runInBatchMode="false"/>
4747
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar" enabled="true" runInBatchMode="false"/>
4848
<factorypathentry kind="VARJAR" id="M2_REPO/org/freemarker/freemarker/2.3.31/freemarker-2.3.31.jar" enabled="true" runInBatchMode="false"/>
4949
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar" enabled="true" runInBatchMode="false"/>
@@ -57,7 +57,7 @@
5757
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/tomcat/embed/tomcat-embed-el/9.0.60/tomcat-embed-el-9.0.60.jar" enabled="true" runInBatchMode="false"/>
5858
<factorypathentry kind="VARJAR" id="M2_REPO/org/eclipse/jdt/ecj/3.18.0/ecj-3.18.0.jar" enabled="true" runInBatchMode="false"/>
5959
<factorypathentry kind="VARJAR" id="M2_REPO/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar" enabled="true" runInBatchMode="false"/>
60-
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-esign-java/3.17.1/docusign-esign-java-3.17.1.jar" enabled="true" runInBatchMode="false"/>
60+
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-esign-java/3.18.0/docusign-esign-java-3.18.0.jar" enabled="true" runInBatchMode="false"/>
6161
<factorypathentry kind="VARJAR" id="M2_REPO/io/swagger/swagger-annotations/1.5.18/swagger-annotations-1.5.18.jar" enabled="true" runInBatchMode="false"/>
6262
<factorypathentry kind="VARJAR" id="M2_REPO/org/glassfish/jersey/core/jersey-client/2.33/jersey-client-2.33.jar" enabled="true" runInBatchMode="false"/>
6363
<factorypathentry kind="VARJAR" id="M2_REPO/jakarta/ws/rs/jakarta.ws.rs-api/2.1.6/jakarta.ws.rs-api-2.1.6.jar" enabled="true" runInBatchMode="false"/>
@@ -88,7 +88,7 @@
8888
<factorypathentry kind="VARJAR" id="M2_REPO/com/brsanthu/migbase64/2.2/migbase64-2.2.jar" enabled="true" runInBatchMode="false"/>
8989
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-rooms-java/1.1.0/docusign-rooms-java-1.1.0.jar" enabled="true" runInBatchMode="false"/>
9090
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-click-java/1.0.0/docusign-click-java-1.0.0.jar" enabled="true" runInBatchMode="false"/>
91-
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-monitor-java/1.0.0/docusign-monitor-java-1.0.0.jar" enabled="true" runInBatchMode="false"/>
91+
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-monitor-java/1.1.0/docusign-monitor-java-1.1.0.jar" enabled="true" runInBatchMode="false"/>
9292
<factorypathentry kind="VARJAR" id="M2_REPO/com/docusign/docusign-admin-java/1.0.0-BETA/docusign-admin-java-1.0.0-BETA.jar" enabled="true" runInBatchMode="false"/>
9393
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/boot/spring-boot-autoconfigure/2.4.4/spring-boot-autoconfigure-2.4.4.jar" enabled="true" runInBatchMode="false"/>
9494
</factorypath>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.docusign.controller.eSignature.examples;
2+
3+
import com.docusign.DSConfiguration;
4+
import com.docusign.common.WorkArguments;
5+
import com.docusign.controller.eSignature.services.ResponsiveSigningService;
6+
import com.docusign.core.model.DoneExample;
7+
import com.docusign.core.model.Session;
8+
import com.docusign.core.model.User;
9+
import com.docusign.esign.api.EnvelopesApi;
10+
import com.docusign.esign.client.ApiClient;
11+
import com.docusign.esign.client.ApiException;
12+
import com.docusign.esign.model.EnvelopeDefinition;
13+
import com.docusign.esign.model.EnvelopeSummary;
14+
import com.docusign.esign.model.RecipientViewRequest;
15+
import com.docusign.esign.model.ViewUrl;
16+
import org.springframework.beans.factory.annotation.Autowired;
17+
import org.springframework.stereotype.Controller;
18+
import org.springframework.ui.ModelMap;
19+
import org.springframework.web.bind.annotation.RequestMapping;
20+
import org.springframework.web.servlet.view.RedirectView;
21+
22+
import javax.servlet.http.HttpServletResponse;
23+
import java.io.IOException;
24+
25+
@Controller
26+
@RequestMapping("/eg038")
27+
public class EG038ControllerResponsiveSigning extends AbstractEsignatureController {
28+
private final Session session;
29+
private final User user;
30+
private static final String SIGNER_CLIENT_ID = "1000";
31+
private static final String FEATURE_WAS_DISABLED = "Please enable this feature in the developer account and try again.";
32+
33+
@Autowired
34+
public EG038ControllerResponsiveSigning(DSConfiguration config, Session session, User user) {
35+
super(config, "eg038", "Use responsive signing");
36+
this.session = session;
37+
this.user = user;
38+
}
39+
40+
@Override
41+
protected Object doWork(WorkArguments args, ModelMap model,
42+
HttpServletResponse response) throws ApiException, IOException {
43+
String signerName = args.getSignerName();
44+
String signerEmail = args.getSignerEmail();
45+
String ccName = args.getCcName();
46+
String ccEmail = args.getCcEmail();
47+
String accountId = session.getAccountId();
48+
ViewUrl viewUrl = null;
49+
50+
EnvelopeDefinition envelope = ResponsiveSigningService.makeEnvelope(
51+
signerEmail,
52+
signerName,
53+
SIGNER_CLIENT_ID,
54+
ccEmail,
55+
ccName,
56+
args);
57+
58+
ApiClient apiClient = createApiClient(session.getBasePath(), user.getAccessToken());
59+
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
60+
61+
try {
62+
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envelope);
63+
64+
String envelopeId = envelopeSummary.getEnvelopeId();
65+
66+
RecipientViewRequest viewRequest = ResponsiveSigningService.makeRecipientViewRequest(
67+
signerEmail,
68+
signerName,
69+
config,
70+
SIGNER_CLIENT_ID);
71+
72+
viewUrl = ResponsiveSigningService.responsiveSigning(
73+
envelopesApi,
74+
accountId,
75+
envelopeId,
76+
viewRequest);
77+
78+
79+
} catch (ApiException apiException) {
80+
DoneExample.createDefault(this.title)
81+
.withMessage(FEATURE_WAS_DISABLED)
82+
.addToModel(model);
83+
}
84+
85+
return new RedirectView(viewUrl.getUrl());
86+
}
87+
}

src/main/java/com/docusign/controller/eSignature/examples/EnvelopeHelpers.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ static Template loadHtmlTemplate(String path) throws IOException {
8181
* @return array of bytes representing created html document
8282
* @throws IOException in case of template parsing error
8383
*/
84-
static byte[] createHtmlFromTemplate(Template template, String objectName, Object value) throws IOException {
84+
static String createHtmlFromTemplate(Template template, String objectName, Object value) throws IOException {
8585
Map<String, Object> input = new HashMap<>();
8686
input.put(objectName, value);
8787
StringWriter stringWriter = new StringWriter();
8888
try {
8989
template.process(input, stringWriter);
90-
return stringWriter.toString().getBytes(StandardCharsets.UTF_8);
90+
return stringWriter.toString();
9191
} catch (TemplateException exception) {
9292
throw new ExampleException("Can't process html template " + template.getName(), exception);
9393
}
@@ -104,7 +104,23 @@ static byte[] createHtmlFromTemplate(Template template, String objectName, Objec
104104
* @return array of bytes representing created html document
105105
* @throws IOException in case of I/O errors or template parsing error
106106
*/
107-
public static byte[] createHtmlFromTemplateFile(String path, String objectName, Object value) throws IOException {
107+
public static byte[] createHtmlFromTemplateFileInByte(String path, String objectName, Object value) throws IOException {
108+
Template template = loadHtmlTemplate(path);
109+
return createHtmlFromTemplate(template, objectName, value).getBytes(StandardCharsets.UTF_8);
110+
}
111+
112+
/**
113+
* Generates a html document from the template file. Placeholder looks like
114+
* ${objectName.fieldName}. It is a convenient method which loads template
115+
* from a file using {@link #loadHtmlTemplate(String)} and creates a html
116+
* page from the loaded template using {@link #createHtmlFromTemplate(Template, String, Object)}
117+
* @param path the path to template file
118+
* @param objectName name of object to find placeholder related to a value
119+
* @param value object which fields are used as a values in the template
120+
* @return array of bytes representing created html document
121+
* @throws IOException in case of I/O errors or template parsing error
122+
*/
123+
public static String createHtmlFromTemplateFile(String path, String objectName, Object value) throws IOException {
108124
Template template = loadHtmlTemplate(path);
109125
return createHtmlFromTemplate(template, objectName, value);
110126
}

src/main/java/com/docusign/controller/eSignature/services/AddDocToTemplateService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.docusign.esign.model.*;
99

1010
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
1112
import java.util.Arrays;
1213
import java.util.Collections;
1314

@@ -125,7 +126,8 @@ private static EnvelopeDefinition makeEnvelope(
125126
signer1AddedDoc.setTabs(signer1Tabs);
126127

127128
// create the HTML document
128-
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args);
129+
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
130+
.getBytes(StandardCharsets.UTF_8);
129131

130132
// create a composite template for the added document and add the recipients via an inlineTemplate
131133
CompositeTemplate compTemplate2 = new CompositeTemplate();

src/main/java/com/docusign/controller/eSignature/services/CollectPaymentService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.docusign.esign.model.*;
99

1010
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
1112
import java.util.Arrays;
1213
import java.util.Collections;
1314

@@ -53,7 +54,8 @@ public static EnvelopeDefinition makeEnvelope(
5354
String gatewayDisplayName,
5455
WorkArguments args
5556
) throws IOException {
56-
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args);
57+
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
58+
.getBytes(StandardCharsets.UTF_8);
5759

5860
// create a signer recipient to sign the document, identified by name and email
5961
// routingOrder (lower means earlier) determines the order of deliveries
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.docusign.controller.eSignature.services;
2+
3+
import com.docusign.DSConfiguration;
4+
import com.docusign.common.WorkArguments;
5+
import com.docusign.controller.eSignature.examples.EnvelopeHelpers;
6+
import com.docusign.esign.api.EnvelopesApi;
7+
import com.docusign.esign.client.ApiException;
8+
import com.docusign.esign.model.*;
9+
10+
import java.io.IOException;
11+
import java.util.Collections;
12+
13+
public final class ResponsiveSigningService {
14+
private static final String HTML_DOCUMENT_FILE_NAME = "templates/order-form.ftl";
15+
16+
public static EnvelopeDefinition makeEnvelope(
17+
String signerEmail,
18+
String signerName,
19+
String signerClientId,
20+
String ccEmail,
21+
String ccName,
22+
WorkArguments args
23+
) throws IOException {
24+
String htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args);
25+
htmlDoc = htmlDoc.replace("/sn1/", "<ds-signature data-ds-role=\"Signer\"/>")
26+
.replace("/l1q/", " <input data-ds-type=\"number\"/>")
27+
.replace("/l2q/", " <input data-ds-type=\"number\"/>");;
28+
29+
Signer signer = new Signer()
30+
.email(signerEmail)
31+
.name(signerName)
32+
.clientUserId(signerClientId)
33+
.recipientId("1")
34+
.routingOrder("1")
35+
.roleName("Signer");
36+
37+
CarbonCopy cc = new CarbonCopy()
38+
.email(ccEmail)
39+
.name(ccName)
40+
.recipientId("2")
41+
.routingOrder("1");
42+
43+
EnvelopeDefinition envelope = new EnvelopeDefinition();
44+
envelope.setEmailSubject("Example Signing Document");
45+
envelope.setDocuments(Collections.singletonList(
46+
new Document()
47+
.name("Lorem Ipsum")
48+
.documentId("1")
49+
.htmlDefinition(new DocumentHtmlDefinition().source(htmlDoc))));
50+
envelope.setRecipients(EnvelopeHelpers.createRecipients(signer, cc));
51+
envelope.setStatus(EnvelopeHelpers.ENVELOPE_STATUS_SENT);
52+
53+
return envelope;
54+
}
55+
56+
public static ViewUrl responsiveSigning(
57+
EnvelopesApi envelopesApi,
58+
String accountId,
59+
String envelopeId,
60+
RecipientViewRequest viewRequest
61+
) throws ApiException {
62+
return envelopesApi.createRecipientView(accountId, envelopeId, viewRequest);
63+
}
64+
65+
public static RecipientViewRequest makeRecipientViewRequest(
66+
String signerEmail,
67+
String signerName,
68+
DSConfiguration config,
69+
String clientUserId
70+
) {
71+
RecipientViewRequest viewRequest = new RecipientViewRequest();
72+
String stateValue = "?state=123";
73+
viewRequest.setReturnUrl(config.getDsReturnUrl() + stateValue);
74+
75+
String authenticationMethod = "none";
76+
viewRequest.setAuthenticationMethod(authenticationMethod);
77+
78+
viewRequest.setEmail(signerEmail);
79+
viewRequest.setUserName(signerName);
80+
viewRequest.setClientUserId(clientUserId);
81+
82+
String pingFrequency = "600";
83+
viewRequest.setPingFrequency(pingFrequency);
84+
viewRequest.setPingUrl(config.getDsPingUrl());
85+
86+
return viewRequest;
87+
}
88+
}

src/main/java/com/docusign/controller/eSignature/services/SendBinaryDocsService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public static String sendBinaryDocs(
5151
// Step 1. Gather documents and their headers
5252
List<DocumentInfo> documents = List.of(
5353
new DocumentInfo(HTML_DOCUMENT_NAME, "1", DocumentType.HTML,
54-
EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)),
54+
EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
55+
.getBytes(StandardCharsets.UTF_8)),
5556
new DocumentInfo(DOCX_DOCUMENT_NAME, "2", DocumentType.DOCX,
5657
EnvelopeHelpers.readFile(DOCX_DOCUMENT_FILE_NAME)),
5758
new DocumentInfo(PDF_DOCUMENT_NAME, "3", DocumentType.PDF,

src/main/java/com/docusign/controller/eSignature/services/SigningViaEmailService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.docusign.esign.model.*;
99

1010
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
1112
import java.util.Arrays;
1213

1314
public final class SigningViaEmailService {
@@ -74,7 +75,8 @@ public static EnvelopeDefinition makeEnvelope(
7475
cc.setRoutingOrder("2");
7576

7677
// The order in the docs array determines the order in the envelope
77-
byte[] htmlDocument = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args);
78+
byte[] htmlDocument = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
79+
.getBytes(StandardCharsets.UTF_8);
7880
EnvelopeDefinition envelope = new EnvelopeDefinition();
7981
envelope.setEmailSubject("Please sign this document set");
8082
envelope.setDocuments(Arrays.asList(
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2+
<jsp:include page="../../../partials/head.jsp"/>
3+
4+
<h4>38. Signable HTML document</h4>
5+
<p>This example demonstrates how to create an HTML document for responsive signing.</p>
6+
7+
<c:if test="${showDoc}">
8+
<p><a target='_blank' href='${documentation}'>Documentation</a> about this example.</p>
9+
</c:if>
10+
11+
<p>API method used:
12+
<a target ='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a> and
13+
<a target ='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopeviews/createrecipient/">EnvelopeViews::createRecipient</a>.
14+
</p>
15+
16+
<p>
17+
View source file <a target="_blank" href="${sourceUrl}">${sourceFile}</a> on GitHub.
18+
</p>
19+
20+
<form class="eg" action="" method="post" data-busy="form">
21+
<div class="form-group">
22+
<label for="signerEmail">Signer Email</label>
23+
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
24+
aria-describedby="emailHelp" placeholder="pat@example.com" required
25+
value="${locals.dsConfig.signerEmail}">
26+
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
27+
</div>
28+
<div class="form-group">
29+
<label for="signerName">Signer Name</label>
30+
<input type="text" class="form-control" id="signerName" placeholder="Pat Johnson" name="signerName"
31+
value="${locals.dsConfig.signerName}" required>
32+
</div>
33+
<div class="form-group">
34+
<label for="ccEmail">CC Email</label>
35+
<input type="email" class="form-control" id="ccEmail" name="ccEmail"
36+
aria-describedby="emailHelp" placeholder="pat@example.com" required>
37+
<small id="emailHelp" class="form-text text-muted">The email for the cc recipient must be different from the signer's email.</small>
38+
</div>
39+
<div class="form-group">
40+
<label for="ccName">CC Name</label>
41+
<input type="text" class="form-control" id="ccName" placeholder="Pat Johnson" name="ccName"
42+
required>
43+
</div>
44+
<input type="hidden" name="_csrf" value="${csrfToken}">
45+
<button type="submit" class="btn btn-docu">Submit</button>
46+
</form>
47+
48+
<jsp:include page="../../../partials/foot.jsp"/>

src/main/webapp/WEB-INF/templates/views/pages/esignature/index.jsp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,17 @@
343343
href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a>.
344344
</p>
345345

346+
<h2>Responsive signing</h2>
346347

348+
<h4 id="example038">38. <a href="eg038">Signable HTML document</a></h4>
349+
<p>
350+
Demonstrates how to create an HTML document for responsive signing.
351+
<p>
352+
API methods used:
353+
<a target="_blank" href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a>,
354+
<a target='_blank'
355+
href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopeviews/createrecipient/">EnvelopeViews::createRecipient</a>.
356+
</p>
347357
</div>
348358

349359

0 commit comments

Comments
 (0)