建立Acrobat Sign網路表單URL
下列程式碼是用來公開POST端點。 此端點會從提交的資料中擷取icTemplateName,並傳回Acrobat Sign網路表單URL以供一般使用者簽署。
package com.acrobatsign.core.servlets;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import javax.servlet.Servlet;
import org.apache.commons.io.IOUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import com.acrobatsign.core.PrintChannelDocumentHelperMethods;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@Component(service = {
Servlet.class
}, property = {
"sling.servlet.methods=post",
"sling.servlet.paths=/bin/getwidgeturl"
})
public class GetWidgetUrl extends SlingAllMethodsServlet {
private static final long serialVersionUID = 1 L;
private static final Logger log = org.slf4j.LoggerFactory.getLogger(GetWidgetUrl.class);
@Reference
PrintChannelDocumentHelperMethods printChannelDocument;
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
String jsonString;
try {
jsonString = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8.name());
log.debug("####Form Data is " + jsonString);
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
log.debug("The json object is " + jsonObject.toString());
String icTemplate = jsonObject.get("icTemplate").getAsString();
log.debug("The icTemplate is " + icTemplate);
//InputStream targetStream = IOUtils.toInputStream(jsonObject.toString());
InputStream targetStream = new ByteArrayInputStream(jsonString.getBytes());
String widgetURL = printChannelDocument.getPrintChannelDocument(icTemplate, targetStream);
log.debug("The widget url is " + widgetURL);
JsonObject jsonResponse = new JsonObject();
jsonResponse.addProperty("widgetURL", widgetURL);
PrintWriter out = response.getWriter();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
out.println(jsonResponse.toString());
out.flush();
} catch (Exception e) {
log.error("Error while getting the widget URL, details are :" + e.getMessage());
}
}
}
8de24117-1378-413c-a581-01e660b7163e