【问题标题】:How to run CoSign Signature SOAP API in IBM Lotus Notes?如何在 IBM Lotus Notes 中运行 CoSign Signature SOAP API?
【发布时间】:2014-08-09 13:51:26
【问题描述】:
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: Access denied”,我错过了什么吗?

【问题讨论】:

  • 请记住为所有有用的答案投票。并“检查”最能解决您问题的答案。

标签: java soap digital-signature cosign-api


【解决方案1】:

请注意,您的 API 用户名是您的电子邮件,而不是您用于开发者门户的用户名。

服务点网址显示在getting started tab of the api overview

Service point url for the trial/developer system

【讨论】:

【解决方案2】:

我在您的代码中发现的唯一问题是您读取/写入文件字节的方式。除此之外,您的代码对我来说运行完美。

这些是我所做的更改:

将文件转换为字节 (Java 1.6)

File file = new File(filePath);
byte[] fileBuffer = new byte[(int) file.length()];
try {
    FileInputStream fileInputStream = new FileInputStream(file);
    fileInputStream.read(fileBuffer);
    fileInputStream.close();
} catch (FileNotFoundException e) {
    System.out.println("File Not Found.");
    e.printStackTrace();
}
catch (IOException e1) {
    System.out.println("Error Reading The File.");
    e1.printStackTrace();
}

将字节附加到文件 (Java 1.6)

try {
    FileOutputStream fileOutputStream = new FileOutputStream(filePath, true);
    fileOutputStream.write(signatureObjectBuffer);
    fileOutputStream.close();
}
    catch(FileNotFoundException ex)   {
    System.out.println("File Not Found.");
}
    catch(IOException ioe)  {
    System.out.println("Error Reading The File.");
}

【讨论】:

  • 嗨,我也试过了,但它仍然给我同样的错误“AccessControlException:访问被拒绝”。我正在使用免费的 30 天试用帐户,这是问题吗?我再一次提到 url "arx.com/SAPIWS/DSS/1.0" 重定向到 "arx.com",这样可以吗?和整体我是否缺少任何配置更改或设置?
  • 您提到的url只是一个XML命名空间,这很好。检查堆栈跟踪以查看哪个方法引发了此异常。也许是因为您无权访问其部署目录之外的文件?检查这个 - stackoverflow.com/questions/10454037
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多