List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR
HttpStatus INTERNAL_SERVER_ERROR
To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.
Click Source Link
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * POST /account : update the current user information. * * @param userDTO the current user information * @return the ResponseEntity with status 200 (OK), or status 400 (Bad Request) or 500 (Internal Server Error) if the user couldn't be updated *///from w w w.ja v a 2s . co m @RequestMapping(value = "/account", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<String> saveAccount(@Valid @RequestBody UserDTO userDTO) { Optional<User> existingUser = userRepository.findOneByEmail(userDTO.getEmail()); if (existingUser.isPresent() && (!existingUser.get().getLogin().equalsIgnoreCase(userDTO.getLogin()))) { return ResponseEntity.badRequest() .headers( HeaderUtil.createFailureAlert("user-management", "emailexists", "Email already in use")) .body(null); } return userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).map(u -> { userService.updateUserInformation(userDTO.getFirstName(), userDTO.getLastName(), userDTO.getEmail(), userDTO.getLangKey()); return new ResponseEntity<String>(HttpStatus.OK); }).orElseGet(() -> new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java
/** * /*from w ww . j a v a2s . c o m*/ * @param request ? * @param exception * @return ExceptionDto JSON */ @ExceptionHandler @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ModelAndView springErrorHand(HttpServletRequest request, Exception exception) { String simpleMsg = (String) request.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE); String errorCode = exception == null ? simpleMsg : exception.getClass().getSimpleName(); String errorMessage = exception == null ? simpleMsg : exception.getMessage(); LOGGER.error("Error catch: statusCode[{}], errorMessage[{}], errorUrl[{}]", HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMessage, request.getRequestURI(), exception); return prepareExceptionInfo(request, HttpStatus.INTERNAL_SERVER_ERROR, errorCode, errorMessage); }
From source file:gateway.test.JobTests.java
/** * Test PUT /job/{jobId}/*from w w w . ja v a2 s . c o m*/ */ @Test public void testRepeat() { // Mock ResponseEntity<JobResponse> mockEntity = new ResponseEntity<JobResponse>(new JobResponse("Updated"), HttpStatus.OK); when(restTemplate.postForEntity(anyString(), any(), eq(JobResponse.class))).thenReturn(mockEntity); // Test ResponseEntity<PiazzaResponse> entity = jobController.repeatJob("123456", user); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.CREATED)); // Test Exception when(restTemplate.postForEntity(anyString(), any(), eq(JobResponse.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); entity = jobController.repeatJob("123456", user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:gateway.test.ServiceTests.java
/** * Test DELETE /service/{serviceId}//w w w . jav a2 s . co m */ @Test public void testDelete() { // Mock when(restTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(SuccessResponse.class))) .thenReturn(new ResponseEntity<SuccessResponse>( new SuccessResponse("Deleted", "Service Controller"), HttpStatus.OK)); // Test ResponseEntity<PiazzaResponse> entity = serviceController.deleteService("123456", false, user); SuccessResponse response = (SuccessResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.data.getMessage().contains("Deleted")); // Test Exception when(restTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(SuccessResponse.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); entity = serviceController.deleteService("123456", false, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { ArithmeticException.class }) protected ResponseEntity<Object> handleArithmeticException(Exception ex, WebRequest request) { ex.printStackTrace();/*from w w w . j a va2 s . c om*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : ArithmeticException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:comsat.sample.actuator.SampleActuatorApplicationTests.java
private void testHtmlErrorPage(final String path) throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()).exchange( "http://localhost:" + this.port + "/" + emptyIfNull(path) + "/foo", HttpMethod.GET, request, String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); String body = entity.getBody(); assertNotNull("Body was null", body); assertTrue("Wrong body: " + body, body.contains("This application has no explicit mapping for /error")); }
From source file:com.mycompany.projetsportmanager.spring.rest.controllers.UserController.java
@RequestMapping(method = RequestMethod.GET, value = "/{userId}/picture", produces = "image/jpeg") public byte[] pictureGet(@PathVariable("userId") Long userId) { try {// w w w . j a v a 2 s. c o m return userService.getUserPicture(userId); } catch (SportManagerException e1) { String msg = "Can't retrieve user picture with id " + userId + " from DB"; logger.error(msg, e1); throw new DefaultSportManagerException( new ErrorResource("db error", msg, HttpStatus.INTERNAL_SERVER_ERROR)); } }
From source file:be.solidx.hot.rest.RestController.java
protected ResponseEntity<byte[]> buildResponse(byte[] response, Map headers, Integer httpStatus) { try {/* ww w. j a v a2 s .c o m*/ HttpHeaders httpHeaders = buildHttpHeaders(headers); return new ResponseEntity<byte[]>(response, httpHeaders, HttpStatus.valueOf(httpStatus)); } catch (ScriptException e) { return new ResponseEntity<byte[]>(e.getMessage().getBytes(), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:gateway.test.DataTests.java
/** * Test POST /data endpoint/* w ww. j ava 2s. c o m*/ */ @Test public void testAddData() throws Exception { // Mock an Ingest Job request, containing some sample data we want to // ingest. IngestJob mockJob = new IngestJob(); mockJob.data = mockData; mockJob.host = false; // Generate a UUID that we can reproduce. when(gatewayUtil.sendJobRequest(any(PiazzaJobRequest.class), anyString())).thenReturn("123456"); // Submit a mock request ResponseEntity<PiazzaResponse> entity = dataController.ingestData(mockJob, user); PiazzaResponse response = entity.getBody(); // Verify the results. If the mock Kafka message is sent, then this is // considered a success. assertTrue(response instanceof JobResponse == true); assertTrue(response instanceof ErrorResponse == false); assertTrue(((JobResponse) response).data.getJobId().equalsIgnoreCase("123456")); assertTrue(entity.getStatusCode().equals(HttpStatus.CREATED)); // Test an Exception when(gatewayUtil.sendJobRequest(any(PiazzaJobRequest.class), anyString())) .thenThrow(new PiazzaJobException("Error")); entity = dataController.ingestData(mockJob, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:com.monarchapis.driver.spring.rest.ApiErrorResponseEntityExceptionHandler.java
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) { request.setAttribute("javax.servlet.error.exception", ex, WebRequest.SCOPE_REQUEST); }/*from w ww.j a v a 2s. c o m*/ return errorResponse("internalError", headers); }