Java 如何在IBMLotusNotes中运行CoSignatureSOAPAPI?

Java 如何在IBMLotusNotes中运行CoSignatureSOAPAPI?,java,soap,digital-signature,cosign-api,Java,Soap,Digital Signature,Cosign Api,使用代码。我已经编写了与java 1.6兼容的代码,我收到了错误“AccessControlException:Access denied”,我是否遗漏了什么?我在代码中发现的唯一问题是读取/写入文件字节的方式。除此之外,你的代码对我来说运行得非常好 以下是我所做的更改: 将文件转换为字节(Java 1.6) 向文件追加字节(Java 1.6) 请注意,API的用户名是您的电子邮件,而不是用于开发人员门户的用户名 服务点url显示在 您好,我也尝试过同样的方法,但它仍然向我抛出同样的错误“Acc

使用代码。我已经编写了与java 1.6兼容的代码,我收到了错误“AccessControlException:Access denied”,我是否遗漏了什么?

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

以下是我所做的更改:

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

向文件追加字节(Java 1.6)


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

服务点url显示在


您好,我也尝试过同样的方法,但它仍然向我抛出同样的错误“AccessControlException:拒绝访问”。我正在使用免费30天试用帐户,这是问题吗?我再次提到url“”重定向到“arx.com”,这样可以吗?总的来说,有没有我缺少的配置更改或设置?您提到的url只是一个XML名称空间,这很好。检查堆栈跟踪以查看哪个方法引发了此异常。可能是因为您没有权限访问其部署目录之外的文件?检查这个-非常感谢您的帮助,代码现在运行良好。我想对现有的代码做一些修改,你能看看我的新问题吗?请记住对所有有用的答案进行投票。并“检查”最能解决您问题的答案。
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());

}
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();
}
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.");
}