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.AlertTriggerTests.java
/** * Test GET /alert/* w ww . ja v a 2 s . co m*/ */ @Test public void testGetAlerts() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("Alert"); // Test ResponseEntity<?> response = alertTriggerController.getAlerts(0, 10, null, "test", null, false, user); // Verify assertTrue(response.getBody().toString().equals("Alert")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("Alert Error")); response = alertTriggerController.getAlerts(0, 10, null, "test", null, false, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("Alert Error")); }
From source file:io.github.autsia.crowly.controllers.rest.CampaignsController.java
@RequestMapping(value = "/changeStatus", method = RequestMethod.GET) public ResponseEntity<String> changeStatus(@RequestParam String campaignId, @RequestParam boolean status, HttpServletResponse response) {/* www . j a v a 2 s. c o m*/ try { Campaign campaign = campaignRepository.findOne(campaignId); if (status) { campaign.setStatus(Campaign.ACTIVE); campaignsManager.startCampaign(campaign); } else { campaign.setStatus(Campaign.NOT_ACTIVE); campaignsManager.stopCampaign(campaign); } campaignRepository.save(campaign); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { logger.error(e.getMessage(), e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:nc.noumea.mairie.organigramme.core.ws.BaseWsConsumer.java
public <T> T readResponseWithReturnMessageDto(Class<T> targetClass, ClientResponse response, String url) { T result = null;/* www . j av a2 s. com*/ try { result = targetClass.newInstance(); } catch (Exception ex) { throw new WSConsumerException( "An error occured when instantiating return type when deserializing JSON from SIRH ABS WS request.", ex); } if (response.getStatus() == HttpStatus.NO_CONTENT.value()) { return null; } if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR.value()) { return null; } String output = response.getEntity(String.class); result = new JSONDeserializer<T>().use(Date.class, new MSDateTransformer()).deserializeInto(output, result); return result; }
From source file:org.trustedanalytics.user.invite.RegistrationsControllerTest.java
@Test(expected = HttpClientErrorException.class) public void testAddUser_createUserHttpConnectionError_throwHttpError() { SecurityCode sc = new SecurityCode(USER_EMAIL, SECURITY_CODE); doReturn(sc).when(securityCodeService).verify(Matchers.anyString()); RegistrationModel registration = new RegistrationModel(); registration.setPassword("123456"); registration.setOrg("abcdefgh"); doReturn(true).when(accessInvitationsService).getOrgCreationEligibility(Matchers.anyString()); doThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(invitationsService) .createUser(Matchers.anyString(), Matchers.anyString(), Matchers.anyString()); sut.addUser(registration, SECURITY_CODE); }
From source file:gateway.controller.DeploymentController.java
/** * Processes a request to create a GIS Server deployment for Piazza data. * /* www.j a v a 2s. co m*/ * @see http ://pz-swagger.stage.geointservices.io/#!/Deployment/post_deployment * * @param job * The job, defining details on the deployment * @param user * The user executing the request * @return Job Id for the deployment; appropriate ErrorResponse if that call fails. */ @RequestMapping(value = "/deployment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ApiOperation(value = "Obtain a GIS Server Deployment for a Data Resource object", notes = "Data that has been loaded into Piazza can be deployed to the GIS Server. This will copy the data to the GIS Server data directory (if needed), or point to the Piazza PostGIS; and then create a WMS/WCS/WFS layer (as available) for the service. Only data that has been internally hosted within Piazza can be deployed.", tags = { "Deployment", "Data" }) @ApiResponses(value = { @ApiResponse(code = 201, message = "The Job Id for the specified Deployment. This could be a long-running process to copy the data over to the GIS Server, so a new Job is spawned.", response = JobResponse.class), @ApiResponse(code = 400, message = "Bad Request", response = ErrorResponse.class), @ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class), @ApiResponse(code = 500, message = "Internal Error", response = ErrorResponse.class) }) public ResponseEntity<PiazzaResponse> createDeployment( @ApiParam(value = "The Data Id and deployment information for creating the Deployment", name = "data", required = true) @Valid @RequestBody AccessJob job, Principal user) { try { // Log the request logger.log( String.format("User %s requested Deployment of type %s for Data %s", gatewayUtil.getPrincipalName(user), job.getDeploymentType(), job.getDataId()), PiazzaLogger.INFO); PiazzaJobRequest jobRequest = new PiazzaJobRequest(); jobRequest.createdBy = gatewayUtil.getPrincipalName(user); jobRequest.jobType = job; String jobId = gatewayUtil.sendJobRequest(jobRequest, null); // Send the response back to the user return new ResponseEntity<PiazzaResponse>(new JobResponse(jobId), HttpStatus.CREATED); } catch (Exception exception) { String error = String.format("Error Loading Data for user %s for Id %s of type %s: %s", gatewayUtil.getPrincipalName(user), job.getDataId(), job.getDeploymentType(), exception.getMessage()); LOGGER.error(error, exception); logger.log(error, PiazzaLogger.ERROR); return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Gateway"), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:ca.hec.tenjin.tool.controller.UserController.java
@RequestMapping(value = "/userProfile", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getUserProfile() throws DeniedAccessException, NoSiteException { Map<String, Object> profile = new HashMap<String, Object>(); String currentUserId = sakaiProxy.getCurrentUserId(); String siteId = sakaiProxy.getCurrentSiteId(); Site site = null;//from w ww . ja v a 2s . c o m Collection<Group> usersGroup; // Section permissions List<Object> sections = new ArrayList<Object>(); List<Object> sectionWrite = new ArrayList<Object>(); List<Object> sectionPublish = new ArrayList<Object>(); Map<String, String> section; // Syllabus permissions List<Long> syllabusReadUnpublished = new ArrayList<Long>(); List<Long> syllabusRead = new ArrayList<Long>(); List<Long> syllabusWrite = new ArrayList<Long>(); List<Long> syllabusPublish = new ArrayList<Long>(); // Permissions to the site and sections try { site = sakaiProxy.getSite(siteId); profile.put("siteId", siteId); profile.put("courseTitle", site.getTitle()); profile.put("locale", sakaiProxy.getCurrentUserLocale()); profile.put("defaultLocale", sakaiProxy.getDefaultLocale()); if (securityService.checkOnSiteGroup(currentUserId, TenjinFunctions.TENJIN_FUNCTION_VIEW_MANAGER, site)) { profile.put("managerView", true); } else { profile.put("managerView", false); } // Whether to allow import profile.put("activateImportButton", importProvider != null && securityService .checkOnSiteGroup(currentUserId, TenjinFunctions.TENJIN_FUNCTION_WRITE_COMMON, site)); profile.put("canModifyPermissions", securityService.checkOnSiteGroup(currentUserId, TenjinFunctions.TENJIN_FUNCTION_MODIFY_PERMISSIONS, site)); // The user has permissions in the sections boolean writeOnSite = securityService.checkOnSiteGroup(currentUserId, TenjinFunctions.TENJIN_FUNCTION_WRITE_PERS, site); boolean publishOnSite = securityService.checkOnSiteGroup(currentUserId, TenjinFunctions.TENJIN_FUNCTION_PUBLISH_PERS, site); usersGroup = site.getGroups(); for (Group group : usersGroup) { // Groups created in site info have this property = true // Taken from SiteAction.java in site-manage Object gProp = group.getProperties().getProperty(group.GROUP_PROP_WSETUP_CREATED); if (group.getProviderGroupId() != null && (gProp == null || gProp.equals(Boolean.FALSE.toString()))) { section = new HashMap<String, String>(); section.put("id", group.getId()); section.put("name", group.getTitle()); sections.add(section); if (writeOnSite || securityService.check(currentUserId, TenjinFunctions.TENJIN_FUNCTION_WRITE_PERS, group)) { sectionWrite.add(section); } if (publishOnSite || securityService.check(currentUserId, TenjinFunctions.TENJIN_FUNCTION_PUBLISH_PERS, group)) { sectionPublish.add(section); } } } } catch (Exception e) { log.error("Site " + siteId + " could not be retrieved: " + e.getMessage()); return (Map<String, Object>) new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } profile.put("sections", sections); profile.put("sectionAssign", sectionWrite); profile.put("sectionPublish", sectionPublish); // check user permission on each syllabus List<Syllabus> syllabusList = syllabusService.getSyllabusListForUser(siteId, sakaiProxy.getCurrentUserId()); if (syllabusList != null) { for (Syllabus syllabus : syllabusList) { if (securityService.canReadUnpublished(currentUserId, syllabus)) { syllabusReadUnpublished.add(syllabus.getId()); } if (securityService.canRead(currentUserId, syllabus)) { syllabusRead.add(syllabus.getId()); } if (securityService.canWrite(currentUserId, syllabus)) { syllabusWrite.add(syllabus.getId()); } if (securityService.canPublish(currentUserId, syllabus)) { syllabusPublish.add(syllabus.getId()); } } } profile.put("syllabusReadUnpublished", syllabusReadUnpublished); profile.put("syllabusRead", syllabusRead); profile.put("syllabusWrite", syllabusWrite); profile.put("syllabusPublish", syllabusPublish); String lockRenewDelaySeconds = sakaiProxy .getSakaiProperty(SakaiProxy.PROPERTY_SYLLABUS_LOCK_RENEW_DELAY_SECONDS); profile.put("lockRenewDelaySeconds", lockRenewDelaySeconds); profile.put("resourcesToolId", sakaiProxy.getCurrentSiteResourcesToolId()); // TODO is this secure? Session session = sessionManager.getCurrentSession(); String token = (String) session.getAttribute(UsageSessionService.SAKAI_CSRF_SESSION_ATTRIBUTE); profile.put("csrf_token", token); return profile; }
From source file:com.cloudbees.jenkins.plugins.demo.actuator.SampleActuatorApplicationTests.java
@Test public void testHtmlErrorPage() 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 + "/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.crazyacking.learn.spring.actuator.SampleActuatorApplicationTests.java
@Test public void testHtmlErrorPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", HttpMethod.GET, request, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); assertThat(body).as("Body was null").isNotNull(); assertThat(body).contains("This application has no explicit mapping for /error"); }
From source file:com.mycompany.projetsportmanager.spring.rest.controllers.UserController.java
/** * Retrieve user by id//www . j a v a 2s . c o m * * @param userId * the user identifier * @return the user corresponding to the specified user identifier */ @RequestMapping(method = RequestMethod.GET, value = "/{userId}") public UserResource userGet(@PathVariable("userId") Long userId, HttpServletRequest httpServletRequest) { User requestBo = null; try { requestBo = userRepo.findOne(userId); } 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)); } if (requestBo == null) { String msg = "User with id " + userId + " not found"; throw new DefaultSportManagerException(new ErrorResource("not found", msg, HttpStatus.NOT_FOUND)); } UserResource resource = userResourceAssembler.toResource(requestBo); if (httpServletRequest.isUserInRole("AK_ADMIN")) { resource.add(linkTo(methodOn(UserController.class).userGet(userId, null)) .withRel(ActionsConstants.UPDATE_VIA_PUT)); resource.add(linkTo(methodOn(UserController.class).userGet(userId, null)) .withRel(ActionsConstants.DELETE_VIA_DELETE)); } return resource; }