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:io.spring.initializr.actuate.stat.ProjectGenerationStatPublisherTests.java
@Test public void fatalErrorOnlyLogs() { ProjectRequest request = createProjectRequest(); this.retryTemplate .setRetryPolicy(new SimpleRetryPolicy(2, Collections.singletonMap(Exception.class, true))); this.mockServer.expect(requestTo("http://example.com/elastic/initializr/request")) .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); this.mockServer.expect(requestTo("http://example.com/elastic/initializr/request")) .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); this.statPublisher.handleEvent(new ProjectGeneratedEvent(request)); this.mockServer.verify(); }
From source file:com.example.todo.api.common.error.RestGlobalExceptionHandler.java
@ExceptionHandler(Exception.class) public ResponseEntity<Object> handleSystemError(Exception ex, WebRequest request) { ApiError apiError = createApiError(request, "E500"); return handleExceptionInternal(ex, apiError, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:com.netflix.genie.web.tasks.leader.ClusterCheckerTaskUnitTests.java
/** * Make sure run method works.// w w w. ja v a 2s. c o m * * @throws IOException on error * @throws GenieException on error */ @Test public void canRun() throws IOException, GenieException { final String host1 = UUID.randomUUID().toString(); final String host2 = UUID.randomUUID().toString(); final String host3 = UUID.randomUUID().toString(); // Mock the 9 invocations for 3 calls to run Mockito.when(this.restTemplate.getForObject(Mockito.anyString(), Mockito.anyObject())).thenReturn("") .thenThrow(new RestClientException("blah")).thenReturn("").thenReturn("") .thenThrow(new RestClientException("blah")).thenReturn("").thenReturn("") .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "", ("{\"status\":\"OUT_OF_SERVICE\", \"genie\": { \"status\": \"OUT_OF_SERVICE\"}, " + "\"db\": { \"status\": \"OUT_OF_SERVICE\"}}").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)) .thenReturn("").thenReturn("") .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "", ("{\"status\":\"OUT_OF_SERVICE\", \"genie\": { \"status\": \"OUT_OF_SERVICE\"}, " + "\"db\": { \"status\": \"OUT_OF_SERVICE\"}}").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)) .thenReturn("").thenReturn("") .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "", ("{\"status\":\"OUT_OF_SERVICE\", \"genie\": { \"status\": \"OUT_OF_SERVICE\"}, " + "\"db\": { \"status\": \"UP\"}}").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)) .thenReturn("").thenReturn("") .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "", ("{\"status\":\"OUT_OF_SERVICE\", \"genie\": { \"status\": \"OUT_OF_SERVICE\"}, " + "\"db\": { \"status\": \"OUT_OF_SERVICE\"}}").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)) .thenReturn(""); final List<String> hostsRunningJobs = Lists.newArrayList(this.hostName, host1, host2, host3); Mockito.when(this.jobSearchService.getAllHostsWithActiveJobs()).thenReturn(hostsRunningJobs); final Job job1 = Mockito.mock(Job.class); final String job1Id = UUID.randomUUID().toString(); Mockito.when(job1.getId()).thenReturn(Optional.of(job1Id)); final Job job2 = Mockito.mock(Job.class); final String job2Id = UUID.randomUUID().toString(); Mockito.when(job2.getId()).thenReturn(Optional.of(job2Id)); final Job job3 = Mockito.mock(Job.class); final String job3Id = UUID.randomUUID().toString(); Mockito.when(job3.getId()).thenReturn(Optional.of(job3Id)); final Job job4 = Mockito.mock(Job.class); final String job4Id = UUID.randomUUID().toString(); Mockito.when(job4.getId()).thenReturn(Optional.of(job4Id)); Mockito.when(this.jobSearchService.getAllActiveJobsOnHost(host2)).thenReturn(Sets.newHashSet(job1, job2)); Mockito.when(this.jobSearchService.getAllActiveJobsOnHost(host3)).thenReturn(Sets.newHashSet(job3, job4)); Mockito.doThrow(new RuntimeException("blah")).doNothing().when(this.jobPersistenceService) .setJobCompletionInformation(Mockito.eq(job1Id), Mockito.eq(JobExecution.LOST_EXIT_CODE), Mockito.eq(JobStatus.FAILED), Mockito.anyString(), Mockito.eq(null), Mockito.eq(null)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(1)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(1)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(1)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(0)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(0)); this.task.run(); Assert.assertThat(this.task.getErrorCountsSize(), Matchers.is(1)); Mockito.verify(this.jobPersistenceService, Mockito.times(2)).setJobCompletionInformation(Mockito.eq(job1Id), Mockito.eq(JobExecution.LOST_EXIT_CODE), Mockito.eq(JobStatus.FAILED), Mockito.anyString(), Mockito.eq(null), Mockito.eq(null)); Mockito.verify(this.jobPersistenceService, Mockito.atLeast(1)).setJobCompletionInformation( Mockito.eq(job2Id), Mockito.eq(JobExecution.LOST_EXIT_CODE), Mockito.eq(JobStatus.FAILED), Mockito.anyString(), Mockito.eq(null), Mockito.eq(null)); Mockito.verify(this.lostJobCounter, Mockito.atLeast(2)).increment(); Mockito.verify(this.unableToUpdateJobCounter, Mockito.times(1)).increment(); }
From source file:org.ng200.openolympus.controller.OlympusErrorController.java
private HttpStatus getStatus(final Integer value) { try {//from w w w . j a v a2s .co m return HttpStatus.valueOf(value); } catch (final Exception ex) { return HttpStatus.INTERNAL_SERVER_ERROR; } }
From source file:org.n52.sps.control.admin.AdminControl.java
@RequestMapping(value = INSERT_RESOURCE, method = RequestMethod.POST, headers = "content-type=application/xml; text/xml") public ModelAndView registerSensorRequest(InputStream payload, HttpServletResponse response) throws InternalServiceException { ModelAndView mav = new ModelAndView("xmlview", "response", null); OwsExceptionReport exceptionReport = new OwsExceptionReport(); // re-use reporting concept try {// w w w .j a v a 2 s . c om if (!service.isSpsAdminAvailable()) { LOGGER.error("register (SensorOffering)"); throw new NoApplicableCodeException(OwsException.BAD_REQUEST); } else { XmlObject request = parseIncomingXmlObject(payload); if (request.schemaType() != InsertSensorOfferingDocument.type) { throw new InvalidRequestException("Sent XML is not of type InsertSensorOffering."); } SpsAdmin spsAdminOperator = service.getSpsAdmin(); spsAdminOperator.insertSensorOffering((InsertSensorOfferingDocument) request, exceptionReport); mav.addObject(getSuccessResponse()); response.setStatus(HttpStatus.OK.value()); } } catch (XmlException e) { LOGGER.error("Could not parse request.", e); exceptionReport.addOwsException(new InvalidRequestException(e.getMessage())); } catch (IOException e) { LOGGER.error("Could not read request.", e); int code = HttpStatus.INTERNAL_SERVER_ERROR.value(); exceptionReport.addOwsException(new NoApplicableCodeException(code)); } catch (OwsException e) { LOGGER.error("Could not handle POST request.", e); exceptionReport.addOwsException(e); } catch (Throwable e) { LOGGER.error("Unexpected Error occured.", e); int code = HttpStatus.INTERNAL_SERVER_ERROR.value(); exceptionReport.addOwsException(new NoApplicableCodeException(code)); } handleServiceExceptionReport(response, mav, exceptionReport); response.setContentType("application/xml"); return mav; }
From source file:com.javafxpert.wikibrowser.WikiClaimsController.java
@RequestMapping(value = "/claims", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> renderClaims(@RequestParam(value = "id", defaultValue = "Q7259") String itemId, @RequestParam(value = "lang") String lang) { String language = wikiBrowserProperties.computeLang(lang); ClaimsSparqlResponse claimsSparqlResponse = callClaimsSparqlQuery(itemId, language); ClaimsResponse claimsResponse = convertSparqlResponse(claimsSparqlResponse, language, itemId); //log.info("claimsResponse:" + claimsResponse); return Optional.ofNullable(claimsResponse).map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK)) .orElse(new ResponseEntity<>("Wikidata query unsuccessful", HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { NullPointerException.class }) protected ResponseEntity<Object> handleNullPointerException(Exception ex, WebRequest request) { ex.printStackTrace();// w ww . j a v a 2 s . co m HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : NullPointerException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:org.ow2.proactive.procci.rest.SwarmRest.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<ResourceRendering> createSwarm(@RequestBody ResourceRendering swarmRendering) { logger.debug("Deploy a swarm " + swarmRendering.toString()); try {/*from ww w .j av a 2 s . co m*/ swarmRendering.checkAttributes(Swarm.getAttributes(), "Compute", mixinService); SwarmBuilder swarmBuilder = new SwarmBuilder(mixinService, swarmRendering); Resource response = instanceService.create(swarmBuilder.build(), transformerManager.getTransformerProvider(TransformerType.SWARM), mixinService); return new ResponseEntity<>(response.getRendering(), HttpStatus.CREATED); } catch (ClientException e) { logger.error(this.getClass().getName(), e); return new ResponseEntity(e.getJsonError(), HttpStatus.BAD_REQUEST); } catch (ServerException e) { logger.error(this.getClass().getName(), e); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.bonitasoft.web.designer.controller.ResourceControllerAdvice.java
@ExceptionHandler(RuntimeException.class) public ResponseEntity<ErrorMessage> handleRepositoryException(RuntimeException exception) { logger.error("Internal Exception", exception); return new ResponseEntity<>(new ErrorMessage(exception), HttpStatus.INTERNAL_SERVER_ERROR); }
From source file:org.ow2.proactive.procci.rest.MixinRest.java
@RequestMapping(value = "{mixinTitle}", method = RequestMethod.PUT) public ResponseEntity<MixinRendering> updateMixin(@PathVariable("mixinTitle") String mixinTitle, @RequestBody MixinRendering mixinRendering) { logger.debug("Updating Mixin " + mixinTitle + " with " + mixinRendering.toString()); Mixin mixin = null;/*from ww w . j a v a2 s .com*/ try { mixin = new MixinBuilder(mixinService, instanceService, mixinRendering).build(); mixinService.addMixin(mixin); } catch (ServerException ex) { logger.error(this.getClass().getName(), ex); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } catch (ClientException ex) { return new ResponseEntity(ex.getJsonError(), HttpStatus.BAD_REQUEST); } return new ResponseEntity(mixin.getRendering(), HttpStatus.OK); }