Example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

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

Introduction

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

Prototype

HttpStatus INTERNAL_SERVER_ERROR

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

Click Source Link

Document

500 Internal Server Error .

Usage

From source file:fr.olympicinsa.riocognized.exception.MyExceptionHandler.java

@ExceptionHandler(ProcessingError.class)
@ResponseBody/*  www . j av  a2  s .com*/
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorMessage handleProcessingErrorException(NoSuchRequestHandlingMethodException e,
        HttpServletRequest req) {
    return new ErrorMessage("INTERNAL_SERVER_ERROR");
}

From source file:org.kew.rmf.reconciliation.ws.MatchController.java

/**
 * Performs a single match query./*from   ww w .  j  a  v a2 s .  c  o m*/
 */
@RequestMapping(value = "/match/{configName}", method = RequestMethod.GET)
public ResponseEntity<List<Map<String, String>>> doMatch(@PathVariable String configName,
        @RequestParam Map<String, String> requestParams, Model model) {
    logger.info("{}: Match query {}", configName, requestParams);

    // Build a map by looping over each property in the config, reading its value from the
    // request object, and applying any transformations specified in the config
    Map<String, String> userSuppliedRecord = new HashMap<String, String>();
    for (String key : requestParams.keySet()) {
        userSuppliedRecord.put(key, requestParams.get(key));
        if (logger.isTraceEnabled()) {
            logger.trace("Setting: {} to {}", key, requestParams.get(key));
        }
    }

    List<Map<String, String>> matches = null;
    try {
        matches = reconciliationService.doQuery(configName, userSuppliedRecord);
        logger.debug("Found {} matches", matches.size());
        if (matches.size() < 4) {
            logger.debug("Matches for {} are {}", requestParams, matches);
        }
    } catch (TooManyMatchesException | MatchExecutionException e) {
        logger.error(configName + ": Problem handling match", e);
        return new ResponseEntity<List<Map<String, String>>>(HttpStatus.INTERNAL_SERVER_ERROR);
    }

    // TODO: Reporter is needed to cause only configured properties to be returned in the JSON.

    // matches will be returned as JSON
    return new ResponseEntity<List<Map<String, String>>>(matches, HttpStatus.OK);
}

From source file:org.osiam.addons.self_administration.controller.AccountManagementService.java

/**
 * Logs the given exception and returns a suitable response status.
 * //www  .  j ava 2  s  .  c o m
 * @param e
 *            the exception to handle
 * @param {@link ResponseEntity} with the resulting error information and status code
 */
public ResponseEntity<String> handleException(RuntimeException e) {
    StringBuilder messageBuilder = new StringBuilder();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;

    if (e instanceof MailException) {
        messageBuilder.append("Failed to send email: ");
    } else if (e instanceof UnauthorizedException) {
        messageBuilder.append("Authorization failed: ");
        status = HttpStatus.UNAUTHORIZED;
    } else if (e instanceof NoResultException) {
        messageBuilder.append("No such entity: ");
        status = HttpStatus.NOT_FOUND;
    } else {
        messageBuilder.append("An exception occurred: ");
    }
    LOGGER.error(messageBuilder.toString());
    messageBuilder.insert(0, "{\"error\":\"");
    messageBuilder.append(e.getMessage());
    messageBuilder.append("\"}");
    return new ResponseEntity<String>(messageBuilder.toString(), status);
}

From source file:com.mycompany.projetsportmanager.spring.rest.controllers.UserController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8")
public PagedResources<UserResource> collectionList(Pageable pageable, PagedResourcesAssembler<User> assembler,
        @RequestParam(value = "firstName", required = false) String firstName,
        @RequestParam(value = "lastName", required = false) String lastName,
        @RequestParam(value = "mail", required = false) String mail, HttpServletRequest httpServletRequest) {

    Page<User> users = null;//  w  w w . ja  va 2  s.c  om

    try {
        if (firstName != null || lastName != null || mail != null) {

            if (firstName == null)
                firstName = "";
            if (lastName == null)
                lastName = "";
            if (mail == null)
                mail = "";

            users = userRepo.findByLastNameLikeIgnoreCaseAndFirstNameLikeIgnoreCaseAndMailLikeIgnoreCase(
                    "%" + lastName + "%", "%" + firstName + "%", "%" + mail + "%", pageable);
        } else {
            users = userRepo.findAllPaged(pageable);
        }

    } catch (DataAccessException e) {
        String msg = "Can't retrieve asked users from DB";
        logger.error(msg, e);
        throw new DefaultSportManagerException(
                new ErrorResource("db error", msg, HttpStatus.INTERNAL_SERVER_ERROR));
    }

    PagedResources<UserResource> resources = assembler.toResource(users, userResourceAssembler);
    resources.add(linkTo(UserController.class).withSelfRel());
    if (httpServletRequest.isUserInRole("AK_ADMIN")) {
        resources.add(linkTo(UserController.class).withRel(ActionsConstants.CREATE_VIA_POST));
        //On rajoute les liens sur les users
        for (UserResource resource : resources) {
            resource.add(linkTo(methodOn(UserController.class).userGet(resource.getTech_id(), null))
                    .withRel(ActionsConstants.UPDATE_VIA_PUT));
            resource.add(linkTo(methodOn(UserController.class).userGet(resource.getTech_id(), null))
                    .withRel(ActionsConstants.DELETE_VIA_DELETE));
        }
    }
    return resources;
}

