
br.com.esec.icpm.libs.signature.helper.RequestBatchSignatureHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of certillion-client-library Show documentation
Show all versions of certillion-client-library Show documentation
This library is used to make integration with Certillion server, so our Clients can easily ask for signatures or generate certificates.
package br.com.esec.icpm.libs.signature.helper;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.esec.icpm.libs.Server;
import br.com.esec.icpm.libs.signature.ApWsFactory;
import br.com.esec.icpm.libs.signature.BatchSignatureRequest.Document;
import br.com.esec.icpm.mss.rest.ApplicationProviderResource;
import br.com.esec.icpm.mss.ws.BatchSignatureComplexDocumentReqType;
import br.com.esec.icpm.mss.ws.BatchSignatureComplexDocumentRespType;
import br.com.esec.icpm.mss.ws.HashDocumentInfoType;
import br.com.esec.icpm.mss.ws.MessagingModeType;
import br.com.esec.icpm.mss.ws.SignaturePortType;
import br.com.esec.icpm.mss.ws.SignatureStandardType;
import br.com.esec.icpm.server.ws.CertificateFiltersType;
import br.com.esec.icpm.server.ws.ICPMException;
import br.com.esec.icpm.server.ws.MobileUserType;
import br.com.esec.icpm.server.ws.SignaturePolicyType;
// TODO: Pegar todas as ICPMException e encapsular em SignatureException mais legiveis e padronizadas.
public class RequestBatchSignatureHelper {
private static Logger log = LoggerFactory.getLogger(RequestBatchSignatureHelper.class);
public static BatchSignatureComplexDocumentRespType requestSynchBatchSignature(Server server, String identifier, String message, SignatureStandardType standard, SignaturePolicyType policyType,
boolean testMode, CertificateFiltersType certificateFilters, List documents, Long apId) throws ICPMException {
log.info("Requesting synch batch signature...");
SignaturePortType signaturePort = ApWsFactory.getInstance().getSoapService(server);
BatchSignatureComplexDocumentReqType request = prepareBachRequest(server, identifier, message, standard, policyType, testMode, certificateFilters, documents, MessagingModeType.SYNCH, apId);
BatchSignatureComplexDocumentRespType response = signaturePort.batchSignatureComplexDocument(request);
log.info("Signature requested with transaction id " + response.getTransactionId() + ".");
return response;
}
public static BatchSignatureComplexDocumentRespType requestAsynchBatchSignature(Server server, String identifier, String message, SignatureStandardType standard, SignaturePolicyType policyType,
boolean testMode, CertificateFiltersType certificateFilters, List documents, Long apId) throws ICPMException {
log.info("Requesting asynch batch signature...");
SignaturePortType signaturePort = ApWsFactory.getInstance().getSoapService(server);
BatchSignatureComplexDocumentReqType request = prepareBachRequest(server, identifier, message, standard, policyType, testMode, certificateFilters, documents, MessagingModeType.ASYNCH_CLIENT_SERVER, apId);
BatchSignatureComplexDocumentRespType response = signaturePort.batchSignatureComplexDocument(request);
log.info("Signature requested with transaction id " + response.getTransactionId() + ".");
return response;
}
public static BatchSignatureComplexDocumentRespType requestAsynchWithNotifyBatchSignature(Server server, String identifier, String message, SignatureStandardType standard, SignaturePolicyType policyType,
boolean testMode, CertificateFiltersType certificateFilters, List documents, Long apId) throws ICPMException {
log.info("Requesting asynch with notify batch signature...");
SignaturePortType signaturePort = ApWsFactory.getInstance().getSoapService(server);
BatchSignatureComplexDocumentReqType request = prepareBachRequest(server, identifier, message, standard, policyType, testMode, certificateFilters, documents, MessagingModeType.ASYNCH_SERVER_SERVER, apId);
BatchSignatureComplexDocumentRespType response = signaturePort.batchSignatureComplexDocument(request);
log.info("Signature requested with transaction id " + response.getTransactionId() + ".");
return response;
}
private static BatchSignatureComplexDocumentReqType prepareBachRequest(Server server, String identifier, String message, SignatureStandardType standard, SignaturePolicyType policyType,
boolean testMode, CertificateFiltersType certificateFilters, List documents, final MessagingModeType messagingMode, Long apId) {
// Set the mobileUser
MobileUserType mobileUser = new MobileUserType();
mobileUser.setUniqueIdentifier(identifier);
// Create the batch request
BatchSignatureComplexDocumentReqType request = new BatchSignatureComplexDocumentReqType();
request.setMobileUser(mobileUser);
request.setMessagingMode(messagingMode);
request.setDataToBeDisplayed(message);
request.setSignatureStandard(standard);
request.setSignaturePolicy(policyType);
request.setTestMode(testMode);
request.setCertificateFilters(certificateFilters);
// Set the request document
List documentInfos = handleDocuments(server, documents);
request.setDocumentsToBeSigned(documentInfos);
return request;
}
private static List handleDocuments(Server server, List documents) {
// upload files from each url
List documentInfos = new ArrayList();
for (Document document : documents) {
log.info("Uploading document '" + document.getName() + "'...");
final String hash = upload(server, document.getIn());
log.info("Document '" + document.getName() + "' uploaded.");
documentInfos.add(getDocumentInfo(hash, document.getName(), document.getMimeType()));
}
return documentInfos;
}
private static HashDocumentInfoType getDocumentInfo(final String hash, final String name, final String mimeType) {
// Get hash from uploaded file, create document and save the document in the list
HashDocumentInfoType document = new HashDocumentInfoType();
document.setDocumentName(name);
document.setHash(hash);
document.setContentType(mimeType);
return document;
}
private static String upload(Server server, InputStream in) {
try {
ApplicationProviderResource restService = ApWsFactory.getInstance().getRestService(server);
return restService.uploadDocument(in);
} finally {
IOUtils.closeQuietly(in);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy