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:io.onedecision.engine.OneDecisionExceptionHandler.java

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(DecisionException.class)
public void handleInternalServerError(Exception e) {
    LOGGER.error(e.getMessage(), e);//from  w w  w .  j  a  va2  s  . c  om
}

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

@RequestMapping(value = "/getFiles", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<Object> getFiles(@RequestParam(value = "from", required = true) String from,
        @RequestParam(value = "qty", required = true) String qty,
        @RequestParam(value = "moreThen", required = false) String moreThen) {
    try {// w  w w .j  av a2 s.com
        Map<String, Object> resp = new HashMap();
        resp.put(FILES,
                moreThen != null
                        ? filesService.getFilesLineMoreThen(Long.valueOf(moreThen), Integer.valueOf(from),
                                Integer.valueOf(qty))
                        : filesService.getAll(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:io.kahu.hawaii.util.exception.HawaiiExceptionTest.java

@Test
public void testGetStatus() throws Exception {

    ServerException e = new ServerException(TestServerError.S1);
    Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.equals(e.getStatus()));

    AuthenticationException auth = new AuthenticationException();
    Assert.assertTrue(HttpStatus.FORBIDDEN.equals(auth.getStatus()));

    AuthorisationException autho = new AuthorisationException();
    Assert.assertTrue(HttpStatus.UNAUTHORIZED.equals(autho.getStatus()));

    ValidationException v = new ValidationException();
    Assert.assertTrue(HttpStatus.BAD_REQUEST.equals(v.getStatus()));
}

From source file:com.javafxpert.wikibrowser.WikiLangLinksController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> locatorEndpoint(@RequestParam(value = "title") String articleTitle,
        @RequestParam(value = "lang") String lang) {

    String language = wikiBrowserProperties.computeLang(lang);

    LangLinksResponseNear langLinksResponseNear = null;
    if (!articleTitle.equals("")) {
        langLinksResponseNear = retrieveLangLinks(articleTitle, language);
    }//from w w  w. j  a v  a  2  s .  c o  m

    return Optional.ofNullable(langLinksResponseNear)
            .map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Wikipedia query unsuccessful", HttpStatus.INTERNAL_SERVER_ERROR));
}

From source file:com.sms.server.controller.UserController.java

@RequestMapping(value = "/{username}", method = RequestMethod.PUT, headers = {
        "Content-type=application/json" })
@ResponseBody/*  w  ww. j ava 2  s.co  m*/
public ResponseEntity<String> updateUser(@RequestBody User update, @PathVariable("username") String username) {
    User user = userDao.getUserByUsername(username);

    if (user == null) {
        return new ResponseEntity<String>("Username does not exist.", HttpStatus.BAD_REQUEST);
    }

    if (username.equals("admin")) {
        return new ResponseEntity<String>("You are not authenticated to perform this operation.",
                HttpStatus.FORBIDDEN);
    }

    // Update user details
    if (update.getUsername() != null) {
        // Check username is available
        if (userDao.getUserByUsername(user.getUsername()) != null) {
            return new ResponseEntity<String>("Username already exists.", HttpStatus.NOT_ACCEPTABLE);
        } else {
            user.setUsername(update.getUsername());
        }
    }

    if (update.getPassword() != null) {
        user.setPassword(update.getPassword());
    }

    if (update.getEnabled() != null) {
        user.setEnabled(update.getEnabled());
    }

    // Update database
    if (!userDao.updateUser(user, username)) {
        LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME,
                "Error updating user '" + user.getUsername() + "'.", null);
        return new ResponseEntity<String>("Error updating user details.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(LogService.Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' updated successfully.", null);
    return new ResponseEntity<String>("User details updated successfully.", HttpStatus.ACCEPTED);
}

From source file:org.frat.common.security.authc.SessionTimeoutAuthenticationFilter.java

@Override
protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response)
        throws IOException {
    saveRequest(request);/*from   www.j av  a 2s  . c o m*/
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    if (WebUtil.isAjaxRequest(req)) {
        ObjectMapper objectMapper = new ObjectMapper();
        res.setContentType("application/json;charset=UTF-8");
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        ResultDto error = new ResultDto();
        error.setCode(ResultCode.SESSION_TIME_OUT);
        error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG));
        objectMapper.writeValue(response.getWriter(), error);
        LOGGER.debug("session time out for ajax request:{}", req.getRequestURI());
    } else {
        LOGGER.debug("session time out for request:{}", req.getRequestURI());
        req.getSession().setAttribute(SESSION_TIMEOUT, true);
        redirectToLogin(request, response);
    }
    HttpSession session = req.getSession(false);
    if (session != null) {
        LOGGER.debug(
                "session time out with id:"
                        + " {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}",
                session.getId(), session.isNew(),
                DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT),
                DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request));
    } else {
        LOGGER.debug("session time out, no session available for current request");
    }
}

