Java Code Examples for org.eclipse.jetty.http.HttpStatus#BAD_REQUEST_400
The following examples show how to use
org.eclipse.jetty.http.HttpStatus#BAD_REQUEST_400 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AliasRoutes.java From james-project with Apache License 2.0 | 6 votes |
@DELETE @Path(ROOT_PATH + "/{" + ALIAS_DESTINATION_ADDRESS + "}/sources/{" + ALIAS_SOURCE_ADDRESS + "}") @ApiOperation(value = "remove an alias from a destination address") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = ALIAS_DESTINATION_ADDRESS, paramType = "path", value = "Destination mail address of the alias to remove.\n" + MAILADDRESS_ASCII_DISCLAIMER), @ApiImplicitParam(required = true, dataType = "string", name = ALIAS_SOURCE_ADDRESS, paramType = "path", value = "Source mail address of the alias to remove.\n" + MAILADDRESS_ASCII_DISCLAIMER) }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = ALIAS_DESTINATION_ADDRESS + " or alias structure format is not valid"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public HaltException deleteAlias(Request request, Response response) throws RecipientRewriteTableException { MailAddress destinationAddress = MailAddressParser.parseMailAddress(request.params(ALIAS_DESTINATION_ADDRESS), ADDRESS_TYPE); MailAddress aliasToBeRemoved = MailAddressParser.parseMailAddress(request.params(ALIAS_SOURCE_ADDRESS), ADDRESS_TYPE); MappingSource source = MappingSource.fromMailAddress(aliasToBeRemoved); recipientRewriteTable.removeAliasMapping(source, destinationAddress.asString()); return halt(HttpStatus.NO_CONTENT_204); }
Example 2
Source File: UserQuotaRoutes.java From james-project with Apache License 2.0 | 6 votes |
@PUT @Path("/size") @ApiOperation(value = "Updating per user mail size limitation") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer nor -1."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUpdateQuotaSize() { service.put(SIZE_ENDPOINT, (request, response) -> { Username username = checkUserExist(request); QuotaSizeLimit quotaSize = Quotas.quotaSize(request.body()); userQuotaService.defineMaxSizeQuota(username, quotaSize); return Responses.returnNoContent(response); }); }
Example 3
Source File: UserQuotaRoutes.java From james-project with Apache License 2.0 | 6 votes |
@POST @ApiOperation(value = "Recomputing current quotas of users") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "task", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?task=RecomputeCurrentQuotas", value = "Compulsory. Only supported value is `RecomputeCurrentQuotas`") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message") }) public Optional<Route> definePostUsersQuota() { return TaskFromRequestRegistry.builder() .parameterName(TASK_PARAMETER) .registrations(usersQuotasTaskRegistration) .buildAsRouteOptional(taskManager); }
Example 4
Source File: UserMailboxesRoutes.java From james-project with Apache License 2.0 | 6 votes |
@POST @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"), @ApiImplicitParam( required = true, name = "task", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?task=reIndex", value = "Compulsory. Only supported value is `reIndex`") }) @ApiOperation(value = "Perform an action on a user mailbox") @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message") }) public Optional<Route> reIndexMailboxesRoute() { return TaskFromRequestRegistry.builder() .parameterName(TASK_PARAMETER) .registrations(usersMailboxesTaskRegistration) .buildAsRouteOptional(taskManager); }
Example 5
Source File: UserQuotaRoutes.java From james-project with Apache License 2.0 | 6 votes |
@PUT @Path("/count") @ApiOperation(value = "Updating per user mail count limitation") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer nor -1."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The user name does not exist."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUpdateQuotaCount() { service.put(COUNT_ENDPOINT, (request, response) -> { Username username = checkUserExist(request); QuotaCountLimit quotaCount = Quotas.quotaCount(request.body()); userQuotaService.defineMaxCountQuota(username, quotaCount); return Responses.returnNoContent(response); }); }
Example 6
Source File: DomainQuotaRoutes.java From james-project with Apache License 2.0 | 6 votes |
@PUT @Path("/count") @ApiOperation(value = "Updating per domain mail count limitation") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The requested domain can not be found."), @ApiResponse(code = HttpStatus.METHOD_NOT_ALLOWED_405, message = "Domain Quota configuration not supported when virtual hosting is desactivated."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUpdateQuotaCount() { service.put(COUNT_ENDPOINT, (request, response) -> { Domain domain = checkDomainExist(request); QuotaCountLimit quotaCount = Quotas.quotaCount(request.body()); domainQuotaService.setMaxCountQuota(domain, quotaCount); return Responses.returnNoContent(response); }); }
Example 7
Source File: GlobalQuotaRoutes.java From james-project with Apache License 2.0 | 6 votes |
@PUT @Path("/size") @ApiOperation(value = "Updating per quotaroot mail size limitation") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "integer", paramType = "body") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUpdateQuotaSize() { service.put(SIZE_ENDPOINT, (request, response) -> { QuotaSizeLimit quotaSize = Quotas.quotaSize(request.body()); globalQuotaService.defineMaxSizeQuota(quotaSize); return Responses.returnNoContent(response); }); }
Example 8
Source File: MessagesRoutes.java From james-project with Apache License 2.0 | 6 votes |
@POST @Path("/") @ApiOperation(value = "Operation on messages") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "task", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?task=SolveInconsistencies", value = "Compulsory. Depends on the tasks handled by the product") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message") }) private Optional<Route> allMessagesOperations() { return TaskFromRequestRegistry.builder() .parameterName(TASK_PARAMETER) .registrations(allMessagesTaskRegistration) .buildAsRouteOptional(taskManager); }
Example 9
Source File: MailQueueRoutes.java From james-project with Apache License 2.0 | 6 votes |
@GET @Path("/{mailQueueName}") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = "mailQueueName", paramType = "path") }) @ApiOperation( value = "Get a MailQueue details" ) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = MailQueueDTO.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid request for getting the mail queue."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The MailQueue does not exist."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void getMailQueue(Service service) { service.get(BASE_URL + SEPARATOR + MAIL_QUEUE_NAME, (request, response) -> getMailQueue(request), jsonTransformer); }
Example 10
Source File: UserRoutes.java From james-project with Apache License 2.0 | 6 votes |
@HEAD @Path("/{username}") @ApiOperation(value = "Testing an user existence") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK. User exists."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid input user."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "User does not exist."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUserExist() { service.head(USERS + SEPARATOR + USER_NAME, this::userExist); }
Example 11
Source File: UserRoutes.java From james-project with Apache License 2.0 | 5 votes |
@DELETE @Path("/{username}") @ApiOperation(value = "Deleting an user") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. User is removed."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid input user."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineDeleteUser() { service.delete(USERS + SEPARATOR + USER_NAME, this::removeUser); }
Example 12
Source File: AliasRoutes.java From james-project with Apache License 2.0 | 5 votes |
@PUT @Path(ROOT_PATH + "/{" + ALIAS_DESTINATION_ADDRESS + "}/sources/{" + ALIAS_SOURCE_ADDRESS + "}") @ApiOperation(value = "adding a source address into an alias") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = ALIAS_DESTINATION_ADDRESS, paramType = "path", value = "Destination mail address of the alias. Sending a mail to the alias source address will send it to " + "that email address.\n" + MAILADDRESS_ASCII_DISCLAIMER), @ApiImplicitParam(required = true, dataType = "string", name = ALIAS_SOURCE_ADDRESS, paramType = "path", value = "Source mail address of the alias. Sending a mail to that address will send it to " + "the email destination address.\n" + MAILADDRESS_ASCII_DISCLAIMER) }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = ALIAS_DESTINATION_ADDRESS + " or alias structure format is not valid"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The alias source exists as an user already"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Source and destination can't be the same!"), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Domain in the destination or source is not managed by the DomainList"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public HaltException addAlias(Request request, Response response) throws UsersRepositoryException, RecipientRewriteTableException, DomainListException { MailAddress aliasSourceAddress = MailAddressParser.parseMailAddress(request.params(ALIAS_SOURCE_ADDRESS), ADDRESS_TYPE); ensureUserDoesNotExist(aliasSourceAddress); MailAddress destinationAddress = MailAddressParser.parseMailAddress(request.params(ALIAS_DESTINATION_ADDRESS), ADDRESS_TYPE); ensureDomainIsSupported(destinationAddress.getDomain()); MappingSource source = MappingSource.fromUser(Username.fromMailAddress(aliasSourceAddress)); addAlias(source, destinationAddress); return halt(HttpStatus.NO_CONTENT_204); }
Example 13
Source File: DomainQuotaRoutes.java From james-project with Apache License 2.0 | 5 votes |
@PUT @ApiOperation(value = "Updating count and size at the same time") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataTypeClass = QuotaDTO.class, paramType = "body") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "OK. The value has been updated."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The body is not a positive integer or not unlimited value (-1)."), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The requested domain can not be found."), @ApiResponse(code = HttpStatus.METHOD_NOT_ALLOWED_405, message = "Domain Quota configuration not supported when virtual hosting is desactivated."), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineUpdateQuota() { service.put(QUOTA_ENDPOINT, ((request, response) -> { try { Domain domain = checkDomainExist(request); QuotaDTO quotaDTO = jsonExtractor.parse(request.body()); ValidatedQuotaDTO validatedQuotaDTO = quotaDTOValidator.validatedQuotaDTO(quotaDTO); domainQuotaService.defineQuota(domain, validatedQuotaDTO); return Responses.returnNoContent(response); } catch (IllegalArgumentException e) { throw ErrorResponder.builder() .statusCode(HttpStatus.BAD_REQUEST_400) .type(ErrorType.INVALID_ARGUMENT) .message("Quota should be positive or unlimited (-1)") .cause(e) .haltError(); } })); }
Example 14
Source File: DLPConfigurationRoutes.java From james-project with Apache License 2.0 | 5 votes |
@GET @Path("/{senderDomain}") @ApiOperation(value = "Return a DLP configuration for a given senderDomain") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = "senderDomain", paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK. DLP configuration is returned", response = DLPConfigurationDTO.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid senderDomain in request", response = ErrorResponder.ErrorDetail.class), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The domain does not exist.", response = ErrorResponder.ErrorDetail.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.", response = ErrorResponder.ErrorDetail.class) }) public void defineList(Service service) { service.get(SPECIFIC_DLP_RULE_DOMAIN, (request, response) -> { Domain senderDomain = parseDomain(request); DLPRules dlpConfigurations = Mono.from(dlpConfigurationStore.list(senderDomain)).block(); DLPConfigurationDTO dto = DLPConfigurationDTO.toDTO(dlpConfigurations); response.status(HttpStatus.OK_200); response.header(CONTENT_TYPE, JSON_CONTENT_TYPE); return dto; }, jsonTransformer); }
Example 15
Source File: MailRepositoriesRoutes.java From james-project with Apache License 2.0 | 5 votes |
@PATCH @Path("/{encodedPath}/mails") @ApiOperation(value = "Reprocessing all mails in that mailRepository") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "action", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?action=reprocess", value = "Compulsory. Only supported value is `reprocess`"), @ApiImplicitParam( required = false, name = "queue", paramType = "query parameter", dataType = "String", defaultValue = "spool", example = "?queue=outgoing", value = "Indicates in which queue the mails stored in the repository should be re-enqueued"), @ApiImplicitParam( required = false, paramType = "query parameter", name = "processor", dataType = "String", defaultValue = "absent", example = "?processor=transport", value = "If present, modifies the state property of the mail to allow their processing by a specific mail container processor.") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - unknown action") }) public void defineReprocessAll() { service.patch(MAIL_REPOSITORIES + "/:encodedPath/mails", TaskFromRequestRegistry.of(REPROCESS_ACTION, this::reprocessAll) .asRoute(taskManager), jsonTransformer); }
Example 16
Source File: MessagesRoutes.java From james-project with Apache License 2.0 | 5 votes |
@POST @Path("/{messageId}") @ApiOperation(value = "Re-indexes one email in the different mailboxes containing it") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "task", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?task=reIndex", value = "Compulsory. Only supported value is `reIndex`"), @ApiImplicitParam( required = true, name = "messageId", paramType = "path parameter", dataType = "String", defaultValue = "none", value = "Compulsory. Needs to be a valid messageId (format depends on the mailbox implementation)") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message") }) private Route reIndexMessage() { return TaskFromRequestRegistry.builder() .parameterName(TASK_PARAMETER) .register(MailboxesRoutes.RE_INDEX, request -> reIndexer.reIndex(extractMessageId(request))) .buildAsRoute(taskManager); }
Example 17
Source File: MailboxesRoutes.java From james-project with Apache License 2.0 | 4 votes |
@POST @Path("/") @ApiOperation(value = "Re-indexes all the mails on this server") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "task", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?task=reIndex", value = "Compulsory. Only supported value is `reIndex`"), @ApiImplicitParam( required = false, name = "messagesPerSecond", paramType = "query parameter", dataType = "Integer", defaultValue = "none", example = "?messagesPerSecond=100", value = "If present, determine the number of messages being processed in one second."), @ApiImplicitParam( name = "reIndexFailedMessagesOf", paramType = "query parameter", dataType = "String", defaultValue = "none", example = "?reIndexFailedMessagesOf=3294a976-ce63-491e-bd52-1b6f465ed7a2", value = "optional. References a previously run reIndexing task. if present, the messages that this previous " + "task failed to index will be reIndexed.") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message") }) private static Task reIndexAll(PreviousReIndexingService previousReIndexingService, ReIndexer reIndexer, Request request) throws MailboxException { boolean indexingCorrection = !Strings.isNullOrEmpty(request.queryParams(RE_INDEX_FAILED_MESSAGES_QUERY_PARAM)); if (indexingCorrection) { IndexingDetailInformation indexingDetailInformation = retrieveIndexingExecutionDetails(previousReIndexingService, request); return reIndexer.reIndex(indexingDetailInformation.failures(), ReindexingRunningOptionsParser.parse(request)); } return reIndexer.reIndex(ReindexingRunningOptionsParser.parse(request)); }
Example 18
Source File: EventDeadLettersRoutes.java From james-project with Apache License 2.0 | 4 votes |
@POST @Path("/groups/" + GROUP_PARAM + "/" + INSERTION_ID_PARAMETER) @ApiOperation(value = "Performing action on an event") @ApiImplicitParams({ @ApiImplicitParam( required = true, name = "group", paramType = "path parameter", dataType = "String", defaultValue = "none", value = "Compulsory. Needs to be a valid group name"), @ApiImplicitParam( required = true, name = "insertionId", paramType = "path parameter", dataType = "String", defaultValue = "none", value = "Compulsory. Needs to be a valid insertionId"), @ApiImplicitParam( required = true, dataType = "String", name = "action", paramType = "query", example = "?action=reDeliver", value = "Specify the action to perform on an unique event. 'reDeliver' is supported as an action, " + "and its purpose is to attempt a redelivery of the specified event."), }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.CREATED_201, message = "The taskId of the given scheduled task", response = TaskIdDto.class, responseHeaders = { @ResponseHeader(name = "Location", description = "URL of the resource associated with the scheduled task") }), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid group name, insertion id or action argument"), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "No event with this insertionId"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = INTERNAL_SERVER_ERROR) }) public Route performActionOnSingleEvent() { return TaskFromRequestRegistry.of(RE_DELIVER, request -> eventDeadLettersService.redeliverSingleEvent(parseGroup(request), parseInsertionId(request))) .asRoute(taskManager); }
Example 19
Source File: UserQuotaRoutes.java From james-project with Apache License 2.0 | 4 votes |
@GET @ApiOperation( value = "Reading count and size at the same time", notes = "If there is no limitation for count and/or size, the returned value will be -1" ) @ApiImplicitParams({ @ApiImplicitParam( required = false, name = "minOccuptationRatio", paramType = "query parameter", dataType = "Double", example = "?minOccuptationRatio=0.8", value = "If present, filter the users with occupation ratio lesser than this value."), @ApiImplicitParam( required = false, name = "maxOccupationRatio", paramType = "query parameter", dataType = "Double", example = "?maxOccupationRatio=0.99", value = "If present, filter the users with occupation ratio greater than this value."), @ApiImplicitParam( required = false, paramType = "query parameter", name = "limit", dataType = "Integer", example = "?limit=100", value = "If present, fixes the maximal number of key returned in that call. Must be more than zero if specified."), @ApiImplicitParam( required = false, name = "offset", paramType = "query parameter", dataType = "Integer", example = "?offset=100", value = "If present, skips the given number of key in the output."), @ApiImplicitParam( required = false, name = "domain", paramType = "query parameter", dataType = "String", example = "?domain=james.org", value = "If present, filter the users by this domain.") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = QuotaDetailsDTO.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Validation issues with parameters"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public void defineGetUsersQuota() { service.get(USERS_QUOTA_ENDPOINT, (request, response) -> { QuotaQuery quotaQuery = QuotaQuery.builder() .lessThan(extractQuotaBoundary(request, MAX_OCCUPATION_RATIO)) .moreThan(extractQuotaBoundary(request, MIN_OCCUPATION_RATIO)) .hasDomain(extractDomain(request, DOMAIN)) .withLimit(extractLimit(request)) .withOffset(extractOffset(request)) .build(); return userQuotaService.getUsersQuota(quotaQuery); }, jsonTransformer); }
Example 20
Source File: OAuthConnector.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
private AccessTokenResponse doRequest(final String grantType, HttpClient httpClient, final Request request, Fields fields) throws OAuthResponseException, OAuthException, IOException { int statusCode = 0; String content = ""; try { final FormContentProvider entity = new FormContentProvider(fields); final ContentResponse response = AccessController .doPrivileged((PrivilegedExceptionAction<ContentResponse>) () -> { Request requestWithContent = request.content(entity); return requestWithContent.send(); }); statusCode = response.getStatus(); content = response.getContentAsString(); if (statusCode == HttpStatus.OK_200) { AccessTokenResponse jsonResponse = gson.fromJson(content, AccessTokenResponse.class); jsonResponse.setCreatedOn(LocalDateTime.now()); // this is not supplied by the response logger.debug("grant type {} to URL {} success", grantType, request.getURI()); return jsonResponse; } else if (statusCode == HttpStatus.BAD_REQUEST_400) { OAuthResponseException errorResponse = gson.fromJson(content, OAuthResponseException.class); logger.error("grant type {} to URL {} failed with error code {}, description {}", grantType, request.getURI(), errorResponse.getError(), errorResponse.getErrorDescription()); throw errorResponse; } else { logger.error("grant type {} to URL {} failed with HTTP response code {}", grantType, request.getURI(), statusCode); throw new OAuthException("Bad http response, http code " + statusCode); } } catch (PrivilegedActionException pae) { Exception underlyingException = pae.getException(); if (underlyingException instanceof InterruptedException || underlyingException instanceof TimeoutException || underlyingException instanceof ExecutionException) { throw new IOException("Exception in oauth communication, grant type " + grantType, underlyingException); } // Dont know what exception it is, wrap it up and throw it out throw new OAuthException("Exception in oauth communication, grant type " + grantType, underlyingException); } catch (JsonSyntaxException e) { throw new OAuthException(String.format( "Unable to deserialize json into AccessTokenResponse/ OAuthResponseException. httpCode: %i json: %s", statusCode, content), e); } }