【问题标题】:Embedded signing with documents in Docusign在 Docusign 中使用文档进行嵌入式签名
【发布时间】:2014-07-11 15:00:08
【问题描述】:

我正在为 DocuSign 使用 Java 中的 REST API。我正在尝试使用文档嵌入签名(最终嵌入到我页面中的 iframe 中),而不是像 API 演练中的模板。浏览这里,我读到这可以通过合并来自 EmbeddedSigning 和 requestSigning API 演练的代码来完成,但我很难做到这一点。现在我想我已经接近了,但遇到了一个我不知道它在说什么的错误。

    //============================================================================
    //STEP 2 - Signature Request on Document API Call
    //============================================================================
    url = baseURL + "/envelopes";   // append "/envelopes" to baseUrl for signature request call
    //this example uses XML formatted requests, JSON format is also accepted
    //following body will place one signature tab 100 pixels right and 100 down from top left corner of document
    body = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
        "<status>sent</status>" +
        "<emailSubject>API Call for adding signature request to document and sending</emailSubject>" +
        //add document(s)
        "<documents>" +
            "<document>" +
                "<documentId>1</documentId>" +
                "<name>" + documentName + "</name>" +
            "</document>" +
        "</documents>" +
        //add recipient(s)
        "<recipients>" +
            "<signers>" +
                "<signer>" +
                    "<recipientId>1</recipientId>" +
                    "<name>" + recipientName + "</name>" +
                    "<email>" + recipientEmail + "</email>" +   
                    "<clientUserId>1001</clientUserId>" +
                    "<tabs>" +
                        "<signHereTabs>" +
                            "<signHere>" +
                                "<xPosition>100</xPosition>" +
                                "<yPosition>100</yPosition>" +
                                "<documentId>1</documentId>" +
                                "<pageNumber>1</pageNumber>" +
                            "</signHere>" +
                        "</signHereTabs>" +
                    "</tabs>" +
                "</signer>" +
            "</signers>" +
        "</recipients>" +
        "</envelopeDefinition>";
    // re-use connection object for second request...
            conn = InitializeRequest(url, "POST", body, authenticationHeader);

            // read document content into byte array
            File file = new File("./" + documentName);
            InputStream inputStream = new FileInputStream(file); 
            byte[] bytes = new byte[(int) file.length()];
            inputStream.read(bytes);
            inputStream.close();

            // start constructing the multipart/form-data request...
            String requestBody = "\r\n\r\n--BOUNDARY\r\n" + 
                    "Content-Type: application/xml\r\n" + 
                    "Content-Disposition: form-data\r\n" + 
                    "\r\n" + 
                    body + "\r\n\r\n--BOUNDARY\r\n" +   // our xml formatted request body
                    "Content-Type: " + docContentType + "\r\n" + 
                    "Content-Disposition: file; filename=\"" + documentName + "\"; documentid=1\r\n" + 
                    "\r\n";
                // we break this up into two string since the PDF doc bytes go here and are not in string format.
                // see further below where we write to the outputstream...
            String reqBody2 = "\r\n" + "--BOUNDARY--\r\n\r\n";

            // write the body of the request...
            DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
            dos.writeBytes(requestBody.toString()); 
            dos.write(bytes);
            dos.writeBytes(reqBody2.toString()); 
            dos.flush(); dos.close();

            System.out.println("STEP 2: Creating envelope from document...\n");

            status = conn.getResponseCode(); // triggers the request
            if( status != 201 ) // 201 = Created
            {
                errorParse(conn, status);
                return;
            }

            // obtain envelope uri from response body 
            response = getResponseBody(conn);
            String uri = parseXMLBody(response, "uri");
            System.out.println("-- Envelope Creation response --\n\n" + prettyFormat(response, 2));
    //============================================================================
            //STEP 3 - Get the Embedded Signing View
            //============================================================================
            url = baseURL + uri + "/views/recipient";   // append envelope uri + "views/recipient" to url
            //this example uses XML formatted requests, JSON format is also accepted
            body = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
                "<authenticationMethod>email</authenticationMethod>" +
                "<email>" + recipientEmail + "</email>" +
                "<returnUrl>http://www.docusign.com/devcenter</returnUrl>" +
                "<clientUserId>1001</clientUserId>" +   //*** must match clientUserId set in Step 2!
                "<userName>" + recipientName + "</userName>" +
            "</recipientViewRequest>";
            System.out.print("Step 3: Generating URL token for embedded signing... ");
            conn = InitializeRequest(url, "POST", body, authenticationHeader);
            status = conn.getResponseCode(); // triggers the request
            if( status != 201 ) // 201 = Created
            {
                errorParse(conn, status);
                return;
            }
            System.out.println("done.");

            response = getResponseBody(conn);
            String urlToken = parseXMLBody(response, "url");
            System.out.println("\nEmbedded signing token created:\n\t" + urlToken);

我得到这个错误:

第 3 步:为嵌入式签名生成 URL 令牌... API 调用失败,返回状态为:411[致命错误]:1:50:publicId 和 systemId 之间需要空格。

我对这一切都很陌生,因此对于我应该如何将签名嵌入文档的任何帮助将不胜感激。 错误:'publicId 和 systemId 之间需要空格。'

【问题讨论】:

  • 我从未见过那个错误,你能发布正在传递的内容(跟踪)和一个完整的错误。听起来不像是来自 DocuSign

标签: java docusignapi


【解决方案1】:

根据RFC 2616 标准HTTP 错误411 表示缺少Content-Length 标头。尝试将 Content-Length 标头添加到请求中,并将其设置为您正在构建的请求正文的大小。

【讨论】:

  • 非常感谢!这是导致我解决嵌入式Signing.java 的InitializeRequest() 和requestSigning.java 需要不同的更大问题的问题的重要部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 1970-01-01
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多