Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Docusign中嵌入文档签名_Java_Docusignapi - Fatal编程技术网

Java 在Docusign中嵌入文档签名

Java 在Docusign中嵌入文档签名,java,docusignapi,Java,Docusignapi,我正在使用Java中的RESTAPI进行DocuSign。我试图用一个文档而不是像API演练中那样的模板来嵌入签名(最终嵌入到我页面中的iframe中)。在这里,我了解到这可以通过合并embeddedSigning和requestSigning API演练中的代码来实现,但我很难做到这一点。现在我想我已经很接近了,但是陷入了一个错误,我不知道它在说什么 //==================================================================

我正在使用Java中的RESTAPI进行DocuSign。我试图用一个文档而不是像API演练中那样的模板来嵌入签名(最终嵌入到我页面中的iframe中)。在这里,我了解到这可以通过合并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);
//============================================================================
//步骤2-文档API调用的签名请求
//============================================================================
url=baseURL+“/信封”;//将“/信封”附加到baseUrl以进行签名请求调用
//本例使用XML格式的请求,也接受JSON格式
//下面的正文将在文档左上角的右侧和下方分别放置一个100像素和100像素的签名选项卡
body=“”+
“已发送”+
“用于将签名请求添加到文档并发送的API调用”+
//添加文档
"" +
"" +
"1" +
“”+documentName+“”+
"" +
"" +
//添加收件人
"" +
"" +
"" +
"1" +
“”+recipientName+“”+
“”+收件人电子邮件+“”+
"1001" +
"" +
"" +
"" +
"100" +
"100" +
"1" +
"1" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
//为第二个请求重新使用连接对象。。。
conn=初始化请求(url,“POST”、正文、authenticationHeader);
//将文档内容读入字节数组
文件文件=新文件(“./”+文件名);
InputStream InputStream=新文件InputStream(文件);
byte[]bytes=新字节[(int)file.length()];
inputStream.read(字节);
inputStream.close();
//开始构造多部分/表单数据请求。。。
String requestBody=“\r\n\r\n--BOUNDARY\r\n”+
“内容类型:应用程序/xml\r\n”+
“内容处置:表单数据\r\n”+
“\r\n”+
body+“\r\n\r\n--BOUNDARY\r\n”+//我们的xml格式的请求正文
“内容类型:”+docContentType+“\r\n”+
“内容处置:文件;文件名=\”“+documentName+”\“documentid=1\r\n”+
“\r\n”;
//我们将其分为两个字符串,因为PDF文档字节位于此处,并且不是字符串格式。
//请参阅下面我们写入outputstream的地方。。。
字符串reqBody2=“\r\n”+“--边界--\r\n\r\n”;
//写下请求的正文。。。
DataOutputStream dos=新的DataOutputStream(conn.getOutputStream());
writeBytes(requestBody.toString());
写入(字节);
dos.writeBytes(reqBody2.toString());
dos.flush();dos.close();
System.out.println(“步骤2:从文档创建信封…\n”);
状态=连接getResponseCode();//触发请求
如果(状态!=201)//201=已创建
{
错误解析(连接,状态);
返回;
}
//从响应体获取信封uri
响应=GetResponseBy(连接);
字符串uri=parseXMLBody(响应,“uri”);
System.out.println(“--信封创建响应--\n\n”+prettyFormat(响应,2));
//============================================================================
//步骤3-获取嵌入式签名视图
//============================================================================
url=baseURL+uri+“/views/recipient”;//将信封uri+“视图/收件人”附加到url
//本例使用XML格式的请求,也接受JSON格式
body=“”+
“电子邮件”+
“”+收件人电子邮件+“”+
"http://www.docusign.com/devcenter" +
“1001”+/***必须与步骤2中设置的clientUserId匹配!
“”+recipientName+“”+
"";
System.out.print(“步骤3:为嵌入式签名生成URL令牌…”);
conn=初始化请求(url,“POST”、正文、authenticationHeader);
状态=连接getResponseCode();//触发请求
如果(状态!=201)//201=已创建
{
错误解析(连接,状态);
返回;
}
System.out.println(“完成”);
响应=GetResponseBy(连接);
字符串urlToken=parseXMLBody(响应,“url”);
System.out.println(“\n创建的嵌入签名令牌:\n\t”+urlToken);
我得到了这个错误:

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

我对这一切都是新手,因此,如果能帮助我准确地嵌入文件签名,我将不胜感激。 错误:“publicId和systemId之间需要空格。”

根据标准HTTP ERROR
411
表示缺少
内容长度的头。尝试将
内容长度
标题添加到请求中,并将其设置为您正在构建的请求正文的大小。

我从未见过这种情况