Java Code Examples for io.gravitee.common.http.MediaType#APPLICATION_JSON
The following examples show how to use
io.gravitee.common.http.MediaType#APPLICATION_JSON .
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: ExtensionGrantPluginResource.java From graviteeio-access-management with Apache License 2.0 | 6 votes |
@GET @Path("schema") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Get an extension grant plugin's schema", notes = "There is no particular permission needed. User must be authenticated.") public void getSchema(@PathParam("extensionGrant") String extensionGrantId, @Suspended final AsyncResponse response) { // Check that the extension grant exists extensionGrantPluginService.findById(extensionGrantId) .switchIfEmpty(Maybe.error(new ExtensionGrantPluginNotFoundException(extensionGrantId))) .flatMap(irrelevant -> extensionGrantPluginService.getSchema(extensionGrantId)) .switchIfEmpty(Maybe.error(new ExtensionGrantPluginSchemaNotFoundException(extensionGrantId))) .map(extensionGrantPluginSchema -> Response.ok(extensionGrantPluginSchema).build()) .subscribe(response::resume, response::resume); }
Example 2
Source File: EnvironmentResource.java From gravitee-management-rest-api with Apache License 2.0 | 6 votes |
/** * Create a new Environment. * @param environmentEntity * @return */ @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Create an Environment", tags = {"Environment"}) @ApiResponses({ @ApiResponse(code = 201, message = "Environment successfully created"), @ApiResponse(code = 500, message = "Internal server error")}) public Response createEnvironment( @ApiParam(name = "environmentId", required = true) @PathParam("envId") String environmentId, @ApiParam(name = "environmentEntity", required = true) @Valid @NotNull final UpdateEnvironmentEntity environmentEntity) { environmentEntity.setId(environmentId); return Response .status(Status.CREATED) .entity(environmentService.createOrUpdate(environmentEntity)) .build(); }
Example 3
Source File: ApiQualityRulesResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Permissions({ @Permission(value = RolePermission.API_QUALITY_RULE, acls = RolePermissionAction.CREATE) }) public ApiQualityRuleEntity create(@PathParam("api") String api, @Valid @NotNull final NewApiQualityRuleEntity apiQualityRuleEntity) { apiQualityRuleEntity.setApi(api); return apiQualityRuleService.create(apiQualityRuleEntity); }
Example 4
Source File: ThemeResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) public Response getPortalTheme() { ThemeEntity theme = themeService.findEnabled(); if (theme.getId() != null) { String themeURL = PortalApiLinkHelper.themeURL(uriInfo.getBaseUriBuilder(), theme.getId()); return Response.ok(themeMapper.convert(theme, themeURL)).build(); } return Response.ok().build(); }
Example 5
Source File: TopApisResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@Path("{topAPI}") @DELETE @Consumes(MediaType.APPLICATION_JSON) @Permissions({ @Permission(value = RolePermission.ENVIRONMENT_TOP_APIS, acls = RolePermissionAction.DELETE) }) public void delete(@PathParam("topAPI") String topAPI) { topApiService.delete(topAPI); }
Example 6
Source File: CategoriesResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Permissions({ @Permission(value = RolePermission.ENVIRONMENT_CATEGORY, acls = RolePermissionAction.UPDATE) }) public List<CategoryEntity> update(@Valid @NotNull final List<UpdateCategoryEntity> categories) { return categoryService.update(categories); }
Example 7
Source File: NotifiersResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "List notifiers") @Permissions({ @Permission(value = RolePermission.ENVIRONMENT_API, acls = RolePermissionAction.READ) }) public Collection<NotifierListItem> listNotifiers(@QueryParam("expand") List<String> expand) { Stream<NotifierListItem> stream = notifierService.findAll().stream().map(this::convert); if(expand!=null && !expand.isEmpty()) { for (String s : expand) { switch (s) { case "schema": stream = stream.map(item -> { item.setSchema(notifierService.getSchema(item.getId())); return item; }); break; default: break; } } } return stream .sorted(Comparator.comparing(NotifierListItem::getName)) .collect(Collectors.toList()); }
Example 8
Source File: PortalPagesResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Create a page", notes = "User must be ADMIN to use this service") @ApiResponses({ @ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({ @Permission(value = RolePermission.ENVIRONMENT_DOCUMENTATION, acls = RolePermissionAction.CREATE) }) public Response createPage( @ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) { if(newPageEntity.getType().equals(PageType.SYSTEM_FOLDER)) { throw new PageSystemFolderActionException("Create"); } int order = pageService.findMaxPortalPageOrder() + 1; newPageEntity.setOrder(order); newPageEntity.setLastContributor(getAuthenticatedUser()); PageEntity newPage = pageService.createPage(newPageEntity); if (newPage != null) { return Response .created(URI.create("/portal/pages/" + newPage.getId())) .entity(newPage) .build(); } return Response.serverError().build(); }
Example 9
Source File: SubscriptionResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@POST @Path("/_close") @Produces(MediaType.APPLICATION_JSON) public Response closeSubscription(@PathParam("subscriptionId") String subscriptionId) { SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscriptionId); if(hasPermission(RolePermission.APPLICATION_SUBSCRIPTION, subscriptionEntity.getApplication(), RolePermissionAction.DELETE)) { subscriptionService.close(subscriptionId); return Response .noContent() .build(); } throw new ForbiddenAccessException(); }
Example 10
Source File: TagsResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) public List<TagEntity> list() { return tagService.findAll() .stream() .sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())) .collect(Collectors.toList()); }
Example 11
Source File: ApiPageResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) public Response getPageByApiIdAndPageId( @HeaderParam("Accept-Language") String acceptLang, @PathParam("apiId") String apiId, @PathParam("pageId") String pageId, @QueryParam("include") List<String> include) { Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull()); if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) { final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang); final ApiEntity apiEntity = apiService.findById(apiId); PageEntity pageEntity = pageService.findById(pageId, acceptedLocale); pageService.transformSwagger(pageEntity, apiId); if (isDisplayable(apiEntity, pageEntity.getExcludedGroups(), pageEntity.getType())) { if (!isAuthenticated() && pageEntity.getMetadata() != null) { pageEntity.getMetadata().clear(); } Page page = pageMapper.convert(pageEntity); if (include.contains(INCLUDE_CONTENT)) { page.setContent(pageEntity.getContent()); } page.setLinks(pageMapper.computePageLinks( PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, pageId), PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, page.getParent()) )); return Response.ok(page).build(); } else { throw new UnauthorizedAccessException(); } } throw new ApiNotFoundException(apiId); }
Example 12
Source File: ApplicationResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Get an application", notes = "User must have the READ permission to use this service") @ApiResponses({ @ApiResponse(code = 200, message = "Application", response = ApplicationEntity.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) }) public ApplicationEntity getApplication(@PathParam("application") String application) { return applicationService.findById(application); }
Example 13
Source File: ApiNotificationSettingsResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@DELETE @Path("{notificationId}") @ApiOperation(value = "Delete notification settings") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Permissions({ @Permission(value = API_NOTIFICATION, acls = DELETE) }) public Response delete( @PathParam("api") String api, @PathParam("notificationId") String notificationId) { genericNotificationConfigService.delete(notificationId); return Response.noContent().build(); }
Example 14
Source File: ApiHealthResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Path("logs/{log}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Health-check log") @ApiResponses({ @ApiResponse(code = 200, message = "Single health-check log"), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({@Permission(value = RolePermission.API_HEALTH, acls = RolePermissionAction.READ)}) public Log healthcheckLog( @PathParam("api") String api, @PathParam("log") String logId) { return healthCheckService.findLog(logId); }
Example 15
Source File: ApplicationSubscriptionsResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@POST @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Subscribe to a plan", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service") @ApiResponses({ @ApiResponse(code = 201, message = "Subscription successfully created", response = Subscription.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.CREATE) }) public Response createSubscription( @PathParam("application") String application, @ApiParam(name = "plan", required = true) @NotNull @QueryParam("plan") String plan, NewSubscriptionEntity newSubscriptionEntity) { // If no request message has been passed, the entity is not created if (newSubscriptionEntity == null) { newSubscriptionEntity = new NewSubscriptionEntity(); } PlanEntity planEntity = planService.findById(plan); if (planEntity.isCommentRequired() && (newSubscriptionEntity.getRequest() == null || newSubscriptionEntity.getRequest().isEmpty())) { return Response.status(Response.Status.BAD_REQUEST) .entity("Plan requires a consumer comment when subscribing") .build(); } newSubscriptionEntity.setApplication(application); newSubscriptionEntity.setPlan(plan); Subscription subscription = convert(subscriptionService.create(newSubscriptionEntity)); return Response .created(URI.create("/applications/" + application + "/subscriptions/" + subscription.getId())) .entity(subscription) .build(); }
Example 16
Source File: ConfigurationResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@GET @Path("/hooks") @ApiOperation("Get the list of available hooks") @Produces(MediaType.APPLICATION_JSON) public Hook[] getHooks() { return Arrays.stream(PortalHook.values()).filter(h -> !h.isHidden()).toArray(Hook[]::new); }
Example 17
Source File: ClientRegistrationProviderResource.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update a client registration provider", notes = "User must have the PORTAL_CLIENT_REGISTRATION_PROVIDER[UPDATE] permission to use this service") @ApiResponses({ @ApiResponse(code = 200, message = "Updated client registration provider", response = ClientRegistrationProviderEntity.class), @ApiResponse(code = 500, message = "Internal server error")}) @Permissions(@Permission(value = RolePermission.ENVIRONMENT_CLIENT_REGISTRATION_PROVIDER, acls = RolePermissionAction.UPDATE)) public ClientRegistrationProviderEntity updateClientRegistrationProvider( @PathParam("clientRegistrationProvider") String clientRegistrationProvider, @ApiParam(name = "clientRegistrationProvider", required = true) @Valid @NotNull final UpdateClientRegistrationProviderEntity updatedClientRegistrationProvider) { return clientRegistrationService.update(clientRegistrationProvider, updatedClientRegistrationProvider); }
Example 18
Source File: HttpUserProvider.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
private Single<HttpResponse<Buffer>> processRequest(TemplateEngine templateEngine, String httpURI, HttpMethod httpMethod, List<HttpHeader> httpHeaders, String httpBody) { // prepare request final String evaluatedHttpURI = templateEngine.getValue(httpURI, String.class); final HttpRequest<Buffer> httpRequest = client.requestAbs(httpMethod, evaluatedHttpURI); // set headers if (httpHeaders != null) { httpHeaders.forEach(header -> { String extValue = templateEngine.getValue(header.getValue(), String.class); httpRequest.putHeader(header.getName(), extValue); }); } // set body Single<HttpResponse<Buffer>> responseHandler; if (httpBody != null && !httpBody.isEmpty()) { String bodyRequest = templateEngine.getValue(httpBody, String.class); if (!httpRequest.headers().contains(HttpHeaders.CONTENT_TYPE)) { httpRequest.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())); responseHandler = httpRequest.rxSendBuffer(Buffer.buffer(bodyRequest)); } else { String contentTypeHeader = httpRequest.headers().get(HttpHeaders.CONTENT_TYPE); switch (contentTypeHeader) { case(MediaType.APPLICATION_JSON): responseHandler = httpRequest.rxSendJsonObject(new JsonObject(bodyRequest)); break; case(MediaType.APPLICATION_FORM_URLENCODED): Map<String, String> queryParameters = format(bodyRequest); MultiMap multiMap = MultiMap.caseInsensitiveMultiMap(); multiMap.setAll(queryParameters); responseHandler = httpRequest.rxSendForm(multiMap); break; default: httpRequest.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())); responseHandler = httpRequest.rxSendBuffer(Buffer.buffer(bodyRequest)); } } } else { responseHandler = httpRequest.rxSend(); } return responseHandler; }
Example 19
Source File: ApplicationsResource.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE), }) public Response createApplication(@Valid @NotNull(message = "Input must not be null.") ApplicationInput applicationInput) { NewApplicationEntity newApplicationEntity = new NewApplicationEntity(); newApplicationEntity.setDescription(applicationInput.getDescription()); newApplicationEntity.setGroups(applicationInput.getGroups() != null ? new HashSet<>(applicationInput.getGroups()) : new HashSet<>()); newApplicationEntity.setName(applicationInput.getName()); newApplicationEntity.setPicture(applicationInput.getPicture()); final io.gravitee.rest.api.portal.rest.model.ApplicationSettings settings = applicationInput.getSettings(); ApplicationSettings newApplicationEntitySettings = new ApplicationSettings(); if (settings == null || (settings.getApp() == null && settings.getOauth() == null)) { newApplicationEntity.setSettings(newApplicationEntitySettings); } else { final io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings simpleAppInput = settings.getApp(); if (simpleAppInput != null) { SimpleApplicationSettings sas = new SimpleApplicationSettings(); sas.setClientId(simpleAppInput.getClientId()); sas.setType(simpleAppInput.getType()); newApplicationEntitySettings.setApp(sas); } final io.gravitee.rest.api.portal.rest.model.OAuthClientSettings oauthAppInput = settings.getOauth(); if (oauthAppInput != null) { OAuthClientSettings ocs = new OAuthClientSettings(); ocs.setApplicationType(oauthAppInput.getApplicationType()); ocs.setGrantTypes(oauthAppInput.getGrantTypes()); ocs.setRedirectUris(oauthAppInput.getRedirectUris()); newApplicationEntitySettings.setoAuthClient(ocs); } } newApplicationEntity.setSettings(newApplicationEntitySettings); ApplicationEntity createdApplicationEntity = applicationService.create(newApplicationEntity, getAuthenticatedUser()); return Response .status(Response.Status.CREATED) .entity(applicationMapper.convert(createdApplicationEntity, uriInfo)) .build(); }
Example 20
Source File: PlatformTicketsResource.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
@POST @Consumes(MediaType.APPLICATION_JSON) public Response create(@Valid @NotNull final NewTicketEntity ticketEntity) { ticketService.create(getAuthenticatedUser(), ticketEntity); return Response.created(URI.create("")).build(); }