Package org.sonatype.plexus.rest.resource

Examples of org.sonatype.plexus.rest.resource.PlexusResourceException


        }

        TreeNode node = indexerManager.listNodes(factory, path, hints, null, repository.getId());

        if (node == null) {
          throw new PlexusResourceException(Status.CLIENT_ERROR_NOT_FOUND,
              "Unable to retrieve index tree nodes");
        }

        return new IndexBrowserTreeViewResponseDTO(((IndexBrowserTreeNode) node).toDTO());
      }
      else {
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
            "The index is disabled for this repository.");
      }
    }
    catch (NoSuchRepositoryAccessException e) {
      getLogger().warn("Repository access denied, id=" + repositoryId);
      throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository");
    }
    catch (NoSuchRepositoryException e) {
      getLogger().error("Repository Not Found, id=" + repositoryId, e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found", e);
    }
    catch (IOException e) {
      getLogger().error("Got IO exception while executing treeView, id=" + repositoryId, e);
      throw new PlexusResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage(), e);
    }
  }
View Full Code Here


      this.ldapConnectionTester.testConnection(ldapContextFactory);
    }
    catch (MalformedURLException e) {
      // should NEVER hit this
      this.getLogger().debug("LDAP Realm is not configured correctly: " + e.getMessage(), e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "LDAP Realm is not configured correctly: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("LDAP Server Connection information is invalid: ", e)));
    }
    catch (Exception e) {
      this.getLogger().debug("Failed to connect to Ldap Server.", e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "LDAP Realm is not configured correctly: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("Failed to connect to Ldap Server: ", e)));
    }

    response.setStatus(Status.SUCCESS_NO_CONTENT);
View Full Code Here

      return searchResponse;
    }
    catch (IllegalArgumentException e) {
      if (e.getCause() instanceof ParseException) {
        // NEXUS-4372: illegal query -> 400 response
        throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getCause(),
            getNexusErrorResponse("search", e.getCause().getMessage()));
      }
      else {
        throw e;
      }
View Full Code Here

    // try the login
    try {
      this.ldapManager.authenticateUserTest(username, password, ldapServer);
    }
    catch (Exception e) {
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Login attempt failed: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("Error connecting to LDAP Server: ", e)));
    }

    // success
View Full Code Here

      }

    }
    catch (MalformedURLException e) {
      getLogger().debug("LDAP Realm is not configured correctly: " + e.getMessage(), e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "LDAP Realm is not configured correctly: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("LDAP Server Connection information is invalid: ", e)));
    }
    catch (LdapDAOException e) {
      getLogger().debug("LDAP Realm is not configured correctly: " + e.getMessage(), e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "LDAP Realm is not configured correctly: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("Invalid LDAP Server Configuration: ", e)));
    }
    catch (NamingException e) {
      getLogger().debug("LDAP Realm is not configured correctly: " + e.getMessage(), e);
      throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "LDAP Realm is not configured correctly: "
          + e.getMessage(), e,
          this.getErrorResponse("*", this.buildExceptionMessage("Error connecting to LDAP Server: ", e)));
    }
    return result;
  }
View Full Code Here

    if (routeRequest != null) {
      RepositoryRouteResource resource = routeRequest.getData();

      if (!RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType())
          && (resource.getRepositories() == null || resource.getRepositories().size() == 0)) {
        throw new PlexusResourceException(
            Status.CLIENT_ERROR_BAD_REQUEST,
            "The route cannot have zero repository members!",
            getNexusErrorResponse("repositories",
                "The route cannot have zero repository members!"));
      }
      else if (RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType())) {
        resource.setRepositories(null);
      }

      resource.setId(Long.toHexString(System.nanoTime()));

      try {
        ArrayList<String> mappedReposes = new ArrayList<String>(resource.getRepositories().size());

        for (RepositoryRouteMemberRepository member : resource.getRepositories()) {
          mappedReposes.add(member.getId());
        }

        RepositoryPathMapping route =
            new RepositoryPathMapping(resource.getId(), resource2configType(resource.getRuleType()),
                resource.getGroupId(), Arrays.asList(new String[]{
                resource
                    .getPattern()
            }), mappedReposes);

        getRepositoryMapper().addMapping(route);

        getNexusConfiguration().saveConfiguration();

        resource.setGroupId(route.getGroupId());

        result = new RepositoryRouteResourceResponse();

        result.setData(resource);
      }
      catch (ConfigurationException e) {
        if (e.getCause() != null && e.getCause() instanceof PatternSyntaxException) {
          throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.",
              getNexusErrorResponse("pattern", e.getMessage()));
        }
        else {
          handleConfigurationException(e);
        }
      }
      catch (PatternSyntaxException e) {
        // TODO: fix because this happens before we validate, we need to fix the validation.
        ErrorResponse errorResponse = getNexusErrorResponse("*", e.getMessage());
        throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", errorResponse);
      }
/*            catch ( NoSuchRepositoryException e )
            {
                getLogger().warn( "Cannot find a repository referenced within a route!", e );

View Full Code Here

      RepositoryRouteResource resource = routeRequest.getData();

      if ((!RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType()) && (resource
          .getRepositories() == null || resource.getRepositories().size() == 0))
          || resource.getId() == null || !resource.getId().equals(getRouteId(request))) {
        throw new PlexusResourceException(
            Status.CLIENT_ERROR_BAD_REQUEST,
            "The route cannot have zero repository members!",
            getNexusErrorResponse("repositories",
                "The route cannot have zero repository members!"));
      }
      else if (RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType())) {
        resource.setRepositories(null);
      }

      try {
        RepositoryPathMapping route = getRepositoryMapper().getMappings().get(getRouteId(request));

        if (route == null) {
          throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Route not found!");
        }

        ArrayList<String> mappedReposes = new ArrayList<String>(resource.getRepositories().size());

        for (RepositoryRouteMemberRepository member : resource.getRepositories()) {
          mappedReposes.add(member.getId());
        }

        RepositoryPathMapping newRoute =
            new RepositoryPathMapping(route.getId(), resource2configType(resource.getRuleType()),
                resource.getGroupId(), Arrays.asList(new String[]{
                resource
                    .getPattern()
            }), mappedReposes);

        getRepositoryMapper().addMapping(newRoute);

        getNexusConfiguration().saveConfiguration();

        response.setStatus(Status.SUCCESS_NO_CONTENT);
      }
      catch (ConfigurationException e) {
        if (e.getCause() != null && e.getCause() instanceof PatternSyntaxException) {
          throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.",
              getNexusErrorResponse("pattern", e.getMessage()));
        }
        else {
          handleConfigurationException(e);
        }
      }
      catch (PatternSyntaxException e) {
        // TODO: fix because this happens before we validate, we need to fix the validation.
        ErrorResponse errorResponse = getNexusErrorResponse("*", e.getMessage());
        throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", errorResponse);
      }
/*            catch ( NoSuchRepositoryAccessException e )
            {
                getLogger().debug( "Access Denied to a repository referenced within a route!", e );

View Full Code Here

        throw new ResourceException(Status.CLIENT_ERROR_CONFLICT, e.getMessage());
      }
      catch (ParseException e) {
        getLogger().warn("Unable to parse data for task " + getModelName(serviceResource));

        throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(),
            getNexusErrorResponse("cronCommand", e.getMessage()));
      }
      catch (InvalidConfigurationException e) {
        handleConfigurationException(e);
      }
View Full Code Here

TOP

Related Classes of org.sonatype.plexus.rest.resource.PlexusResourceException

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.