From source file:org.jbr.taskmgr.web.controller.GlobalExceptionHandler.java

/**
 * Converts a general, unmapped exception into an HTTP 500 response with an
 * error body./*  w  w w . j a  v a2  s.  c o  m*/
 * 
 * @param e
 *            the general exception
 * @return the error body
 */
@ExceptionHandler(Exception.class)
@RestEndpoint
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ResponseEntity<GenericMessage> handleGeneralException(final Exception e) {
    return createResponseEntity("Unexpected server-side error occurred!", e, HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:cn.powerdash.libsystem.common.security.authc.SessionTimeoutAuthenticationFilter.java

@Override
protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response)
        throws IOException {
    saveRequest(request);//from w  w w. j a va  2s  .co m
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    if (WebUtil.isAjaxRequest(req)) {
        ObjectMapper objectMapper = new ObjectMapper();
        res.setContentType("application/json;charset=UTF-8");
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        ResultDto<String> error = new ResultDto<String>();
        error.setCode(ResultCode.SESSION_TIME_OUT);
        error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG));
        objectMapper.writeValue(response.getWriter(), error);
        LOGGER.debug("session time out for ajax request:{}", req.getRequestURI());
    } else {
        LOGGER.debug("session time out for request:{}", req.getRequestURI());
        req.getSession().setAttribute(SESSION_TIMEOUT, true);
        redirectToLogin(request, response);
    }
    HttpSession session = req.getSession(false);
    if (session != null) {
        LOGGER.debug(
                "session time out with id: {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}",
                session.getId(), session.isNew(),
                DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT),
                DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request));
    } else {
        LOGGER.debug("session time out, no session available for current request");
    }
}

From source file:com.sms.server.controller.AdminController.java

@RequestMapping(value = "/user", method = RequestMethod.POST, headers = { "Content-type=application/json" })
@ResponseBody/*from   w w  w. j  a  v a2s  .c o  m*/
public ResponseEntity<String> createUser(@RequestBody User user) {
    // Check mandatory fields.
    if (user.getUsername() == null || user.getPassword() == null) {
        return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST);
    }

    // Check unique fields
    if (userDao.getUserByUsername(user.getUsername()) != null) {
        return new ResponseEntity<>("Username already exists.", HttpStatus.NOT_ACCEPTABLE);
    }

    // Add user to the database.
    if (!userDao.createUser(user)) {
        LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME,
                "Error adding user '" + user.getUsername() + "' to database.", null);
        return new ResponseEntity<>("Error adding user to database.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' created successfully.", null);
    return new ResponseEntity<>("User created successfully.", HttpStatus.CREATED);
}

From source file:org.paradise.microservice.SwaggerConfig.java

@Bean
public Docket api() {

    ApiInfo info = new ApiInfo("QR as Postal Address API", "API query DPID of Australian Postal Address",
            "1.0.0", "https://opensource.org/ToS", "Terrence Miao <TerrenceMiao@users.noreply.github.com>",
            "Apache License 2.0", "http://www.apache.org/licenses/LICENSE-2.0");

    return new Docket(DocumentationType.SWAGGER_2).apiInfo(info).select().apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any()).build().pathMapping("/")
            .directModelSubstitute(LocalDate.class, String.class).genericModelSubstitutes(ResponseEntity.class)
            .alternateTypeRules(newRule(
                    typeResolver.resolve(DeferredResult.class,
                            typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                    typeResolver.resolve(WildcardType.class)))
            .useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET,
                    newArrayList(new ResponseMessageBuilder().code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                            .message("500 message").responseModel(new ModelRef("Error")).build()))
            .securitySchemes(newArrayList(apiKey())).securityContexts(newArrayList(securityContext()))
            .enableUrlTemplating(true);//  w  w w. ja va 2s .  c  o m
    //                .globalOperationParameters(
    //                        newArrayList(new ParameterBuilder()
    //                                .name("someGlobalParameter")
    //                                .description("Description of someGlobalParameter")
    //                                .modelRef(new ModelRef("string"))
    //                                .parameterType("query")
    //                                .required(false)
    //                                .build()));

}