Search in sources :

Example 76 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project cas by apereo.

the class StatusController method handleRequestInternal.

/**
 * Handle request.
 *
 * @param request  the request
 * @param response the response
 * @throws Exception the exception
 */
@GetMapping
@ResponseBody
protected void handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    ensureEndpointAccessIsAuthorized(request, response);
    final StringBuilder sb = new StringBuilder();
    final Health health = this.healthEndpoint.invoke();
    final Status status = health.getStatus();
    if (status.equals(Status.DOWN) || status.equals(Status.OUT_OF_SERVICE)) {
        response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
    }
    sb.append("Health: ").append(status.getCode());
    sb.append("\n\nHost:\t\t").append(StringUtils.isBlank(casProperties.getHost().getName()) ? InetAddressUtils.getCasServerHostName() : casProperties.getHost().getName());
    sb.append("\nServer:\t\t").append(casProperties.getServer().getName());
    sb.append("\nVersion:\t").append(CasVersion.getVersion());
    response.setContentType(MediaType.TEXT_PLAIN_VALUE);
    try (Writer writer = response.getWriter()) {
        IOUtils.copy(new ByteArrayInputStream(sb.toString().getBytes(response.getCharacterEncoding())), writer, StandardCharsets.UTF_8);
        writer.flush();
    }
}
Also used : Status(org.springframework.boot.actuate.health.Status) HttpStatus(org.springframework.http.HttpStatus) Health(org.springframework.boot.actuate.health.Health) ByteArrayInputStream(java.io.ByteArrayInputStream) Writer(java.io.Writer) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 77 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project cas by apereo.

the class TrustedDevicesController method getRecords.

/**
 * Gets records.
 *
 * @param request  the request
 * @param response the response
 * @return the records
 */
@GetMapping(value = "/getRecords")
@ResponseBody
public Set<MultifactorAuthenticationTrustRecord> getRecords(final HttpServletRequest request, final HttpServletResponse response) {
    ensureEndpointAccessIsAuthorized(request, response);
    final TrustedDevicesMultifactorProperties trusted = casProperties.getAuthn().getMfa().getTrusted();
    final LocalDate onOrAfter = LocalDate.now().minus(trusted.getExpiration(), DateTimeUtils.toChronoUnit(trusted.getTimeUnit()));
    this.mfaTrustEngine.expire(onOrAfter);
    return this.mfaTrustEngine.get(onOrAfter);
}
Also used : TrustedDevicesMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.TrustedDevicesMultifactorProperties) LocalDate(java.time.LocalDate) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 78 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleMethodResultValidationException.

@ExceptionHandler(MethodResultValidationException.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleMethodResultValidationException(MethodResultValidationException e) {
    log.error("MethodResultValidationException in service", e);
    ErrorInfo errorInfo = new ErrorInfo("Server error", "");
    return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 79 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleValidationException.

@ExceptionHandler(ValidationException.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleValidationException(ValidationException e) {
    log.error("ValidationException in service", e);
    ErrorInfo errorInfo = new ErrorInfo("Server error", "");
    return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 80 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project production_ssm by megagao.

the class PMeasureCheckController method deleteBatch.

@RequestMapping(value = "/delete_batch")
@ResponseBody
private CustomResult deleteBatch(String[] ids) throws Exception {
    System.out.println(ids);
    CustomResult result = pMeasureCheckService.deleteBatch(ids);
    return result;
}
Also used : CustomResult(com.megagao.production.ssm.domain.customize.CustomResult) 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