Docusign Rest with UTF-8 Characters

血红的双手。 提交于 2021-01-28 12:20:10

问题


I am trying to upload the Document using the Docusign Rest API, I have spanish characters in the body of the email and they are not displayed properly when Recipient gets the email. Listed below is the java code where I set the encoding to be UTF-8 and also I have pasted the Request Body before it hits the docusign server and also what the server is seeing

Java Code

public HttpURLConnection initializeRequest(String url, String method,
            String body, String httpAuthHeader) {
        try {

            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
                    "web.prod.proxy.company.com", 4200));
            conn = (HttpURLConnection) new URL(url).openConnection(proxy);
            conn.setRequestMethod(method);
            conn.setRequestProperty("X-DocuSign-Authentication", httpAuthHeader);
            conn.setRequestProperty("Accept", "application/json");
            conn.setRequestProperty("Accept-Charset", "UTF-8");
            if (method.equalsIgnoreCase("POST")) {
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data; boundary=BOUNDARY");
                conn.setDoOutput(true);
            } else {
                conn.setRequestProperty("Content-Type", "application/json");
            }
            return conn;
        } catch (Exception e) {
            throw new RuntimeException(e); // simple exception handling, please
                                            // review it
        }
    }

Request Body at local Box

  {
      "emailSubject" : "IRT16,17,18,19,20 MCI as of 11/10/2015",
      "emailBlurb" : "Buenos días/Tardes, \r\n\r\nAdjunto la documentación de la(s) transacción(es) con fecha de ejecución [Trade Date].  Rogamos que, en prueba de conformidad con los términos de la operación contenidos en esta Confirmación, nos devuelvan la copia adjunta debidamente firmada dentro de los siguientes dos días hábiles a partir de la fecha de ejecución. \r\n\r\nComo resultado de dicha(s) liquidación(es), [Cargill/Counterparty Name] deberá hacer un pago de US $XXX,XXX.XX el día [Payment date],  Adjunto la factura correspondiente. Por favor confirmar como quieren que se maneje este saldo.\r\n\r\nCualquier inquietud al respecto por favor comunicarse conmigo.\r\n\r\nUn cordial saludo,\r\n\r\n\r\nAttached is your intercompany statement as of 10-30-2015 with Cargill Risk Management.\r\n\r\nPlease confirm by filling out below template with your amounts and accounts and then replying to all. \r\n\r\n                              Please enter your amount:   Please enter your G/L account:\r\n\r\nPosition Market Value:                              \r\n\r\nPayable/Receivable:                                 \r\n\r\nYTD P&L:                                            \r\n\r\n2015-11-09",
      "recipients" : {
        "signers" : [ {
          "routingOrder" : "1",
          "name" : "John Doe",
          "email" : "John.Doe@gmail.com",
          "recipientId" : "1",
          "tabs" : {
            "signHereTabs" : [ {
              "anchorString" : "By:",
              "anchorXOffset" : "0",
              "anchorYOffset" : "0",
              "anchorIgnoreIfNotPresent" : "true",
              "anchorUnits" : "inches"
            } ]
          }
        } ],
        "carbonCopies" : [ ]
      },
      "documents" : [ {
        "name" : "CustomerOneSigner.pdf",
        "documentId" : "1",
        "bytes" : "Omitted for Better readablity"
      } ],
      "status" : "sent"
    }

Request Body what Docusign Recieves

{
  "emailSubject" : "IRT16,17,18,19,20 MCI as of 11/10/2015",
  "emailBlurb" : "Buenos d�as/Tardes, \r\n\r\nAdjunto la documentaci�n de la(s) transacci�n(es) con fecha de ejecuci�n [Trade Date].  Rogamos que, en prueba de conformidad con los t�rminos de la operaci�n contenidos en esta Confirmaci�n, nos devuelvan la copia adjunta debidamente firmada dentro de los siguientes dos d�as h�biles a partir de la fecha de ejecuci�n. \r\n\r\nComo resultado de dicha(s) liquidaci�n(es), [Cargill/Counterparty Name] deber� hacer un pago de US $XXX,XXX.XX el d�a [Payment date],  Adjunto la factura correspondiente. Por favor confirmar como quieren que se maneje este saldo.\r\n\r\nCualquier inquietud al respecto por favor comunicarse conmigo.\r\n\r\nUn cordial saludo,\r\n\r\n\r\nAttached is your intercompany statement as of 10-30-2015 with Cargill Risk Management.\r\n\r\nPlease confirm by filling out below template with your amounts and accounts and then replying to all. \r\n\r\n                              Please enter your amount:   Please enter your G/L account:\r\n\r\nPosition Market Value:                              \r\n\r\nPayable/Receivable:                                 \r\n\r\nYTD P&L:                                            \r\n\r\n2015-11-09",
  "recipients" : {
    "signers" : [ {
      "routingOrder" : "1",
      "name" : "John Doe",
      "email" : "John.Doe@gmail.com",
      "recipientId" : "1",
      "tabs" : {
        "signHereTabs" : [ {
          "anchorString" : "By:",
          "anchorXOffset" : "0",
          "anchorYOffset" : "0",
          "anchorIgnoreIfNotPresent" : "true",
          "anchorUnits" : "inches"
        } ]
      }
    } ],
    "carbonCopies" : [ ]
  },
  "documents" : [ {
    "name" : "CustomerOneSigner.pdf",
    "documentId" : "1",
    "bytes" : "Omitted"
  } ],
  "status" : "sent"
}

