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:gateway.test.DeploymentTests.java
/** * Test POST /deployment//from www . j a va 2 s. c o m */ @Test public void testCreate() throws Exception { // Mock AccessJob accessJob = new AccessJob("123456"); accessJob.setDeploymentType("geoserver"); // Generate a UUID that we can reproduce. when(gatewayUtil.sendJobRequest(any(PiazzaJobRequest.class), anyString())).thenReturn("654321"); // Test ResponseEntity<PiazzaResponse> entity = deploymentController.createDeployment(accessJob, user); // Verify assertTrue(((JobResponse) entity.getBody()).data.getJobId().equals("654321")); assertTrue(entity.getStatusCode().equals(HttpStatus.CREATED)); // Test Exception Mockito.doThrow(new PiazzaJobException("Kafka Blows Up")).when(gatewayUtil) .sendJobRequest(any(PiazzaJobRequest.class), anyString()); entity = deploymentController.createDeployment(accessJob, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) entity.getBody()).message.contains("Kafka Blows Up")); }
From source file:ca.hec.tenjin.tool.controller.PermissionsController.java
@ExceptionHandler(GroupNotDefinedException.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody String handlegroupNotDefinedException(GroupNotDefinedException ex) { ex.printStackTrace();//from w ww .jav a2 s . c o m return "GroupNotDefinedException"; }
From source file:org.openlmis.fulfillment.web.errorhandler.ServiceErrorHandling.java
/** * Handles the {@link DataRetrievalException} which we were unable to retrieve * reference data due to a communication error. * * @param ex the exception that caused the issue * @return the error response// www. j a va 2 s .c o m */ @ExceptionHandler(DataRetrievalException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public Message.LocalizedMessage handleRefDataException(DataRetrievalException ex) { return logErrorAndRespond("Error fetching from reference data", ERROR_REFERENCE_DATA_RETRIEVE, ex.getResource(), ex.getStatus().toString(), ex.getResponse()); }
From source file:org.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java
@Test public void testExceptionHandler() throws Exception { // Login first TestLoginInfo loginInfo = login();/*from www . j av a2 s . co m*/ HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<String> entity = new HttpEntity<String>(headers); // Calling protected resource - requires CSRF token UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + "/exc") .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<ResponseDataVO> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, ResponseDataVO.class); ResponseDataVO data = responseEntity.getBody(); assertEquals(500, data.getErrorVO().getCode()); assertTrue("contains message", data.getErrorVO().getMessage().contains("kk")); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); }
From source file:io.omatic.event.controller.EventController.java
@ExceptionHandler @ResponseBody/*from ww w.jav a 2 s . c o m*/ @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public ApiIssue handleException(Exception exception) { ApiIssue error = new ApiIssue(); error.setLevel(IssueLevel.ERROR); error.setCode(500); error.setMessage("The request could not be processed due to an unexpected error."); log.error(exception.getMessage()); return error; }
From source file:org.n52.sps.control.xml.XmlController.java
@RequestMapping(method = RequestMethod.POST /*, headers = "content-type=application/xml; text/xml"*/) public ModelAndView handlePOSTRequest(InputStream payload, HttpServletResponse response, HttpServletRequest request) throws OwsException { ModelAndView mav = new ModelAndView("xmlview", "response", null); OwsExceptionReport exceptionReport = new OwsExceptionReport(); try {/*from ww w . j av a2 s .co m*/ XmlObject xmlPayload = parseIncomingXmlObject(payload); RequestDelegationHandler requestHandler = createRequestHandler(xmlPayload); mav.addObject(requestHandler.delegate()); 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) { // REQ 2: http://www.opengis.net/spec/SPS/2.0/req/exceptions LOGGER.info("Could not handle POST request.", e); exceptionReport.addOwsException(e); } catch (OwsExceptionReport e) { LOGGER.info("Could not handle POST request.", e); exceptionReport = e; } catch (Throwable e) { // TODO extract to Spring ExceptionHandler LOGGER.error("Unknown exception occured!", e); exceptionReport.addOwsException(new NoApplicableCodeException(OwsException.INTERNAL_SERVER_ERROR)); } handleServiceExceptionReport(response, mav, exceptionReport); LOGGER.debug(mav.toString()); return mav; }
From source file:gateway.test.EventTests.java
/** * Test POST /event// w ww. j ava 2 s . c o m */ @Test public void testFireEvent() { // Mock Response when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn(any(String.class)); // Test ResponseEntity<?> response = eventController.fireEvent(new Event(), user); // Verify assertTrue(response.getStatusCode().equals(HttpStatus.CREATED)); // Test REST Exception when(restTemplate.postForObject(anyString(), any(), eq(String.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, WORKFLOW_ERROR)); response = eventController.fireEvent(new Event(), user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); // Test Exception when(restTemplate.postForObject(anyString(), any(), eq(String.class))) .thenThrow(new RestClientException("event error")); response = eventController.fireEvent(new Event(), user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event error")); }
From source file:ca.hec.tenjin.tool.controller.SiteToolsController.java
@RequestMapping(value = "/announcement/{siteId}", method = RequestMethod.POST) public @ResponseBody ResponseEntity createAnnouncement(@RequestBody Map<String, Object> announcement, @PathVariable String siteId) { String title = (String) announcement.get("title"); String message = (String) announcement.get("message"); ArrayList<String> groups = (ArrayList<String>) announcement.get("groups"); Collection<Group> authzGroups = new Vector<Group>(); AnnouncementChannel channel = getAnnouncementChannel(siteId); try {/*from w w w . ja v a2 s .c o m*/ if (channel != null) { AnnouncementMessageEdit messageEdit = null; messageEdit = channel.addAnnouncementMessage(); if (messageEdit != null) { AnnouncementMessageHeaderEdit header = messageEdit.getAnnouncementHeaderEdit(); header.setSubject(title); messageEdit.setBody(message); for (String group : groups) { authzGroups.add(sakaiProxy.getGroup(group)); } header.setGroupAccess(authzGroups); channel.commitMessage(messageEdit); } } else { throw new Exception("No annoucement channel available"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity(HttpStatus.OK); }
From source file:gateway.test.ServiceTests.java
/** * Test POST /service endpoint// www. j a va 2 s .co m */ @Test public void testRegister() { // Mock Service service = new Service(); service.setServiceId("123456"); ServiceIdResponse mockResponse = new ServiceIdResponse(service.getServiceId()); when(restTemplate.postForEntity(anyString(), any(), eq(ServiceIdResponse.class))) .thenReturn(new ResponseEntity<ServiceIdResponse>(mockResponse, HttpStatus.CREATED)); // Test ResponseEntity<PiazzaResponse> entity = serviceController.registerService(service, user); ServiceIdResponse response = (ServiceIdResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.CREATED)); assertTrue(response.data.getServiceId().equals("123456")); // Test Exception when(restTemplate.postForEntity(anyString(), any(), eq(ServiceIdResponse.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); entity = serviceController.registerService(service, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:com.esri.geoportal.harvester.rest.BrokerController.java
/** * Get a single broker.//from w ww. jav a 2s . c o m * @param brokerId broker id * @return broker info or <code>null</code> if no broker found */ @RequestMapping(value = "/rest/harvester/brokers/{brokerId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<BrokerResponse> getBroker(@PathVariable UUID brokerId) { try { LOG.debug(formatForLog("GET /rest/harvester/brokers/%s", brokerId)); return new ResponseEntity<>( BrokerResponse.createFrom( engine.getBrokersService().findBroker(brokerId, LocaleContextHolder.getLocale())), HttpStatus.OK); } catch (DataProcessorException ex) { LOG.error(formatForLog("Error getting broker: %s", brokerId), ex); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }