Package org.eclipse.orion.server.core

Examples of org.eclipse.orion.server.core.ServerStatus


        if ("GET".equals(req.getMethod())) { //$NON-NLS-1$
          if (serveOrionFile(req, resp, site, new Path(uri.getPath()), failEarlyOn404))
            return;
        } else {
          String message = "Only GET method is supported for workspace paths";
          handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_METHOD_NOT_ALLOWED, NLS.bind(message, mappedURIs), null));
          return;
        }
      } else {
        if (serveURI(req, new LocationHeaderServletResponseWrapper(req, resp, site), uri, failEarlyOn404))
          return;
View Full Code Here


      boolean fileMatch = AuthorizationService.checkRights(userId, fileURI, "GET"); //$NON-NLS-1$
      boolean dirMatch = fileURI.endsWith("/") && AuthorizationService.checkRights(userId, fileURI, "GET"); //$NON-NLS-1$ //$NON-NLS-2$
      if (fileMatch || dirMatch) {
        allow = true;
      } else {
        handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("No rights to access {0}", fileURI), null));
      }
    } catch (CoreException e) {
      throw new ServletException(e);
    }

    if (allow) {
      // FIXME: this code is copied from NewFileServlet, fix it
      // start copied
      String pathInfo = path.toString();
      IPath filePath = pathInfo == null ? Path.ROOT : new Path(pathInfo);
      IFileStore file = tempGetFileStore(filePath);
      if (file == null || !file.fetchInfo().exists()) {
        if (failEarlyOn404) {
          return false;
        }
        handleException(resp, new ServerStatus(IStatus.ERROR, 404, NLS.bind("File not found: {0}", filePath), null));
        return true;
      }
      if (fileSerializer.handleRequest(req, resp, file)) {
        //return;
      }
View Full Code Here

      // Otherwise proxy as a remote URL.
      return proxyRemoteUrl(req, resp, new URL(remoteURI.toString()), failEarlyOn404);
    } catch (MalformedURLException e) {
      String message = NLS.bind("Malformed remote URL: {0}", remoteURI.toString());
      logger.error(message, e);
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, message, e));
    } catch (UnknownHostException e) {
      String message = NLS.bind("Unknown host {0}", e.getMessage());
      logger.error(message, e);
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, message, e));
    } catch (Exception e) {
      String message = NLS.bind("An error occurred while retrieving {0}", remoteURI.toString());
      logger.error(message, e);
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message, e));
    }
    return true;
  }
View Full Code Here

    result = new SetSpaceCommand(this.target, targetJSON != null ? targetJSON.optString("Space") : null).doIt();
    if (!result.isOK())
      return result;

    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
  }
View Full Code Here

      return HttpUtil.executeMethod(stopMethod);
    } catch (Exception e) {
      String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
  }
View Full Code Here

  private boolean handlePost(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException {
    //setup and precondition checks
    JSONObject requestObject = OrionServlet.readJSONRequest(request);
    String name = computeName(request, requestObject);
    if (name.length() == 0)
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null));
    IFileStore toCreate = dir.getChild(name);
    if (!name.equals(toCreate.getName()) || name.contains(":"))
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad file name: " + name, null));
    int options = getCreateOptions(request);
    boolean destinationExists = toCreate.fetchInfo(EFS.NONE, null).exists();
    if (!validateOptions(request, response, toCreate, destinationExists, options))
      return true;
    //perform the operation
View Full Code Here

        toCreate.openOutputStream(EFS.NONE, null).close();
    } catch (CoreException e) {
      IStatus status = e.getStatus();
      if (status != null && status.getCode() == EFS.ERROR_WRITE) {
        // Sanitize message, as it might contain the filepath.
        statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create: " + toCreate.getName(), null));
        return false;
      }
      throw e;
    }
    return true;
View Full Code Here

   * @return <code>true</code> if the operation was successful, and <code>false</code> otherwise.
   */
  private boolean performCopyMove(HttpServletRequest request, HttpServletResponse response, JSONObject requestObject, IFileStore toCreate, boolean isCopy, int options) throws ServletException, CoreException {
    String locationString = requestObject.optString(ProtocolConstants.KEY_LOCATION, null);
    if (locationString == null) {
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Copy or move request must specify source location", null));
      return false;
    }
    try {
      IFileStore source = resolveSourceLocation(request, locationString);
      if (source == null) {
        statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("Source does not exist: ", locationString), null));
        return false;
      } else if (source.isParentOf(toCreate)) {
        statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "The destination cannot be a descendent of the source location", null));
        return false;
      }
      boolean allowOverwrite = (options & CREATE_NO_OVERWRITE) == 0;
      int efsOptions = allowOverwrite ? EFS.OVERWRITE : EFS.NONE;
      try {
        if (isCopy) {
          source.copy(toCreate, efsOptions, null);
        } else {
          source.move(toCreate, efsOptions, null);
          // Path format is /file/workspaceId/projectId/[location to folder]
          Path path = new Path(locationString);
          if (path.segmentCount() == 3 && path.segment(0).equals("file")) {
            // The folder is a project, remove the metadata
            OrionConfiguration.getMetaStore().deleteProject(path.segment(1), source.getName());
          }
        }
      } catch (CoreException e) {
        if (!source.fetchInfo(EFS.NONE, null).exists()) {
          statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("Source does not exist: ", locationString), e));
          return false;
        }
        if (e.getStatus().getCode() == EFS.ERROR_EXISTS) {
          statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_PRECONDITION_FAILED, "A file or folder with the same name already exists at this location", null));
          return false;
        }
        //just rethrow if we can't do something more specific
        throw e;
      }
    } catch (URISyntaxException e) {
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Bad source location in request: ", locationString), e));
      return false;
    }
    return true;
  }
View Full Code Here

   */
  private boolean validateOptions(HttpServletRequest request, HttpServletResponse response, IFileStore toCreate, boolean destinationExists, int options) throws ServletException {
    //operation cannot be both copy and move
    int copyMove = CREATE_COPY | CREATE_MOVE;
    if ((options & copyMove) == copyMove) {
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Syntax error in request", null));
      return false;
    }
    //if overwrite is disallowed make sure destination does not exist yet
    boolean noOverwrite = (options & CREATE_NO_OVERWRITE) != 0;
    //for copy/move case, let the implementation check for overwrite because pre-validating is complicated
    if ((options & copyMove) == 0 && noOverwrite && destinationExists) {
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_PRECONDITION_FAILED, "A file or folder with the same name already exists at this location", null));
      return false;
    }
    return true;
  }
View Full Code Here

          return handleDelete(request, response, dir);
        default :
          return false;
      }
    } catch (JSONException e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Syntax error in request", e));
    } catch (CoreException e) {
      //core exception messages are designed for end user consumption, so use message directly
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    } catch (Exception e) {
      if (handleAuthFailure(request, response, e))
        return true;
      //the exception message is probably not appropriate for end user consumption
      LogHelper.log(e);
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An unknown failure occurred. Consult your server log or contact your system administrator.", e));
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.ServerStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.