2014-07-10 72 views
0

我在Java中爲DocuSign使用REST API。我試圖用文檔嵌入簽名(最終到我的頁面中的iframe),而不是像API演練中的模板。仔細看看這裏,我發現這可以通過合併來自embeddedSigning和requestSigning API演練的代碼來完成,但我很難做到這一點。現在我認爲我很接近,但卻陷入了一個錯誤,我不知道它在說什麼。用Docusign中的文檔進行嵌入式簽名

//============================================================================ 
    //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之間需要空格。'

+0

我從來沒有見過這個錯誤,你能發表什麼傳遞(一個跟蹤)和一個完整的錯誤。聽起來不像是來自DocuSign – Andrew

回答

1

根據RFC 2616標準HTTP錯誤411表示缺少Content-Length標頭。嘗試將Content-Length標頭添加到請求中,並將其設置爲您正在構建的請求正文的大小。

+0

非常感謝!這是導致我爲解決嵌入式簽名.java和requestSigning.java需要不同的更大問題InitializeRequest()的問題的重要組成部分。 – Laka

相關問題