private boolean identifyNewDiffResource(HttpServletRequest request, HttpServletResponse response)
     throws ServletException {
   try {
     StringWriter writer = new StringWriter();
     IOUtilities.pipe(request.getReader(), writer, false, false);
     JSONObject requestObject = new JSONObject(writer.toString());
     URI u = getURI(request);
     IPath p = new Path(u.getPath());
     IPath np = new Path("/"); // $NON-NLS-1$
     for (int i = 0; i < p.segmentCount(); i++) {
       String s = p.segment(i);
       if (i == 2) {
         s += ".."; // $NON-NLS-1$
         s += GitUtils.encode(requestObject.getString(GitConstants.KEY_COMMIT_NEW));
       }
       np = np.append(s);
     }
     if (p.hasTrailingSeparator()) np = np.addTrailingSeparator();
     URI nu =
         new URI(
             u.getScheme(),
             u.getUserInfo(),
             u.getHost(),
             u.getPort(),
             np.toString(),
             u.getQuery(),
             u.getFragment());
     JSONObject result = new JSONObject();
     result.put(ProtocolConstants.KEY_LOCATION, nu.toString());
     OrionServlet.writeJSONResponse(request, response, result);
     response.setHeader(
         ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString());
     return true;
   } catch (Exception e) {
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "An error occured when identifying a new Diff resource.",
             e));
   }
 }
Exemplo n.º 2
0
 private boolean identifyNewCommitResource(
     HttpServletRequest request, HttpServletResponse response, Repository db, String newCommit)
     throws ServletException {
   try {
     URI u = getURI(request);
     IPath p = new Path(u.getPath());
     IPath np = new Path("/"); // $NON-NLS-1$
     for (int i = 0; i < p.segmentCount(); i++) {
       String s = p.segment(i);
       if (i == 2) {
         s += ".." + newCommit; // $NON-NLS-1$
       }
       np = np.append(s);
     }
     if (p.hasTrailingSeparator()) np = np.addTrailingSeparator();
     URI nu =
         new URI(
             u.getScheme(),
             u.getUserInfo(),
             u.getHost(),
             u.getPort(),
             np.toString(),
             u.getQuery(),
             u.getFragment());
     JSONObject result = new JSONObject();
     result.put(ProtocolConstants.KEY_LOCATION, nu);
     OrionServlet.writeJSONResponse(
         request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
     response.setHeader(
         ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString());
     return true;
   } catch (Exception e) {
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "An error occured when identifying a new Commit resource.",
             e));
   }
 }