2014-07-10 3 views
0

DocuSign 용 Java에서 REST API를 사용하고 있습니다. API 연습과 같은 템플릿 대신 서명 (궁극적으로 내 페이지의 iframe에 삽입)을 문서와 함께 삽입하려고합니다. 여기를 살펴보면 embeddedSigning 및 requestSigning API 연습의 코드를 병합하여 수행 할 수 있음을 알았지 만 그렇게하기가 힘들었습니다. 이제는 내가 가까이에 있다고 생각하지만, 그게 무슨 말인지 알지 못하는 오류에 집착했습니다. (411) [치명적인 오류] : 1 : 50 :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 호출이 실패 상태가 반환 화이트 공간이 publicId와 systemId 사이에 필요합니다.

저는이 모든 것을 처음 접했기 때문에 문서로 서명을 삽입하는 방법에 대한 도움을 주시면 대단히 감사하겠습니다. 오류 : 'publicId와 systemId 사이에 공백이 필요합니다.'

+0

나는 그 오류를 본 적이 없으며, 전달되는 내용 (추적)과 완전한 오류를 게시 할 수 있습니까? DocuSign에서 오는 것처럼 들리지 않습니다. – Andrew

답변

1

RFC 2616 표준 HTTP 오류 411에 따르면 Content-Length 헤더가 없음을 나타냅니다. 요청에 Content-Length 헤더를 추가하고 구성중인 요청 본문의 크기로 설정하십시오.

+0

정말 고마워요! 이것은 문제의 큰 부분이었고, embeddedSigning.java와 requestSigning.java가 다른 것을 요구하는 InitializeRequest()의 더 큰 문제를 해결하게되었습니다. – Laka