From source file:au.com.ors.rest.controller.AutoCheckController.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@ExceptionHandler/*www  . ja v a  2  s .co m*/
ResponseEntity handleExceptions(Exception e) {
    ResponseEntity responseEntity = null;

    // TODO handle exceptions of this controller
    RESTError error = new RESTError();

    error.setErrCode("INVALID_INPUT");
    error.setErrMessage("Your INPUT IS WRONG");
    responseEntity = new ResponseEntity(error, HttpStatus.INTERNAL_SERVER_ERROR);

    return responseEntity;
}

From source file:com.webfileanalyzer.controller.IndexController.java

@RequestMapping(value = "/getFileStat/{id}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getFileStat(@PathVariable("id") long value,
        @RequestParam(value = "from", required = true) String from,
        @RequestParam(value = "qty", required = true) String qty) {
    try {/*from w w  w.  j  av a2 s .co m*/
        Map<String, Object> resp = new HashMap();
        resp.put(FILE_STAT,
                fileStatisticService.getStatisticsByFileId(value, Integer.valueOf(from), Integer.valueOf(qty)));
        return new ResponseEntity<>((Object) resp, HttpStatus.OK);
    } catch (Exception ex) {
        return new ResponseEntity<>((Object) errorViewMap(ex), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.agatom.springatom.webmvc.controllers.SVVinController.java

/**
 * <p>handleVinDecodingException.</p>
 *
 * @param error a {@link org.agatom.springatom.web.exceptions.ControllerTierException} object.
 *
 * @return a {@link org.springframework.http.ResponseEntity} object.
 *//*from  www .java  2 s  .  c o  m*/
@ResponseBody
@ExceptionHandler({ VinDecodingException.class })
public ResponseEntity<?> handleVinDecodingException(final VinDecodingException error) {
    return this.errorResponse(error, HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:net.maritimecloud.identityregistry.controllers.CertificateController.java

@RequestMapping(value = "/api/certificates/ocsp/{encodedOCSP}", method = RequestMethod.GET, produces = "application/ocsp-response")
@ResponseBody/*w ww.  j  a  v  a 2 s .c  om*/
public ResponseEntity<?> getOCSP(@PathVariable String encodedOCSP) {
    byte[] byteResponse;
    try {
        byteResponse = handleOCSP(Base64.decode(encodedOCSP));
    } catch (IOException e) {
        log.error("Failed to get OCSP", e);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return new ResponseEntity<>(byteResponse, HttpStatus.OK);
}

From source file:gateway.controller.AdminController.java

@RequestMapping(value = "/version", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getVersion() {
    try {//from ww  w .j a v  a  2  s  .com
        return new ResponseEntity<String>(restTemplate.getForObject(RELEASE_URL, String.class), HttpStatus.OK);
    } catch (Exception e) {
        String error = String.format("Error retrieving version for Piazza: %s", e.getMessage());
        LOGGER.error(error, e);
        return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Gateway"),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.hp.autonomy.frontend.find.hod.search.FindHodDocumentServiceTest.java

@Test
public void invalidIndexName() throws HodErrorException {
    final ResourceIdentifier goodIndex = testUtils.getDatabases().get(0);
    final ResourceIdentifier badIndex = new ResourceIdentifier("bad", "bad");

    when(cacheManager.getCache(CacheNames.DATABASES)).thenReturn(cache);

    final HodError invalidIndexError = new HodError.Builder().setErrorCode(HodErrorCode.INDEX_NAME_INVALID)
            .build();/*  ww  w .j  a  v  a 2s.c o m*/
    final HodSearchResult result = new HodSearchResult.Builder().setIndex(goodIndex.getName()).build();
    final Documents<HodSearchResult> mockedResults = new Documents<>(Collections.singletonList(result), 1, null,
            null, null, null);
    when(queryTextIndexService.queryTextIndexWithText(anyString(), any(QueryRequestBuilder.class)))
            .thenThrow(new HodErrorException(invalidIndexError, HttpStatus.INTERNAL_SERVER_ERROR.value()))
            .thenReturn(mockedResults);

    final Database goodDatabase = new Database.Builder().setName(goodIndex.getName())
            .setDomain(goodIndex.getDomain()).build();
    when(databasesService.getDatabases(any(HodDatabasesRequest.class)))
            .thenReturn(Collections.singleton(goodDatabase));

    final QueryRestrictions<ResourceIdentifier> queryRestrictions = new HodQueryRestrictions.Builder()
            .setQueryText("*").setDatabases(Arrays.asList(goodIndex, badIndex)).setAnyLanguage(true).build();
    final SearchRequest<ResourceIdentifier> searchRequest = new SearchRequest.Builder<ResourceIdentifier>()
            .setQueryRestrictions(queryRestrictions).setStart(1).setMaxResults(30).setSummary("concept")
            .setSummaryCharacters(250).setSort(null).setHighlight(true).setAutoCorrect(false)
            .setQueryType(SearchRequest.QueryType.MODIFIED).build();
    final Documents<HodSearchResult> results = documentsService.queryTextIndex(searchRequest);
    assertThat(results.getDocuments(), hasSize(1));
    assertNotNull(results.getWarnings());
    assertThat(results.getWarnings().getInvalidDatabases(), hasSize(1));
    assertEquals(badIndex, results.getWarnings().getInvalidDatabases().iterator().next());
    verify(cache).clear();
}