回答1:


EDIT :

Best option is to escape unicode:

Instead of this:

Buenos días/Tardes, \r\n\r\nAdjunto la documentación de la(s) transacción(es) con fecha de ejecución [Trade Date].  Rogamos que, en prueba de conformidad con los términos de la operación contenidos en esta Confirmación, nos devuelvan la copia adjunta debidamente firmada dentro de los siguientes dos días hábiles a partir de la fecha de ejecución. \r\n\r\nComo resultado de dicha(s) liquidación(es), [Cargill/Counterparty Name] deberá hacer un pago de US $XXX,XXX.XX el día [Payment date],  Adjunto la factura correspondiente. Por favor confirmar como quieren que se maneje este saldo.\r\n\r\nCualquier inquietud al respecto por favor comunicarse conmigo.\r\n\r\nUn cordial saludo,\r\n\r\n\r\nAttached is your intercompany statement as of 10-30-2015 with Cargill Risk Management.\r\n\r\nPlease confirm by filling out below template with your amounts and accounts and then replying to all. \r\n\r\n                              Please enter your amount:   Please enter your G/L account:\r\n\r\nPosition Market Value:                              \r\n\r\nPayable/Receivable:                                 \r\n\r\nYTD P&L:                                            \r\n\r\n2015-11-09

Use:

Buenos%20d%EDas/Tardes%2C%20%0D%0A%0D%0AAdjunto%20la%20documentaci%F3n%20de%20la%28s%29%20transacci%F3n%28es%29%20con%20fecha%20de%20ejecuci%F3n%20%5BTrade%20Date%5D.%20%20Rogamos%20que%2C%20en%20prueba%20de%20conformidad%20con%20los%20t%E9rminos%20de%20la%20operaci%F3n%20contenidos%20en%20esta%20Confirmaci%F3n%2C%20nos%20devuelvan%20la%20copia%20adjunta%20debidamente%20firmada%20dentro%20de%20los%20siguientes%20dos%20d%EDas%20h%E1biles%20a%20partir%20de%20la%20fecha%20de%20ejecuci%F3n.%20%0D%0A%0D%0AComo%20resultado%20de%20dicha%28s%29%20liquidaci%F3n%28es%29%2C%20%5BCargill/Counterparty%20Name%5D%20deber%E1%20hacer%20un%20pago%20de%20US%20%24XXX%2CXXX.XX%20el%20d%EDa%20%5BPayment%20date%5D%2C%20%20Adjunto%20la%20factura%20correspondiente.%20Por%20favor%20confirmar%20como%20quieren%20que%20se%20maneje%20este%20saldo.%0D%0A%0D%0ACualquier%20inquietud%20al%20respecto%20por%20favor%20comunicarse%20conmigo.%0D%0A%0D%0AUn%20cordial%20saludo%2C%0D%0A%0D%0A%0D%0AAttached%20is%20your%20intercompany%20statement%20as%20of%2010-30-2015%20with%20Cargill%20Risk%20Management.%0D%0A%0D%0APlease%20confirm%20by%20filling%20out%20below%20template%20with%20your%20amounts%20and%20accounts%20and%20then%20replying%20to%20all.%20%0D%0A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Please%20enter%20your%20amount%3A%20%20%20Please%20enter%20your%20G/L%20account%3A%0D%0A%0D%0APosition%20Market%20Value%3A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0D%0A%0D%0APayable/Receivable%3A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0D%0A%0D%0AYTD%20P%26L%3A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0D%0A%0D%0A2015-11-09

http://unicode.online-toolz.com/tools/text-unicode-entities-convertor.php




回答2:


Found a Solution, before calling the POST method convert the request body to UTF-8 so the code now is

 String body = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(
                envelope);
    body =  docuSignUtils.convertToUTF8(body);            
    conn = initializeRequest(url, "POST", body,getAuthenticationHeader());

ConverttoUTF* function is something like this

 public  String convertToUTF8(String s) {
            String out = null;
            try {
                out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
            } catch (java.io.UnsupportedEncodingException e) {
                return null;
            }
            return out;
        }

earlier I was just converting the EmailBlurb into UTF-8 , which did not work we need to convert the whole Envelope Object into UTF-8



来源:https://stackoverflow.com/questions/33764977/docusign-rest-with-utf-8-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!