EchoSignEndpointServlet.java
6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.addon.signing.DocumentSigningService
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.servlet.Servlet
* javax.servlet.ServletOutputStream
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.request.RequestPathInfo
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.signing.echosign.servlet;
import com.adobe.aemds.guide.addon.signing.DocumentSigningService;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletOutputStream;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, immediate=1, label="AdobeSignEndpointServlet", description="AdobeSignEndpointServlet")
@Service(value={Servlet.class})
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/af/components/guideContainer"}), @Property(name="sling.servlet.methods", value={"GET"}), @Property(name="sling.servlet.selectors", value={"adobesign"})})
public class EchoSignEndpointServlet
extends SlingAllMethodsServlet {
private static final long serialVersionUID = 1936534819338551669L;
private final Logger log = LoggerFactory.getLogger(EchoSignEndpointServlet.class);
@Reference
private DocumentSigningService documentSigningService;
public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
throw new UnsupportedOperationException("Post is not supported for AnalyticsReportingServlet.");
}
public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
block10 : {
ResourceResolver requestResolver = request.getResourceResolver();
Session session = (Session)requestResolver.adaptTo(Session.class);
RequestPathInfo requestPathInfo = request.getRequestPathInfo();
try {
if (this.documentSigningService != null && session != null) {
String documentKeyNode = "echosigndocumentkey";
String cloudService = "/etc/cloudservices/echosign/" + requestPathInfo.getSuffix();
String receivedDocumentKey = request.getParameter("documentKey");
HashMap<String, String> configMap = new HashMap<String, String>();
configMap.put("CONFIG_PATH", cloudService);
try {
Node dataNode = null;
if (requestPathInfo.getSelectors().length == 2) {
String UUID2 = requestPathInfo.getSelectors()[1];
Resource tempResource = request.getResourceResolver().getResource("/tmp/fd/af//" + UUID2);
if (tempResource != null) {
Node uuidNode = (Node)tempResource.adaptTo(Node.class);
dataNode = uuidNode.hasNode(documentKeyNode) ? uuidNode.getNode(documentKeyNode) : uuidNode.addNode(documentKeyNode, "nt:unstructured");
} else {
response.sendError(500, "Failed to obtain the location access for storage.");
}
byte[] bytesData = this.documentSigningService.getSignedDocument(receivedDocumentKey, configMap);
if (bytesData != null) {
response.setContentType("application/pdf");
response.setContentLength(bytesData.length);
response.getOutputStream().write(bytesData);
dataNode.setProperty("documentKey", receivedDocumentKey);
session.save();
} else {
response.sendError(500, "Failed to download the signed pdf.");
}
break block10;
}
this.log.error("Invalid request not having proper selectors.");
}
catch (RepositoryException repoException) {
this.log.error("Repository exception while saving the document key", (Throwable)repoException);
}
break block10;
}
response.sendError(500, "Failed to get Adobe Sign service instance or session");
}
catch (IOException ioException) {
this.log.error("IO Exception while obtaining the signed PDF", (Throwable)ioException);
}
}
}
protected void bindDocumentSigningService(DocumentSigningService documentSigningService) {
this.documentSigningService = documentSigningService;
}
protected void unbindDocumentSigningService(DocumentSigningService documentSigningService) {
if (this.documentSigningService == documentSigningService) {
this.documentSigningService = null;
}
}
}