Acrobat Sign REST API용 래퍼 만들기
사용자 지정 AEM 번들은 웹 양식을 작성하여 최종 사용자에게 반환하기 위해 개발되었습니다
- 임시 문서 만들기. 이 호출을 통해 업로드된 문서는 업로드 후 7일 동안만 사용할 수 있으므로 임시 문서라고 합니다. 반환된 임시 문서 ID는 업로드된 파일을 참조해야 하는 API 호출에서 사용할 수 있습니다. 임시 문서 요청은 파일 이름, MIME 유형 및 파일 스트림의 세 부분으로 구성된 다중 부분 요청입니다. 이 요청에서는 한 번에 하나의 파일만 업로드할 수 있습니다.
- 웹 양식 만들기.새 웹 양식을 만드는 데 사용되는 기본 끝점입니다. 웹 양식을 즉시 호스팅하기 위해 활성 상태로 웹 양식을 만들었습니다.
- 웹 양식 검색.사용자의 웹 양식을 검색합니다. 그런 다음 이 웹 양식이 문서 서명을 위해 호출 애플리케이션에 표시됩니다.
Acrobat Sign OSGi 구성 만들기
Acrobat Sign REST API에는 통합 키 및 통합 키와 연결된 이메일이 필요합니다. 이 두 값은 아래와 같이 OSGi 구성 속성으로 제공됩니다
package com.acrobatsign.core.configuration;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(name="Acrobat Sign Configuration", description = "Acrobat SignConfiguration")
public @interface AcrobatSignConfiguration
{
@AttributeDefinition(name="Acrobat Sign Integration Key", description = "Integration key you created in Acrobat Sign ")
String getIntegrationKey();
@AttributeDefinition(name="X-API-USER", description = "X-API-USER")
String getApiUser();
}
package com.acrobatsign.core.configuration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.Designate;
@Component(immediate = true, service = AcrobatSignConfigurationService.class)
@Designate(ocd = AcrobatSignConfiguration.class)
public class AcrobatSignConfigurationService {
private String IntegrationKey;
private String apiUserEmail;
public String getIntegrationKey() {
return IntegrationKey;
}
public String getApiUserEmail() {
return apiUserEmail;
}
@Activate
protected final void activate(AcrobatSignConfiguration config) {
IntegrationKey = config.getIntegrationKey();
apiUserEmail = config.getApiUser();
}
}
임시 문서 ID 가져오기
다음 코드는 임시 문서를 만들기 위해 작성되었습니다.
public String getTransientDocumentID(Document documentForSigning) throws IOException {
String integrationKey = acrobatSignConfig.getIntegrationKey();
String apiUser = acrobatSignConfig.getApiUserEmail();
String url = "https://api.na1.adobesign.com/api/rest/v6/transientDocuments";
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("x-api-user", "email:" + apiUser);
httpPost.addHeader("Authorization", "Bearer " + integrationKey);
builder.addBinaryBody("File", documentForSigning.getInputStream(), ContentType.DEFAULT_BINARY, "NDA.PDF");
builder.addTextBody("File-Name", "NDA.pdf");
HttpEntity entity = builder.build();
log.debug("Build the entity");
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
log.debug("Sent the request!!!!");
log.debug("REsponse code " + response.getStatusLine().getStatusCode());
HttpEntity httpEntity = response.getEntity();
String transientDocumentId = JsonParser.parseString(EntityUtils.toString(httpEntity)).getAsJsonObject().get("transientDocumentId").getAsString();
log.debug("Transient ID " + transientDocumentId);
return transientDocumentId;
}
위젯 ID 가져오기
public String getWidgetID(String transientDocumentID) {
String integrationKey = acrobatSignConfig.getIntegrationKey();
String apiUser = acrobatSignConfig.getApiUserEmail();
String url = "https://api.na1.adobesign.com:443/api/rest/v6/widgets";
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("x-api-user", "email:" + apiUser);
httpPost.addHeader("Authorization", "Bearer " + integrationKey);
String jsonREquest = "{\r\n" +
" \"fileInfos\": [\r\n" +
" {\r\n" +
" \"transientDocumentId\": \"a\"\r\n" +
" }\r\n" +
" ],\r\n" +
" \"name\": \"Release and Waiver Agreement\",\r\n" +
" \"state\": \"ACTIVE\",\r\n" +
" \"widgetParticipantSetInfo\": {\r\n" +
" \"memberInfos\": [\r\n" +
" {\r\n" +
" \"email\": \"\"\r\n" +
" }\r\n" +
" ],\r\n" +
" \"role\": \"SIGNER\"\r\n" +
" }\r\n" +
"}";
JsonObject jsonReq = JsonParser.parseString(jsonREquest).getAsJsonObject();
jsonReq.getAsJsonArray("fileInfos").get(0).getAsJsonObject().addProperty("transientDocumentId", transientDocumentID);
log.debug("The updated json object is " + jsonReq);
try {
StringEntity stringEntity = new StringEntity(jsonReq.toString());
httpPost.setEntity(stringEntity);
httpPost.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpClient.execute(httpPost);
log.debug("The response is " + response.getStatusLine().getStatusCode());
String widgetID = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject().get("id").getAsString();
log.debug("The widget id is " + widgetID);
return widgetID;
} catch (Exception e) {
log.debug("Error in getting Widget ID:" + e.getMessage());
}
return null;
}
위젯 URL 가져오기
public String getWidgetURL(String widgetId) throws ClientProtocolException, IOException {
log.debug("$$$$ in get Widget URL for "+widgetId+ "widget id");
String url = "https://api.na1.adobesign.com:443/api/rest/v6/widgets";
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("x-api-user", "email:"+acrobatSignConfig.getApiUserEmail());
httpGet.addHeader("Authorization", "Bearer "+acrobatSignConfig.getIntegrationKey());
CloseableHttpResponse response = httpClient.execute(httpGet);
JsonObject jsonResponse = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject();
log.debug("The json response from get widgets is "+jsonResponse.toString());
JsonArray userWidgetList = jsonResponse.get("userWidgetList").getAsJsonArray();
log.debug("The array size is "+userWidgetList.size());
for(int i=0;i<userWidgetList.size();i++)
{
log.debug("Getting widget object "+i);
JsonObject temp = userWidgetList.get(i).getAsJsonObject();
log.debug("The widget object "+i+"is "+temp.toString());
if(temp.get("id").getAsString().equalsIgnoreCase(widgetId))
{
log.debug("Bingo found the matching widget id "+i);
String widgetURL = temp.get("url").getAsString();
return widgetURL;
}
}
return null;
}
다음 단계
recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e