/** * 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"); } }
.createDtoFromJson(toJson(response), KeycloakTokenResponse.class); } catch (BadRequestException e) { if (assotiateUserPattern.matcher(e.getMessage()).matches()) { throw new UnauthorizedException(e.getMessage());
@Override public Installer getInstaller(String installerKey) throws InstallerException { checkConfiguration(); try { return requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "getInstaller") .build(installerKey) .toString()) .useGetMethod() .request() .asDto(InstallerDto.class); } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (BadRequestException e) { throw new IllegalInstallerKeyException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
/** * 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"); } } }
@Override public List<Installer> getOrderedInstallers(List<String> installerKeys) throws InstallerException { checkConfiguration(); try { return new ArrayList<>( requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "getOrderedInstallers") .build() .toString()) .usePostMethod() .setBody(installerKeys) .request() .asList(InstallerDto.class)); } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (BadRequestException e) { throw new IllegalInstallerKeyException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
/** * 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"); } } }
+ "' identity provider", e); if (e.getMessage().endsWith("Invalid token.")) { throw new InfrastructureException( "Your session has expired. \nPlease " + "</a> to Che again to get access to your Openshift account"); throw new InfrastructureException(e.getMessage(), e); } catch (Exception e) { LOG.error(
/** * 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());
throw new ServerException(serviceError); } else if (responseCode == Response.Status.BAD_REQUEST.getStatusCode()) { throw new BadRequestException(serviceError);