List of usage examples for org.springframework.http HttpStatus NOT_FOUND
HttpStatus NOT_FOUND
To view the source code for org.springframework.http HttpStatus NOT_FOUND.
Click Source Link
From source file:locksdemo.LocksController.java
@ExceptionHandler(LockNotHeldException.class) @ResponseBody/* w w w. j a v a2 s . co m*/ public ResponseEntity<Map<String, Object>> lockNotHeld() { Map<String, Object> body = new HashMap<String, Object>(); body.put("status", "INVALID"); body.put("description", "Lock not held (values do not match)"); return new ResponseEntity<Map<String, Object>>(body, HttpStatus.NOT_FOUND); }
From source file:$.TaskRestFT.java
/** * //./* ww w . java2 s . c o m*/ */ @Test @Category(Smoke.class) public void createUpdateAndDeleteTask() { // create Task task = TaskData.randomTask(); URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task); System.out.println(createdTaskUri.toString()); Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class); assertThat(createdTask.getTitle()).isEqualTo(task.getTitle()); // update String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/"); task.setId(new Long(id)); task.setTitle(TaskData.randomTitle()); restTemplate.put(createdTaskUri, task); Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class); assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle()); // delete restTemplate.delete(createdTaskUri); try { restTemplate.getForObject(createdTaskUri, Task.class); fail("Get should fail while feth a deleted task"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } }
From source file:org.mitre.uma.web.ClaimsCollectionEndpoint.java
@RequestMapping(method = RequestMethod.GET) public String collectClaims(@RequestParam("client_id") String clientId, @RequestParam(value = "redirect_uri", required = false) String redirectUri, @RequestParam("ticket") String ticketValue, @RequestParam(value = "state", required = false) String state, Model m, OIDCAuthenticationToken auth) { ClientDetailsEntity client = clientService.loadClientByClientId(clientId); PermissionTicket ticket = permissionService.getByTicket(ticketValue); if (client == null || ticket == null) { logger.info("Client or ticket not found: " + clientId + " :: " + ticketValue); m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND); return HttpCodeView.VIEWNAME; }/*from w w w . ja va 2s .c o m*/ // we've got a client and ticket, let's attach the claims that we have from the token and userinfo // subject Set<Claim> claimsSupplied = Sets.newHashSet(ticket.getClaimsSupplied()); String issuer = auth.getIssuer(); UserInfo userInfo = auth.getUserInfo(); claimsSupplied.add(mkClaim(issuer, "sub", new JsonPrimitive(auth.getSub()))); if (userInfo.getEmail() != null) { claimsSupplied.add(mkClaim(issuer, "email", new JsonPrimitive(userInfo.getEmail()))); } if (userInfo.getEmailVerified() != null) { claimsSupplied.add(mkClaim(issuer, "email_verified", new JsonPrimitive(userInfo.getEmailVerified()))); } if (userInfo.getPhoneNumber() != null) { claimsSupplied .add(mkClaim(issuer, "phone_number", new JsonPrimitive(auth.getUserInfo().getPhoneNumber()))); } if (userInfo.getPhoneNumberVerified() != null) { claimsSupplied.add(mkClaim(issuer, "phone_number_verified", new JsonPrimitive(auth.getUserInfo().getPhoneNumberVerified()))); } if (userInfo.getPreferredUsername() != null) { claimsSupplied.add(mkClaim(issuer, "preferred_username", new JsonPrimitive(auth.getUserInfo().getPreferredUsername()))); } if (userInfo.getProfile() != null) { claimsSupplied.add(mkClaim(issuer, "profile", new JsonPrimitive(auth.getUserInfo().getProfile()))); } ticket.setClaimsSupplied(claimsSupplied); PermissionTicket updatedTicket = permissionService.updateTicket(ticket); if (Strings.isNullOrEmpty(redirectUri)) { if (client.getClaimsRedirectUris().size() == 1) { redirectUri = client.getClaimsRedirectUris().iterator().next(); // get the first (and only) redirect URI to use here logger.info("No redirect URI passed in, using registered value: " + redirectUri); } else { throw new RedirectMismatchException("Unable to find redirect URI and none passed in."); } } else { if (!client.getClaimsRedirectUris().contains(redirectUri)) { throw new RedirectMismatchException("Claims redirect did not match the registered values."); } } UriComponentsBuilder template = UriComponentsBuilder.fromUriString(redirectUri); template.queryParam("authorization_state", "claims_submitted"); if (!Strings.isNullOrEmpty(state)) { template.queryParam("state", state); } String uriString = template.toUriString(); logger.info("Redirecting to " + uriString); return "redirect:" + uriString; }
From source file:reconf.server.services.property.ReadPropertyService.java
@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}/rule/{rule}", method = RequestMethod.GET) @Transactional(readOnly = true)// ww w. ja va 2 s .c o m public ResponseEntity<PropertyRuleResult> restricted(@PathVariable("prod") String product, @PathVariable("comp") String component, @PathVariable("prop") String property, @PathVariable("rule") String rule, HttpServletRequest request) { PropertyKey key = new PropertyKey(product, component, property, rule); Property fromRequest = new Property(key); if (!products.exists(key.getProduct())) { return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(fromRequest, Product.NOT_FOUND), HttpStatus.NOT_FOUND); } if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) { return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(fromRequest, Component.NOT_FOUND), HttpStatus.NOT_FOUND); } Property target = properties.findOne(key); if (target == null) { return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(fromRequest, Property.NOT_FOUND), HttpStatus.NOT_FOUND); } PropertyRuleResult result = new PropertyRuleResult(target, CrudServiceUtils.getBaseUrl(request)); result.addSelfUri(CrudServiceUtils.getBaseUrl(request)); return new ResponseEntity<PropertyRuleResult>(result, HttpStatus.OK); }
From source file:reconf.server.services.property.ClientReadPropertyService.java
@RequestMapping(value = "/{prod}/{comp}/{prop}", method = RequestMethod.GET) @Transactional(readOnly = true)//from w ww. j a v a2 s. c om public ResponseEntity<String> doIt(@PathVariable("prod") String product, @PathVariable("comp") String component, @PathVariable("prop") String property, @RequestParam(value = "instance", required = false, defaultValue = "unknown") String instance) { PropertyKey key = new PropertyKey(product, component, property); List<String> errors = DomainValidator.checkForErrors(key); Property reqProperty = new Property(key); HttpHeaders headers = new HttpHeaders(); if (!errors.isEmpty()) { addErrorHeader(headers, errors, reqProperty); return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST); } List<Property> dbProperties = properties .findByKeyProductAndKeyComponentAndKeyNameOrderByRulePriorityDescKeyRuleNameAsc(key.getProduct(), key.getComponent(), key.getName()); for (Property dbProperty : dbProperties) { try { if (isMatch(instance, dbProperty)) { addRuleHeader(headers, dbProperty); return new ResponseEntity<String>(dbProperty.getValue(), headers, HttpStatus.OK); } } catch (Exception e) { log.error("error applying rule", e); addRuleHeader(headers, dbProperty); addErrorHeader(headers, Collections.singletonList("rule error"), reqProperty); return new ResponseEntity<String>(headers, HttpStatus.INTERNAL_SERVER_ERROR); } } return new ResponseEntity<String>(HttpStatus.NOT_FOUND); }
From source file:edu.sjsu.cmpe275.lab2.service.ManageFriendshipController.java
/** Add a friendship object (9) Add a friend/* ww w . j a v a2s .c o m*/ Path:friends/{id1}/{id2} Method: PUT This makes the two persons with the given IDs friends with each other. If either person does not exist, return 404. If the two persons are already friends, do nothing, just return 200. Otherwise, Record this friendship relation. If all is successful, return HTTP code 200 and any informative text message in the HTTP payload. * @param a Description of a * @param b Description of b * @return Description of c */ @RequestMapping(value = "/{id1}/{id2}", method = RequestMethod.PUT) public ResponseEntity createFriendship(@PathVariable("id1") long id1, @PathVariable("id2") long id2) { Session session = null; Transaction transaction = null; Person person1 = null, person2 = null; try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); person1 = (Person) session.get(Person.class, id1); person2 = (Person) session.get(Person.class, id2); if (person1 == null || person2 == null) { throw new HibernateException("Can't find persons with id1 = " + id1 + " and id2 = " + id2); } List<Person> f = person1.getFriends(); if (!f.contains(person2)) { f.add(person2); } person1.setFriends(f); session.update(person1); f = person2.getFriends(); if (!f.contains(person1)) { f.add(person1); } person2.setFriends(f); session.update(person2); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } return new ResponseEntity("Can't find persons with id1 = " + id1 + " and id2 = " + id2, HttpStatus.NOT_FOUND); } finally { if (session != null) { session.close(); } } return new ResponseEntity("Created the friendship between id1 = " + id1 + " and id2 = " + id2, HttpStatus.OK); }
From source file:it.tidalwave.northernwind.frontend.ui.springmvc.SpringMvcSiteView.java
/******************************************************************************************************************* * * {@inheritDoc}// ww w .j ava 2s . c o m * ******************************************************************************************************************/ @Override public void renderSiteNode(final @Nonnull SiteNode siteNode) throws IOException { log.info("renderSiteNode({})", siteNode); try { final Visitor<Layout, TextHolder> nodeViewBuilderVisitor = new SpringMvcNodeViewBuilderVisitor( siteNode); final TextHolder textHolder = siteNode.getLayout().accept(nodeViewBuilderVisitor); responseHolder.response().withBody(textHolder.asBytes("UTF-8")) .withContentType(textHolder.getMimeType()).put(); } catch (NotFoundException e) { log.error("", e); responseHolder.response().withStatus(HttpStatus.NOT_FOUND.value()).withBody(e.toString()) .withContentType("text/html").put(); } }
From source file:sagan.projects.support.BadgeController.java
/** * Creates a SVG badge for a project with a given {@link ReleaseStatus}. * * @param projectId/*from w w w .j a va 2 s. c o m*/ * @param releaseStatus * @return * @throws IOException */ private ResponseEntity<byte[]> badgeFor(String projectId, ReleaseStatus releaseStatus) throws IOException { Project project = service.getProject(projectId); if (project == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Optional<ProjectRelease> gaRelease = getRelease(project.getProjectReleases(), projectRelease -> projectRelease.getReleaseStatus() == releaseStatus); if (!gaRelease.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } byte[] svgBadge = versionBadgeService.createSvgBadge(project, gaRelease.get()); return ResponseEntity.ok().eTag(gaRelease.get().getVersion()) .cacheControl(CacheControl.maxAge(1L, TimeUnit.HOURS)).body(svgBadge); }
From source file:ch.wisv.areafiftylan.extras.rfid.controller.RFIDController.java
@ExceptionHandler(RFIDNotFoundException.class) public ResponseEntity<?> handleRFIDNotFoundException(RFIDNotFoundException e) { return createResponseEntity(HttpStatus.NOT_FOUND, e.getMessage()); }
From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataServiceTest.java
@Test public void shouldReturnNullIfEntityCannotBeFoundById() throws Exception { // given/*from ww w. j av a 2 s. c o m*/ BaseReferenceDataService<T> service = prepareService(); UUID id = UUID.randomUUID(); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getResultClass()))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); T found = service.findOne(id); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getResultClass())); URI uri = uriCaptor.getValue(); String url = service.getServiceUrl() + service.getUrl() + id; assertThat(uri.toString(), is(equalTo(url))); assertThat(found, is(nullValue())); assertAuthHeader(entityCaptor.getValue()); assertThat(entityCaptor.getValue().getBody(), is(nullValue())); }