/** * Checks object reference is not {@code null} * * @param object object reference to check * @param subject used as subject of exception message "{subject} required" * @throws BadRequestException when object reference is {@code null} */ private void requiredNotNull(Object object, String subject) throws BadRequestException { if (object == null) { throw new BadRequestException(subject + " required"); } }
/** * Checks object reference is not {@code null} * * @param object object reference to check * @param subject used as subject of exception message "{subject} required" * @throws BadRequestException when object reference is {@code null} */ private void requiredNotNull(Object object, String subject) throws BadRequestException { if (object == null) { throw new BadRequestException(subject + " required"); } } }
/** * Checks object reference is not {@code null} * * @param object object reference to check * @param subject used as subject of exception message "{subject} required" * @throws BadRequestException when object reference is {@code null} */ private void requiredNotNull(Object object, String subject) throws BadRequestException { if (object == null) { throw new BadRequestException(subject + " required"); } } }
/** * Checks object reference is not {@code null} * * @param object object reference to check * @param subject used as subject of exception message "{subject} required" * @throws BadRequestException when object reference is {@code null} */ private void requiredNotNull(Object object, String subject) throws BadRequestException { if (object == null) { throw new BadRequestException(subject + " required"); } } }
/** * Checks that key consists either from workspaceId or username:workspace_name string. * * @param key key string to validate * @throws BadRequestException if validation is failed */ public static void validateKey(String key) throws BadRequestException { String[] parts = key.split(":", -1); // -1 is to prevent skipping trailing part switch (parts.length) { case 1: { return; // consider it's id } case 2: { if (parts[1].isEmpty()) { throw new BadRequestException( "Wrong composite key format - workspace name required to be set."); } break; } default: { throw new BadRequestException( format("Wrong composite key %s. Format should be 'username:workspace_name'. ", key)); } } } }
private OAuthAuthenticator getAuthenticator(String oauthProviderName) throws BadRequestException { OAuthAuthenticator oauth = providers.getAuthenticator(oauthProviderName); if (oauth == null) { LOG.warn(format(UNSUPPORTED_OAUTH_PROVIDER_ERROR, oauthProviderName)); throw new BadRequestException(format(UNSUPPORTED_OAUTH_PROVIDER_ERROR, oauthProviderName)); } return oauth; }
@GET @Path("branch") @Produces(MediaType.APPLICATION_JSON) public List<Branch> branchList(@QueryParam("listMode") String listMode) throws ApiException { try (GitConnection gitConnection = getGitConnection()) { return gitConnection.branchList(listMode == null ? null : BranchListMode.valueOf(listMode)); } catch (IllegalArgumentException exception) { throw new BadRequestException(exception.getMessage()); } }
@Override public Response authenticate( UriInfo uriInfo, String oauthProvider, List<String> scopes, String redirectAfterLogin, HttpServletRequest request) throws BadRequestException { Jwt jwtToken = (Jwt) request.getAttribute("token"); if (jwtToken == null) { throw new BadRequestException("No token provided."); } String accountLinkUrl = keycloakServiceClient.getAccountLinkingURL(jwtToken, oauthProvider, redirectAfterLogin); return Response.temporaryRedirect(URI.create(accountLinkUrl)).build(); }
final int colonIdx = attribute.indexOf(':'); if (colonIdx == -1) { throw new BadRequestException( "Attribute '" + attribute throw new BadRequestException( "Attribute '" + attribute
private Workspace doUpdate(String id, Workspace update) throws BadRequestException, ConflictException, NotFoundException, ServerException { try { return workspaceManager.updateWorkspace(id, update); } catch (ValidationException x) { throw new BadRequestException(x.getMessage()); } }
/** * Validates given {@code freeResourcesLimit} * * @param freeResourcesLimit resources limit to validate * @throws BadRequestException when {@code freeResourcesLimit} is null * @throws BadRequestException when any of {@code freeResourcesLimit.getResources} is not valid * @see ResourceValidator#validate(ResourceDto) */ public void check(FreeResourcesLimitDto freeResourcesLimit) throws BadRequestException { if (freeResourcesLimit == null) { throw new BadRequestException("Missed free resources limit description."); } if (freeResourcesLimit.getAccountId() == null) { throw new BadRequestException("Missed account id."); } Set<String> resourcesToSet = new HashSet<>(); for (ResourceDto resource : freeResourcesLimit.getResources()) { if (!resourcesToSet.add(resource.getType())) { throw new BadRequestException( format( "Free resources limit should contain only one resources with type '%s'.", resource.getType())); } resourceValidator.validate(resource); } } }
@GET @Produces(APPLICATION_JSON) @ApiOperation( value = "Get a collection of the available installers", response = Installer.class, responseContainer = "collection") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains collection of available installers"), @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response getInstallers( @ApiParam(value = "Max items") @QueryParam("maxItems") @DefaultValue("30") int maxItems, @ApiParam(value = "Skip count") @QueryParam("skipCount") @DefaultValue("0") int skipCount) throws InstallerException, BadRequestException { try { Page<? extends Installer> installers = installerRegistry.getInstallers(maxItems, skipCount); return Response.ok() .entity( installers.getItems().stream().map(DtoConverter::asDto).collect(Collectors.toList())) .header("Link", createLinkHeader(installers)) .header(TOTAL_ITEMS_COUNT_HEADER, installers.getTotalItemsCount()) .build(); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage()); } }
/** * Validate stack object * * @param stack stack to validate * @throws BadRequestException if stack is not valid */ public void check(Stack stack) throws BadRequestException, ServerException, NotFoundException { if (stack == null) { throw new BadRequestException("Required non-null stack"); } if (stack.getName() == null || stack.getName().isEmpty()) { throw new BadRequestException("Required non-null and non-empty stack name"); } if (stack.getScope() == null || !stack.getScope().equals("general") && !stack.getScope().equals("advanced")) { throw new BadRequestException("Required non-null scope value: 'general' or 'advanced'"); } if (stack.getWorkspaceConfig() == null) { throw new BadRequestException("Workspace config required"); } try { wsValidator.validateConfig(stack.getWorkspaceConfig()); } catch (ValidationException x) { throw new BadRequestException(x.getMessage()); } } }
throw new BadRequestException("Missed resource"); throw new BadRequestException( "Specified resources type '" + resource.getType() + "' is not supported"); } else { if (!units.contains(resource.getUnit())) { throw new BadRequestException( "Specified resources type '" + resource.getType() throw new BadRequestException( "Resources with type '" + resource.getType() + "' has negative amount");
return asDtoWithLinksAndToken(workspace); } catch (ValidationException x) { throw new BadRequestException(x.getMessage());
@POST @Consumes(APPLICATION_JSON) @GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR) @ApiOperation( value = "Create a new ssh pair", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created ssh pair") @ApiResponses({ @ApiResponse(code = 204, message = "The ssh pair successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse( code = 409, message = "Conflict error occurred during the ssh pair creation" + "(e.g. The Ssh pair with such name and service already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void createPair( @ApiParam(value = "The ssh pair to create", required = true) SshPairDto sshPair) throws BadRequestException, ServerException, ConflictException { requiredNotNull(sshPair, "Ssh pair required"); requiredNotNull(sshPair.getService(), "Service name required"); requiredNotNull(sshPair.getName(), "Name required"); if (sshPair.getPublicKey() == null && sshPair.getPrivateKey() == null) { throw new BadRequestException("Key content was not provided."); } sshManager.createPair(new SshPairImpl(getCurrentUserId(), sshPair)); }
throw new ServerException(serviceError); } else if (responseCode == Response.Status.BAD_REQUEST.getStatusCode()) { throw new BadRequestException(serviceError);
workspace = workspaceManager.createWorkspace(config, namespace, attributes); } catch (ValidationException x) { throw new BadRequestException(x.getMessage());
throw new ServerException(serviceError.getErrorMessage()); } else if (responseCode == Response.Status.BAD_REQUEST.getStatusCode()) { throw new BadRequestException(serviceError.getErrorMessage());
requiredNotNull(name, "Name required"); if (privateKey == null && publicKey == null) { throw new BadRequestException("Key content was not provided.");