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:org.mitre.oauth2.web.TokenAPI.java

@RequestMapping(value = "/access/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getAccessTokenById(@PathVariable("id") Long id, ModelMap m, Principal p) {

    OAuth2AccessTokenEntity token = tokenService.getAccessTokenById(id);

    if (token == null) {
        logger.error("getToken failed; token not found: " + id);
        m.put(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        m.put(JsonErrorView.ERROR_MESSAGE, "The requested token with id " + id + " could not be found.");
        return JsonErrorView.VIEWNAME;
    } else if (!token.getAuthenticationHolder().getAuthentication().getName().equals(p.getName())) {
        logger.error("getToken failed; token does not belong to principal " + p.getName());
        m.put(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
        m.put(JsonErrorView.ERROR_MESSAGE, "You do not have permission to view this token");
        return JsonErrorView.VIEWNAME;
    } else {/*from   w w  w .  j a v  a  2s . c  om*/
        m.put(JsonEntityView.ENTITY, token);
        return TokenApiView.VIEWNAME;
    }
}

From source file:com.github.shredder121.gh_event_api.handler.HmacBehaviorTest.java

@Test
public void testHmacMissing() {
    given().headers("X-GitHub-Event", "create").and().body(getBody(), restAssuredMapper).with()
            .contentType(JSON).expect().statusCode(HttpStatus.NOT_FOUND.value()).when().post();
}

From source file:org.bonitasoft.web.designer.controller.ResourceControllerAdvice.java

@ExceptionHandler(NotFoundException.class)
public ResponseEntity<ErrorMessage> handleNotFoundException(NotFoundException exception) {
    logger.error("Element Not Found Exception", exception);
    return new ResponseEntity<>(new ErrorMessage(exception), HttpStatus.NOT_FOUND);
}

From source file:com.iscas.rent.rest.UserRestController.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public Account get(@PathVariable("id") Long id) {
    Account user = userService.getUser(id);
    if (user == null) {
        String message = "?(id:" + id + ")";
        logger.warn(message);/* w w  w  .  ja  va2  s. c o m*/
        throw new RestException(HttpStatus.NOT_FOUND, message);
    }
    return user;
}

From source file:org.ameba.exception.NotFoundException.java

/**
 * {@link HttpStatus#NOT_FOUND}.
 *
 * @return {@link HttpStatus#NOT_FOUND}
 */
@Override
public HttpStatus getStatus() {
    return HttpStatus.NOT_FOUND;
}

From source file:com.appglu.impl.PushTemplateTest.java

@Test
public void readDeviceNotFound() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/push/device/f3f71c5a-0a98-48f7-9acd-d38d714d76ad"))
            .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)
                    .body(compactedJson("data/error_not_found")).headers(responseHeaders));

    Device device = pushOperations.readDevice("f3f71c5a-0a98-48f7-9acd-d38d714d76ad");
    Assert.assertNull(device);/* w w  w.j ava 2s .  c o  m*/

    mockServer.verify();
}

From source file:org.createnet.raptor.auth.service.controller.RoleController.java

@PreAuthorize("hasAuthority('admin') or hasAuthority('super_admin')")
@RequestMapping(value = { "/role/{roleId}" }, method = RequestMethod.PUT)
@ApiOperation(value = "Update a role", notes = "", response = Role.class, nickname = "updateRole")
public ResponseEntity<?> update(@AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser,
        @PathVariable Long roleId, @RequestBody Role rawRole) {

    if ((rawRole.getName().isEmpty() || rawRole.getName() == null)) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name property is missing");
    }//from  w  w  w .jav  a2  s . c  o m

    Role role2 = roleService.getByName(rawRole.getName());
    if (role2 != null) {
        return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
    }

    rawRole.setId(roleId);
    Role role = roleService.update(roleId, rawRole);
    if (role == null) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }

    logger.debug("Updated role {}", role.getName());
    return ResponseEntity.ok(role);
}

From source file:org.ow2.proactive.scheduling.api.graphql.service.AuthenticationServiceTest.java

@Test
public void testAuthenticateInvalidSessionId() {
    HttpClientErrorException e = new HttpClientErrorException(HttpStatus.NOT_FOUND);
    when(restTemplate.getForObject(any(String.class), eq(String.class))).thenThrow(e);
    try {/*from w ww. ja  v  a 2s .c o  m*/
        authenticationService.authenticate("sessionId");
    } catch (Exception ex) {
        assertThat(ex.getMessage().contains("session ID is invalid"), is(true));
    }
}

From source file:gateway.test.JobTests.java

/**
 * Initialize mock objects.//from w  w  w  . j  av a2  s. co m
 */
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    MockitoAnnotations.initMocks(gatewayUtil);

    // Mock a common error we can use to test
    mockError = new ErrorResponse("Job Not Found", "Gateway");
    mockJobError = new ResponseEntity<PiazzaResponse>(new JobErrorResponse("1234", "Job Not Found", "Gateway"),
            HttpStatus.NOT_FOUND);

    // Mock a Job
    mockJob = new Job();
    mockJob.setJobId("123456");
    mockJob.jobType = new RepeatJob("654321");
    mockJob.progress = new JobProgress(50);
    mockJob.createdBy = "Test User 2";
    mockJob.status = StatusUpdate.STATUS_RUNNING;

    // Mock a user
    user = new JMXPrincipal("Test User");

    // Mock the Kafka response that Producers will send. This will always
    // return a Future that completes immediately and simply returns true.
    when(producer.send(isA(ProducerRecord.class))).thenAnswer(new Answer<Future<Boolean>>() {
        @Override
        public Future<Boolean> answer(InvocationOnMock invocation) throws Throwable {
            Future<Boolean> future = mock(FutureTask.class);
            when(future.isDone()).thenReturn(true);
            when(future.get()).thenReturn(true);
            return future;
        }
    });

    when(gatewayUtil.getErrorResponse(anyString())).thenCallRealMethod();
}

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

@RequestMapping(value = "/user/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> updateUser(@PathVariable("id") int id, @RequestBody User user) {
    logger.info("Updating User " + id);
    User currentUser = userService.getUserById(id);

    if (currentUser == null) {
        logger.info("User with id " + id + " not found");
        return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
    }/*w  ww .j  a  v  a 2 s .  c o m*/

    currentUser.setUserName(user.getUserName());
    currentUser.setPassWord(user.getPassWord());
    currentUser.setRoles(user.getRoles());
    currentUser.setIsActive(user.isIsActive());

    userService.updateUser(currentUser);
    return new ResponseEntity<User>(currentUser, HttpStatus.OK);
}