Example usage for org.springframework.http HttpStatus EXPECTATION_FAILED

List of usage examples for org.springframework.http HttpStatus EXPECTATION_FAILED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus EXPECTATION_FAILED.

Prototype

HttpStatus EXPECTATION_FAILED

To view the source code for org.springframework.http HttpStatus EXPECTATION_FAILED.

Click Source Link

Document

417 Expectation Failed .

Usage

From source file:pitayaa.nail.msg.core.license.controller.LicenseController.java

@RequestMapping(value = "licenses/{ID}", method = RequestMethod.DELETE)
public @ResponseBody ResponseEntity<?> deleteLicense(@PathVariable("ID") UUID uid) throws Exception {

    // Find license
    Optional<License> optionalLicense = licenseService.findOne(uid);
    if (!optionalLicense.isPresent()) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/*  w w  w .  j  av  a 2s  .  c o  m*/
    // Delete license
    boolean isDelete = licenseService.deleteLicense(uid);

    // Get status
    HttpStatus status = (isDelete) ? HttpStatus.NO_CONTENT : HttpStatus.EXPECTATION_FAILED;

    // Return
    return new ResponseEntity<>(status);
}

From source file:br.com.uol.runas.controller.JUnitController.java

private ResponseEntity<String> runJUnit(String path, String[] suites) throws Exception {
    final JUnitServiceResponse response = jUnitService.runTests(path, suites);

    HttpStatus status;/*from ww w  . j ava  2  s.co m*/

    if (response.getResult().wasSuccessful() && response.getResult().getIgnoreCount() == 0) {
        status = HttpStatus.OK;
    } else if (response.getResult().getFailureCount() > 0) {
        status = HttpStatus.EXPECTATION_FAILED;
    } else {
        status = HttpStatus.PARTIAL_CONTENT;
    }

    return ResponseEntity.status(status).contentType(response.getMediaType()).body(response.getLog());
}

From source file:br.com.modoagil.asr.rest.support.ResponseBuilder.java

/**
 * Ajusta a mensagem de reposta com a propriedade {@code status}
 *
 * @param status/*from w  w  w  .  jav a  2 s . c o  m*/
 *            {@link HttpStatus}
 * @return {@link Response}
 */
public ResponseBuilder<E> status(final HttpStatus status) {
    ReflectionUtil.setField(this.response, "status",
            status == null ? HttpStatus.EXPECTATION_FAILED.value() : status.value());
    return this;
}

From source file:seava.j4e.web.controller.AbstractBaseController.java

/**
 * Generic exception handler//from  w w  w. ja  v a2 s  . c  o m
 * 
 * @param e
 * @param response
 * @return
 * @throws IOException
 */
@ExceptionHandler(value = Exception.class)
@ResponseBody
protected String handleException(Exception e, HttpServletResponse response) throws IOException {

    e.printStackTrace();

    StringBuffer sb = new StringBuffer(" NOT MANAGED EXCEPTION HANDLER ");
    if (e.getLocalizedMessage() != null) {
        sb.append(e.getLocalizedMessage());
    } else if (e.getCause() != null) {
        if (sb.length() > 0) {
            sb.append(" Reason: ");
        }
        sb.append(e.getCause().getLocalizedMessage());
    }
    if (sb.length() == 0) {
        if (e.getStackTrace() != null) {
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            e.printStackTrace(response.getWriter());
            return null;
        }
    }
    response.setStatus(HttpStatus.EXPECTATION_FAILED.value());
    response.getOutputStream().print(sb.toString());
    response.getOutputStream().flush();
    return null;

}

From source file:net.nan21.dnet.core.web.controller.AbstractDnetController.java

/**
 * Generic exception handler//from  w w w . j  a  v a  2  s .co  m
 * 
 * @param e
 * @param response
 * @return
 * @throws IOException
 */
@ExceptionHandler(value = Exception.class)
@ResponseBody
protected String handleException(Exception e, HttpServletResponse response) throws IOException {

    e.printStackTrace();

    if (e instanceof NotAuthorizedRequestException) {
        return this.handleException((NotAuthorizedRequestException) e, response);
    } else if (e instanceof InvocationTargetException) {
        StringBuffer sb = new StringBuffer();
        if (e.getMessage() != null) {
            sb.append(e.getMessage() + "\n");
        }
        Throwable exc = ((InvocationTargetException) e).getTargetException();

        if (exc.getMessage() != null) {
            sb.append(exc.getMessage() + "\n");
        }

        if (exc.getCause() != null) {
            if (sb.length() > 0) {
                sb.append(" Reason: ");
            }
            sb.append(exc.getCause().getLocalizedMessage());
        }

        exc.printStackTrace();
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.getOutputStream().print(sb.toString());
        return null;
    }
    StringBuffer sb = new StringBuffer();
    if (e.getLocalizedMessage() != null) {
        sb.append(e.getLocalizedMessage());
    } else if (e.getCause() != null) {
        if (sb.length() > 0) {
            sb.append(" Reason: ");
        }
        sb.append(e.getCause().getLocalizedMessage());
    }
    if (sb.length() == 0) {
        if (e.getStackTrace() != null) {
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            e.printStackTrace(response.getWriter());
            return null;
        }
    }
    response.setStatus(HttpStatus.EXPECTATION_FAILED.value());
    response.getOutputStream().print(sb.toString());
    response.getOutputStream().flush();
    return null;

}

From source file:org.geoserver.opensearch.rest.CollectionsController.java

private File getSampleGranule(String collection, final String nsURI, int band, final String mosaicName)
        throws IOException {
    // make sure there is at least one granule to grab resolution, sample/color model,
    // and preferred SPI
    SimpleFeatureSource granuleSource = DataUtilities
            .simple(getOpenSearchAccess().getFeatureSource(new NameImpl(nsURI, mosaicName)));
    SimpleFeature firstFeature = DataUtilities.first(granuleSource.getFeatures());
    if (firstFeature == null) {
        throw new RestException(
                "Could not locate any granule for collection '" + collection + "' and band '" + band + "'",
                HttpStatus.EXPECTATION_FAILED);
    }//from w w  w. j  a v  a 2  s.  c  om
    // grab the file
    String location = (String) firstFeature.getAttribute("location");
    File file = new File(location);
    if (!file.exists()) {
        throw new RestException(
                "Sample granule '" + location + "' could not be found on the file system, check your database",
                HttpStatus.EXPECTATION_FAILED);
    }

    return file;
}

From source file:org.kuali.coeus.sys.health.HealthCheckController.java

@RequestMapping("/")
public ResponseEntity<HealthResponse> doHealthCheck() {
    HealthResponse result = new HealthResponse();
    result.version = configurationService.getPropertyValueAsString("version");
    try (Connection conn = dataSource.getConnection(); Connection riceConn = riceDataSource.getConnection()) {
        if (conn.createStatement().executeQuery(kcHealthQuery).next()) {
            result.kcDatabaseUp = true;/*from  w w  w . j av  a2s.  c  o m*/
        }
        if (riceConn.createStatement().executeQuery(riceHealthQuery).next()) {
            result.riceDatabaseUp = true;
        }
    } catch (Exception e) {
        LOG.error("Health Check Failed.", e);
        return new ResponseEntity<>(result, HttpStatus.EXPECTATION_FAILED);
    }
    return new ResponseEntity<>(result, HttpStatus.OK);
}