Uploaded image for project: 'Change Request Application'
  1. Change Request Application
  2. CRAPP-295

ActionHandler wrong to set content length on answerJSON

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 1.9.2
    • 1.9.1
    • None
    • None
    • Unknown
    • N/A
    • N/A

    Description

      AbstractChangeRequestActionHandler

      protected void answerJSON(int status, Map<String, String> answer) throws IOException
      {
          ObjectMapper mapper = new ObjectMapper();
          XWikiContext context = contextProvider.get();
          XWikiResponse response = context.getResponse();
          String jsonAnswerAsString = mapper.writeValueAsString(answer);
          response.setContentType("application/json");
          // cause by 
          response.setContentLength(jsonAnswerAsString.length());
         // when comments or jsonAnswerAsString.getBytes(context.getWiki().getEncoding()).length works well   
      
          response.setStatus(status);
          response.setCharacterEncoding(context.getWiki().getEncoding());// Default UTF8
          response.getWriter().print(jsonAnswerAsString);
          context.setResponseSent(true);
      } 

      if answer has UTF8 characters. ContentLength is not enough to response data.

      Reproduction steps:

      • XWiki support multiple languages with ChangeRequest supported de/fr/ja
      • ChangeRquest Configuration check "ONLY ACCEPT APPROVERS THAT HAVE THE APPROVAL RIGHT"
      • Open a new change request and the approvers group set XWikiAllGroup
      • Save it will check the approval right and response "changeRequestError" with translation "changerequest.checkers.approversright.incompatibilityReason"
      • UI show the otherError
      • Change the language to de and save again.
      • UI now not show other error.

      Expected result:

      • Correct response data

      Obtained result:

      • Response data was truncated,ajax callback not resolve, ui not show the otherError.
        {"changeRequestError":"Der gewählte Genehmigende hat nicht die richtigen Rechte für die Genehmigung. 

       

      Attachments

        Issue Links

          Activity

            People

              surli Simon Urli
              wrck wrck
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: