Example usage for org.springframework.http ResponseEntity status

List of usage examples for org.springframework.http ResponseEntity status

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity status.

Prototype

Object status

To view the source code for org.springframework.http ResponseEntity status.

Click Source Link

Usage

From source file:org.awesomeagile.testing.google.FakeGoogleController.java

@ResponseBody
@ExceptionHandler({ AuthenticationException.class })
public ResponseEntity<String> handleAuthenticationException(AuthenticationException ex) {
    return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ex.getMessage());
}

From source file:com.yoncabt.ebr.ws.ReportWS.java

@RequestMapping(value = { "/ws/1.0/output/{requestId}" }, method = RequestMethod.GET)
public ResponseEntity<byte[]> output(@PathVariable("requestId") String requestId) throws IOException {
    try {//from   w ww  .ja  va 2  s. c om
        byte[] output = reportService.output(requestId);
        ReportTask task = reportService.detail(requestId);
        logManager.info("output :" + requestId);
        return ResponseEntity.status(HttpStatus.OK)
                .contentType(ReportOutputFormat.valueOf(task.getRequest().getExtension()).getMediaType())
                .lastModified(task.getEnded()).header("Content-Disposition",
                        "inline; filename=" + requestId + "." + task.getRequest().getExtension())
                .body(output);
    } catch (NoSuchElementException e) {
        logManager.info("output :YOK !!! " + requestId);
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }
}

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

@PreAuthorize("hasAuthority('admin') or hasAuthority('super_admin')")
@RequestMapping(value = { "/role/{roleId}" }, method = RequestMethod.DELETE)
@ApiOperation(value = "Delete a role", notes = "", code = 202, nickname = "deleteRole")
public ResponseEntity<Role> delete(
        @AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser,
        @PathVariable Long roleId) {

    if (!roleService.delete(roleId)) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }//from  w w w . jav  a2  s  . c  o  m

    logger.debug("Deleted role {}", roleId);
    return ResponseEntity.status(HttpStatus.ACCEPTED).body(null);
}

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

@RequestMapping(value = "/sync", method = RequestMethod.POST)
@ApiOperation(value = "Sync user permission on a device", notes = "", code = 202, nickname = "syncPermission")
public ResponseEntity<?> syncPermission(
        @AuthenticationPrincipal RaptorUserDetailsService.RaptorUserDetails currentUser,
        @RequestBody SyncRequest body) {

    deviceService.sync(currentUser, body);
    return ResponseEntity.status(HttpStatus.ACCEPTED).body(null);
}

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

@RequestMapping(value = "/{deviceUuid}/permission", method = RequestMethod.PUT)
@ApiOperation(value = "Save user permissions on a device", notes = "", response = String.class, responseContainer = "List", nickname = "setPermissions")
public ResponseEntity<?> setPermission(@RequestBody PermissionRequestBatch body,
        @PathVariable("deviceUuid") String deviceUuid) {

    Device device = deviceService.getByUuid(deviceUuid);
    if (device == null) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Device not found");
    }//from   ww  w .j  a  va  2s . c  o m

    User user = userService.getByUuid(body.user);
    if (user == null) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found");
    }

    List<Permission> permissions = body.permissions.stream().map((String s) -> {
        Permission p = RaptorPermission.fromLabel(s);
        if (p == null) {
            throw new PermissionNotFoundException("Permission not found ");
        }
        return p;
    }).distinct().collect(Collectors.toList());

    aclDeviceService.set(device, user, permissions);
    List<String> settedPermissions = RaptorPermission.toLabel(aclDeviceService.list(device, user));

    return ResponseEntity.status(HttpStatus.ACCEPTED).body(settedPermissions);
}

From source file:cern.jarrace.controller.rest.controller.AgentContainerController.java

@RequestMapping(value = "/{" + CONTAINER_NAME_VARIABLE_NAME + "}/read", method = RequestMethod.GET)
public ResponseEntity<String> readSource(@PathVariable(CONTAINER_NAME_VARIABLE_NAME) String containerName,
        @RequestParam("class") String className) {
    return agentContainerManager.findAgentContainer(containerName).map(container -> {
        try {//from   w  w w  .j  av a  2  s  .c o m
            return JarReader.ofContainer(container, reader -> {
                final String entry = className + JAVA_CLASS_SUFFIX;
                try {
                    return ResponseEntity.ok(reader.readEntry(entry));
                } catch (NoSuchElementException e) {
                    return ResponseEntity.badRequest().body("No class source found for entry " + entry);
                } catch (IOException e) {
                    return ResponseEntity.status(INTERNAL_SERVER_ERROR)
                            .body("Failed to read entry " + entry + " inside container " + containerName);
                }
            });
        } catch (IOException e) {
            LOGGER.warn("Failed to read from container file {}: " + containerName, e);
            return ResponseEntity.status(INTERNAL_SERVER_ERROR)
                    .body("Failed to open container of name " + containerName);
        }
    }).orElse(ResponseEntity.badRequest().body("No container deployed under the name " + containerName));
}

From source file:com.crossover.trial.weather.endpoint.RestWeatherCollectorEndpoint.java

@RequestMapping(path = "/collect/airport/{iata}/{lat}/{long:.+}", method = POST, produces = "application/json")
@ApiResponses({ @ApiResponse(code = 201, message = "Created"),
        @ApiResponse(code = 400, message = "Bad Request") })
public ResponseEntity<Airport> registerAirport(@PathVariable("iata") IATA iata,
        @PathVariable("lat") double latitude, @PathVariable("long") double longitude) {
    Assert.isTrue(iata != null);/*from w  ww  .  ja v a2  s  . c om*/

    return ResponseEntity.status(HttpStatus.CREATED).body(airportRepository.save(
            new Airport.Builder().withIata(iata).withLatitude(latitude).withLongitude(longitude).build()));
}

From source file:com.github.lynxdb.server.api.http.handlers.EpQuery.java

@RequestMapping(path = "/exp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity exp() {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

From source file:jp.classmethod.aws.brian.web.TriggerController.java

/**
 * Delete specified triggerGroup (belonging triggers).
 * //from   w  ww.  ja v  a 2  s  . com
 * @param triggerGroupName trigger group name
 * @return wherther the trigger is removed
 * @throws SchedulerException
 */
@ResponseBody
@RequestMapping(value = "/triggers/{triggerGroupName}/", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteTriggerGroup(@PathVariable("triggerGroupName") String triggerGroupName)
        throws SchedulerException {
    logger.info("deleteTriggerGroup {}", triggerGroupName);

    List<String> triggers = listTriggers(triggerGroupName);
    Set<String> failed = triggers.stream().filter(triggerName -> {
        TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
        try {
            return scheduler.unscheduleJob(triggerKey) == false;
        } catch (SchedulerException e) {
            logger.error("unexpected", e);
        }
        return false;
    }).collect(Collectors.toSet());

    if (failed.isEmpty()) {
        return ResponseEntity.ok(triggers);
    }
    Map<String, Object> map = new HashMap<>();
    map.put("failed", failed);
    map.put("deleted", triggers.stream().filter(t -> failed.contains(t) == false).collect(Collectors.toList()));
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
            .body(new BrianResponse<>(false, "failed to unschedule", map));
}

From source file:com.github.lynxdb.server.api.http.handlers.EpQuery.java

@RequestMapping(path = "/gexp", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity gexp() {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}