Example usage for org.springframework.http HttpStatus NOT_FOUND

List of usage examples for org.springframework.http HttpStatus NOT_FOUND

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus NOT_FOUND.

Prototype

HttpStatus NOT_FOUND

To view the source code for org.springframework.http HttpStatus NOT_FOUND.

Click Source Link

Document

404 Not Found .

Usage

From source file:edu.sjsu.cmpe275.project.controller.UserController.java

/** Delete a user object
 * @return         void/*from   w  ww .jav  a2  s.  c o m*/
 */

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity deleteUser(@PathVariable("id") String name) {

    User user = userDao.removeUser(name);

    if (user == null) {
        return new ResponseEntity(null, HttpStatus.NOT_FOUND);
    } else {
        return new ResponseEntity(user, HttpStatus.OK);
    }
}

From source file:org.springsource.restbucks.training.payment.web.PaymentController.java

/**
 * Accepts a payment for an {@link Order}
 * /*from  w  ww .j  a va 2s  .  co m*/
 * @param order the {@link Order} to process the payment for. Retrieved from the path variable and converted into an
 *          {@link Order} instance by Spring Data's {@link DomainClassConverter}. Will be {@literal null} in case no
 *          {@link Order} with the given id could be found.
 * @param number the {@link CreditCardNumber} unmarshalled from the request payload.
 * @return
 */
@RequestMapping(value = PaymentLinks.PAYMENT, method = RequestMethod.PUT)
ResponseEntity<PaymentResource> submitPayment(@PathVariable("id") Order order,
        @RequestBody CreditCardNumber number) {

    if (order == null || order.isPaid()) {
        return new ResponseEntity<PaymentResource>(HttpStatus.NOT_FOUND);
    }

    CreditCardPayment payment = paymentService.pay(order, number);

    PaymentResource resource = new PaymentResource(order.getPrice(), payment.getCreditCard());
    resource.add(entityLinks.linkToSingleResource(order));

    return new ResponseEntity<PaymentResource>(resource, HttpStatus.CREATED);
}

From source file:com.orange.ngsi.client.NotifyContextRequestTest.java

@Test(expected = HttpClientErrorException.class)
public void notifyContextRequestWith404() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/notifyContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.notifyContext(baseUrl, null, createNotifyContextTempSensor(0)).get();
}

From source file:com.mycompany.springrest.controllers.RoleController.java

@RequestMapping(value = "/role/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Role> updateRole(@PathVariable("id") int id, @RequestBody Role role) {
    logger.info("Updating Role " + id);
    Role currentRole = roleService.getRoleById(id);

    if (currentRole == null) {
        logger.info("Role with id " + id + " not found");
        return new ResponseEntity<Role>(HttpStatus.NOT_FOUND);
    }/*from ww w  .  ja v  a  2s.  co  m*/

    currentRole.setName(role.getName());
    currentRole.setUser(role.getUser());

    roleService.updateRole(currentRole);
    return new ResponseEntity<Role>(currentRole, HttpStatus.OK);
}

From source file:com.orange.ngsi.client.QueryContextRequestTest.java

@Test(expected = HttpClientErrorException.class)
public void queryContextRequestWith404() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature()).get();
}

From source file:edu.sjsu.cmpe275.project.controller.RoomController.java

/** Update a room
 * @param a         Description of a//  ww  w. ja  v  a 2s .c  o m
 * @param b         Description of b
 * @return         Description of c
 */

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public ResponseEntity<?> updateRoom(@PathVariable("id") String roomNo,
        @RequestParam(value = "room_type", required = true) Integer roomType,
        @RequestParam(value = "smoking", required = true) Boolean smoking,
        @RequestParam(value = "base_price", required = false) Integer basePrice) {

    Room room = new Room(roomNo, roomType, smoking, basePrice);
    room = roomDao.updateRoom(room);
    if (room == null) {
        return new ResponseEntity<Object>(null, HttpStatus.NOT_FOUND);
    } else {
        return new ResponseEntity<Object>(room, HttpStatus.OK);
    }
}

