如何在IBM Lotus Notes中运行CoSign签名SOAP API? [英] How to run CoSign Signature SOAP API in IBM Lotus Notes?

查看:105
本文介绍了如何在IBM Lotus Notes中运行CoSign签名SOAP API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// Custom Values
String filePath      = "C://20/ToSign.pdf";  // Pdf File to sign
String fileMimeType  = "application/pdf";   // File MIME type
String username      = "xyz@gmail.com";       // CoSign account username,Not exactly these credentials, I have entered my CoSign username and password here.
String password      = "password";          // CoSign account password
String domain        = "";                  // CoSign account domain
int sigPageNum       = 1;                   // Create signature on the first page
int sigX             = 145;                 // Signature field X location
int sigY             = 125;                 // Signature field Y location
int sigWidth         = 160;                 // Signature field width
int sigHeight        = 45;                  // Signature field height
String timeFormat    = "hh:mm:ss";          // The display format of the time
String dateFormat    = "dd/MM/yyyy";        // The display format of the date
long appearanceMask  = 11; 
String signatureType = "http://arx.com/SAPIWS/DSS/1.0/signature-field-create-sign"; // The actual operation of the Sign Request function
String wsdlUrl       = "https://prime.cosigntrial.com:8080/sapiws/dss.asmx?WSDL";   // URL to the WSDL file

// Read file contents

BufferedReader br = new BufferedReader(new FileReader(new File(filePath)));
String line;
String fileBufferContent="";
while ((line=br.readLine())!=null){
      fileBufferContent=fileBufferContent+line ;

}

byte[] fileBuffer = fileBufferContent.getBytes();

// Set file contents + MIME type (the SOAP library automatically base64 encodes the data)
DocumentType document = new DocumentType();
Base64Data base64Data = new Base64Data();
base64Data.setValue(fileBuffer);
base64Data.setMimeType(fileMimeType);
document.setBase64Data(base64Data);

// Set user credentials. In case of Active Directory, the domain name should be defined in the NameQualifier attribute
ClaimedIdentity claimedIdentity = new ClaimedIdentity();
NameIdentifierType nameIdentifier = new NameIdentifierType();
nameIdentifier.setValue(username);
nameIdentifier.setNameQualifier(domain);
CoSignAuthDataType coSignAuthData = new CoSignAuthDataType();
coSignAuthData.setLogonPassword(password);
claimedIdentity.setName(nameIdentifier);
claimedIdentity.setSupportingInfo(coSignAuthData);

System.out.println("credentials set");
// Define signature field settings
SAPISigFieldSettingsType sigFieldSettings = new SAPISigFieldSettingsType();
sigFieldSettings.setInvisible(false);
sigFieldSettings.setX(sigX);
sigFieldSettings.setY(sigY);
sigFieldSettings.setWidth(sigWidth);
sigFieldSettings.setHeight(sigHeight);
sigFieldSettings.setPage(sigPageNum);
sigFieldSettings.setAppearanceMask(appearanceMask);
TimeDateFormatType timeDateFormat = new TimeDateFormatType();
timeDateFormat.setTimeFormat(timeFormat);
timeDateFormat.setDateFormat(dateFormat);
timeDateFormat.setExtTimeFormat(ExtendedTimeFormatEnum.GMT);
sigFieldSettings.setTimeFormat(timeDateFormat);
// Build complete request object
SignRequest signRequest = new SignRequest();
RequestBaseType.InputDocuments inputDocuments = new RequestBaseType.InputDocuments();
inputDocuments.getDocumentOrTransformedDataOrDocumentHash().add(document);
RequestBaseType.OptionalInputs optionalInputs = new RequestBaseType.OptionalInputs();
optionalInputs.setSignatureType(signatureType);
optionalInputs.setClaimedIdentity(claimedIdentity);
optionalInputs.setSAPISigFieldSettings(sigFieldSettings);
optionalInputs.setReturnPDFTailOnly(true);
signRequest.setOptionalInputs(optionalInputs);
signRequest.setInputDocuments(inputDocuments);
// Initiate service client //
DSS client = new DSS(new URL(wsdlUrl), new QName("http://arx.com/SAPIWS/DSS/1.0/", "DSS"));

// Send the request
DssSignResult response = client.getDSSSoap().dssSign(signRequest);

// Check response output
if ("urn:oasis:names:tc:dss:1.0:resultmajor:Success".equals(response.getResult().getResultMajor())) {
    // On success- append signature object to the source PDF document (the SOAP library automatically decodes the base64 encoded output)
    byte[] signatureObjectBuffer = response.getSignatureObject().getBase64Signature().getValue();
    //Files.write(Paths.get(filePath), signatureObjectBuffer, StandardOpenOption.APPEND);

    BufferedWriter bw = new BufferedWriter(new FileWriter( new File(filePath)));

    String signatureObjectBufferString = signatureObjectBuffer.toString();
    bw.write(signatureObjectBufferString);
    bw.close();
}
else
{ 
    // On failure- raise exception with the result error message
    throw new Exception(response.getResult().getResultMessage().getValue());

}

使用代码 http://developer.arx.com/quick-start/sapi-web-services/#t- helloworld 。我编写了与Java 1.6兼容的代码,出现错误 AccessControlException:访问被拒绝,我丢失了什么吗?

using the code http://developer.arx.com/quick-start/sapi-web-services/#t-helloworld .I have written code compatible to java 1.6, I am getting errors "AccessControlException: Access denied", Am I missing something?

推荐答案

请注意,您用于API的用户名是您的电子邮件,而不是用于Developers Portal的用户名。

Note that your username for the APIs is your email, not the username you use for the Developers Portal.

服务点网址显示在 api概述的入门标签

试用/开发人员系统的服务点网址

这篇关于如何在IBM Lotus Notes中运行CoSign签名SOAP API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