Search in sources :

Example 56 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project geode by apache.

the class FunctionAccessController method list.

/**
   * list all registered functions in Gemfire data node
   * 
   * @return result as a JSON document.
   */
@RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
@ApiOperation(value = "list all functions", notes = "list all functions available in the GemFire cluster", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK."), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 500, message = "GemFire throws an error or exception.") })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("@securityService.authorize('DATA', 'READ')")
public ResponseEntity<?> list() {
    logger.debug("Listing all registered Functions in GemFire...");
    final Map<String, Function> registeredFunctions = FunctionService.getRegisteredFunctions();
    String listFunctionsAsJson = JSONUtils.formulateJsonForListFunctionsCall(registeredFunctions.keySet());
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(toUri("functions"));
    return new ResponseEntity<>(listFunctionsAsJson, headers, HttpStatus.OK);
}
Also used : Function(org.apache.geode.cache.execute.Function) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 57 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project geode by apache.

the class BaseControllerAdvice method handleException.

/**
   * Handles any Exception thrown by a REST API web service endpoint, HTTP request handler method.
   * <p/>
   * 
   * @param cause the Exception causing the error.
   * @return a ResponseEntity with an appropriate HTTP status code (500 - Internal Server Error) and
   *         HTTP response body containing the stack trace of the Exception.
   */
@ExceptionHandler(Throwable.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(final Throwable cause) {
    final StringWriter stackTraceWriter = new StringWriter();
    cause.printStackTrace(new PrintWriter(stackTraceWriter));
    final String stackTrace = stackTraceWriter.toString();
    if (logger.isDebugEnabled()) {
        logger.debug(stackTrace);
    }
    return convertErrorAsJson(cause.getMessage());
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 58 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project geode by apache.

the class QueryAccessController method runNamedQuery.

/**
   * Run named parametrized Query with ID
   * 
   * @param queryId id of the OQL string
   * @param arguments query bind params required while executing query
   * @return query result as a JSON document
   */
@RequestMapping(method = RequestMethod.POST, value = "/{query}", produces = { MediaType.APPLICATION_JSON_VALUE })
@ApiOperation(value = "run parametrized query", notes = "run the specified named query passing in scalar values for query parameters in the GemFire cluster", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Query successfully executed."), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 400, message = "Query bind params specified as JSON document in the request body is invalid"), @ApiResponse(code = 500, message = "GemFire throws an error or exception") })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("@securityService.authorize('DATA', 'READ')")
public ResponseEntity<String> runNamedQuery(@PathVariable("query") String queryId, @RequestBody String arguments) {
    logger.debug("Running named Query with ID ({})...", queryId);
    queryId = decode(queryId);
    if (arguments != null) {
        // Its a compiled query.
        // Convert arguments into Object[]
        Object[] args = jsonToObjectArray(arguments);
        Query compiledQuery = compiledQueries.get(queryId);
        if (compiledQuery == null) {
            // This is first time the query is seen by this server.
            final String oql = getValue(PARAMETERIZED_QUERIES_REGION, queryId, false);
            ValidationUtils.returnValueThrowOnNull(oql, new ResourceNotFoundException(String.format("No Query with ID (%1$s) was found!", queryId)));
            try {
                compiledQuery = getQueryService().newQuery(oql);
            } catch (QueryInvalidException qie) {
                throw new GemfireRestException("Syntax of the OQL queryString is invalid!", qie);
            }
            compiledQueries.putIfAbsent(queryId, (DefaultQuery) compiledQuery);
        }
        // and handle the Exceptions appropriately (500 Server Error)!
        try {
            Object queryResult = compiledQuery.execute(args);
            return processQueryResponse(compiledQuery, args, queryResult);
        } catch (FunctionDomainException fde) {
            throw new GemfireRestException("A function was applied to a parameter that is improper for that function!", fde);
        } catch (TypeMismatchException tme) {
            throw new GemfireRestException("Bind parameter is not of the expected type!", tme);
        } catch (NameResolutionException nre) {
            throw new GemfireRestException("Name in the query cannot be resolved!", nre);
        } catch (IllegalArgumentException iae) {
            throw new GemfireRestException(" The number of bound parameters does not match the number of placeholders!", iae);
        } catch (IllegalStateException ise) {
            throw new GemfireRestException("Query is not permitted on this type of region!", ise);
        } catch (QueryExecutionTimeoutException qete) {
            throw new GemfireRestException("Query execution time is exceeded  max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured!", qete);
        } catch (QueryInvocationTargetException qite) {
            throw new GemfireRestException("Data referenced in from clause is not available for querying!", qite);
        } catch (QueryExecutionLowMemoryException qelme) {
            throw new GemfireRestException("Query gets canceled due to low memory conditions and the resource manager critical heap percentage has been set!", qelme);
        } catch (Exception e) {
            throw new GemfireRestException("Error encountered while executing named query!", e);
        }
    } else {
        throw new GemfireRestException(" Bind params either not specified or not processed properly by the server!");
    }
}
Also used : Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ResourceNotFoundException(org.apache.geode.rest.internal.web.exception.ResourceNotFoundException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ResourceNotFoundException(org.apache.geode.rest.internal.web.exception.ResourceNotFoundException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 59 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project geode by apache.

the class DurableClientCommandsController method closeDurableContinuousQuery.

@RequestMapping(method = RequestMethod.POST, value = "/durable-clients/{durable-client-id}/cqs/{durable-cq-name}", params = "op=close")
@ResponseBody
public String closeDurableContinuousQuery(@PathVariable(ConfigurationProperties.DURABLE_CLIENT_ID) final String durableClientId, @PathVariable("durable-cq-name") final String durableCqName, @RequestParam(value = CliStrings.CLOSE_DURABLE_CQS__MEMBER, required = false) final String memberNameId, @RequestParam(value = CliStrings.CLOSE_DURABLE_CQS__GROUP, required = false) final String[] groups) {
    final CommandStringBuilder command = new CommandStringBuilder(CliStrings.CLOSE_DURABLE_CQS);
    command.addOption(CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, decode(durableClientId));
    command.addOption(CliStrings.CLOSE_DURABLE_CQS__NAME, decode(durableCqName));
    if (hasValue(memberNameId)) {
        command.addOption(CliStrings.CLOSE_DURABLE_CQS__MEMBER, memberNameId);
    }
    if (hasValue(groups)) {
        command.addOption(CliStrings.CLOSE_DURABLE_CQS__GROUP, StringUtils.join(groups, StringUtils.COMMA_DELIMITER));
    }
    return processCommand(command.toString());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 60 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project geode by apache.

the class DurableClientCommandsController method listDurableClientContinuousQueries.

@RequestMapping(method = RequestMethod.GET, value = "/durable-clients/{durable-client-id}/cqs")
@ResponseBody
public String listDurableClientContinuousQueries(@PathVariable(ConfigurationProperties.DURABLE_CLIENT_ID) final String durableClientId, @RequestParam(value = CliStrings.LIST_DURABLE_CQS__MEMBER, required = false) final String memberNameId, @RequestParam(value = CliStrings.LIST_DURABLE_CQS__GROUP, required = false) final String[] groups) {
    final CommandStringBuilder command = new CommandStringBuilder(CliStrings.LIST_DURABLE_CQS);
    command.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, decode(durableClientId));
    if (hasValue(memberNameId)) {
        command.addOption(CliStrings.LIST_DURABLE_CQS__MEMBER, memberNameId);
    }
    if (hasValue(groups)) {
        command.addOption(CliStrings.LIST_DURABLE_CQS__GROUP, StringUtils.join(groups, StringUtils.COMMA_DELIMITER));
    }
    return processCommand(command.toString());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1991 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1700 HashMap (java.util.HashMap)458 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)212 IOException (java.io.IOException)207 JSONObject (com.alibaba.fastjson.JSONObject)200 Map (java.util.Map)172 ApiOperation (io.swagger.annotations.ApiOperation)170 ArrayList (java.util.ArrayList)169 GetMapping (org.springframework.web.bind.annotation.GetMapping)112 ResponseEntity (org.springframework.http.ResponseEntity)102 ApiRest (build.dream.common.api.ApiRest)101 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)101 AuthPassport (com.ngtesting.platform.util.AuthPassport)99 PostMapping (org.springframework.web.bind.annotation.PostMapping)94 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)87 Date (java.util.Date)81 UserVo (com.ngtesting.platform.vo.UserVo)78 LogDetail (com.bc.pmpheep.annotation.LogDetail)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)65