From source file:com.github.shredder121.gh_event_api.filter.GithubMACChecker.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws IOException, ServletException {
    String signatureHeader = request.getHeader(GITHUB_SIGNATURE_HEADER);
    if (shouldFilter(request)) {
        if (signatureHeader != null) {
            HttpServletRequest preReadRequest = new PreReadRequest(request);
            byte[] requestBytes = ByteStreams.toByteArray(preReadRequest.getInputStream());
            String signatureString = "sha1=" + hexDigest(requestBytes);
            if (signatureString.hashCode() != signatureHeader.hashCode()) {
                logger.warn("bad signature {} {}", signatureString, signatureHeader);
                response.sendError(HttpStatus.NO_CONTENT.value());
                // drops the payload
            } else {
                filterChain.doFilter(preReadRequest, response);
            }/*from  w w w.j  a va 2  s  . co m*/
        } else {
            response.sendError(HttpStatus.NOT_FOUND.value());
        }
    } else {
        if (signatureHeader != null) {
            logger.warn("Signature checking requested, but Mac is not set up.");
        }
        filterChain.doFilter(request, response);
    }
}

From source file:org.mitre.uma.web.PolicyAPI.java

/**
 * Get the indicated resource set/*from ww  w.  j  a v  a  2 s  .  c om*/
 * @param rsid
 * @param m
 * @param auth
 * @return
 */
@RequestMapping(value = "/{rsid}", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getResourceSet(@PathVariable(value = "rsid") Long rsid, Model m, Authentication auth) {

    ResourceSet rs = resourceSetService.getById(rsid);

    if (rs == null) {
        m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        return HttpCodeView.VIEWNAME;
    }

    if (!rs.getOwner().equals(auth.getName())) {
        logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got "
                + auth.getName());

        // authenticated user didn't match the owner of the resource set
        m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
        return HttpCodeView.VIEWNAME;
    }

    m.addAttribute(JsonEntityView.ENTITY, rs);

    return JsonEntityView.VIEWNAME;
}

From source file:rest.DependenciaRestController.java

@RequestMapping(value = "/dependencia/{codDep}", method = RequestMethod.PUT)
public ResponseEntity<DependenciaBean> updateDependencia(@PathVariable("codDep") long codDep,
        @RequestBody DependenciaBean dependencia) {
    System.out.println("Actualizando Dependencia");
    DependenciaBean dependenciaActual = dependenciaService.findById(codDep);
    if (dependenciaActual == null) {
        System.out.println("La depndencia con codigo codDep = " + codDep + " No existe.");
        return new ResponseEntity<DependenciaBean>(HttpStatus.NOT_FOUND);
    }/*from w  ww . j  a v  a  2s . c o m*/

    dependenciaActual.setDesDep(dependencia.getDesDep());
    dependenciaService.update(dependenciaActual);

    return new ResponseEntity<DependenciaBean>(dependenciaActual, HttpStatus.OK);
}

From source file:web.EventLogRESTController.java

/**
 * Updates an event in the Event Log through REST API
 * @param id/* w w  w  . j  ava  2 s.c  o m*/
 * @param el
 * @return
 */
@RequestMapping(value = "/api/eventlog/{id}", method = RequestMethod.PUT)
public ResponseEntity<EventLog> updateEvent(@PathVariable("id") int id, @RequestBody EventLog el) {
    EventLog currentEL = null;
    //gets Event info.  returns NOT_FOUND error if no Event exists
    try {
        currentEL = dao.getEventsById(id);
    } catch (EmptyResultDataAccessException ex) {
        return new ResponseEntity<EventLog>(HttpStatus.NOT_FOUND);
    }
    //updates Event info and returns the info
    currentEL.setClientFirstName(el.getClientFirstName());
    currentEL.setClientLastName(el.getClientLastName());
    currentEL.setUsername(el.getUsername());
    currentEL.setInteraction(el.getInteraction());
    currentEL.setDate(el.getDate());

    dao.updateEvent(currentEL);
    return new ResponseEntity<EventLog>(currentEL, HttpStatus.OK);
}