/**
 * Copyright (C) 2000 - 2013 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Affero General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of the GPL, you may
 * redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
 * applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
 * text describing the FLOSS exception, and it is also available here:
 * "http://www.silverpeas.org/docs/core/legal/floss_exception.html"
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package com.silverpeas.directory.servlets;

import com.silverpeas.directory.control.DirectorySessionController;
import com.stratelia.silverpeas.notificationManager.NotificationManagerException;
import com.stratelia.silverpeas.notificationManager.UserRecipient;
import com.stratelia.silverpeas.peasCore.MainSessionController;
import com.stratelia.silverpeas.silvertrace.SilverTrace;
import java.io.IOException;
import java.io.Writer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.json.JSONObject;
import org.owasp.encoder.Encode;

public class DirectoryJSONServlet extends HttpServlet {

  private static final long serialVersionUID = 3351692741655439410L;

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    doPost(req, res);
  }

  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    HttpSession session = req.getSession(true);
    DirectorySessionController dsc = (DirectorySessionController) session.getAttribute(
        "Silverpeas_directory");
    if (dsc == null) {
      MainSessionController msc = (MainSessionController) session.getAttribute(
          MainSessionController.MAIN_SESSION_CONTROLLER_ATT);
      if (msc != null) {
        dsc = new DirectorySessionController(msc, msc.createComponentContext(null, null));
      }
    }
    res.setContentType("application/json");
    String action = req.getParameter("Action");
    Writer writer = res.getWriter();
    JSONObject jsonObject = new JSONObject();
    if ("SendMessage".equals(action) && dsc != null) {
      try {
        UserRecipient[] selectedUsers = new UserRecipient[1];
        selectedUsers[0] = new UserRecipient(req.getParameter("TargetUserId"));
        String title = req.getParameter("Title");
        String message = Encode.forHtml(req.getParameter("Message"));
        dsc.sendMessage(null, title, message, selectedUsers);
        jsonObject.put("success", true);
      } catch (NotificationManagerException ex) {
        SilverTrace.error("directory", "DirectoryRequestRouter.sendMessage", "ERROR", ex);
        jsonObject.put("success", false);
        jsonObject.put("error", ex.toString());
      }
    }
    writer.write(jsonObject.toString());
  }
}

@@ -1518,51 +1518,72 @@
 ort 
-java.io.IOException;%0Aimport java.io.Writer;
+org.owasp.encoder.Encode;%0Aimport org.silverpeas.util.JSONCodec;%0A
 %0Aimp
@@ -1800,60 +1800,50 @@
 ort 
-org.json.JSONObject;%0Aimport org.owasp.encoder.Encode
+java.io.IOException;%0Aimport java.io.Writer
 ;%0A%0Ap
@@ -2849,48 +2849,30 @@
     
-JSONObject jsonObject = new JSONObject()
+String jsonStatus = %22%22
 ;%0A  
@@ -3264,38 +3264,70 @@
 s);%0A        json
-Object
+Status = JSONCodec.encodeObject(o -%3E o
 .put(%22success%22, 
@@ -3327,24 +3327,25 @@
 cess%22, true)
+)
 ;%0A      %7D ca
@@ -3483,30 +3483,74 @@
         json
-Object
+Status =%0A            JSONCodec.encodeObject(o -%3E o
 .put(%22succes
@@ -3563,28 +3563,8 @@
 lse)
-;%0A        jsonObject
 .put
@@ -3583,24 +3583,25 @@
 .toString())
+)
 ;%0A      %7D%0A  
@@ -3629,25 +3629,14 @@
 json
-Object.toString()
+Status
 );%0A 

Replace the use of the JSONObject from json-rpc lib by JSONCodec in DirectoryJSONServlet