Example usage for org.springframework.http HttpStatus BANDWIDTH_LIMIT_EXCEEDED

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

Introduction

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

Prototype

HttpStatus BANDWIDTH_LIMIT_EXCEEDED

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

Click Source Link

Document

509 Bandwidth Limit Exceeded

Usage

From source file:plbtw.klmpk.barang.hilang.controller.UserController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public CustomResponseMessage getAllUsers(@RequestHeader String apiKey) {
    try {/*from   w ww . ja  va2  s  .c o m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Get");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        List<User> allUsers = (List<User>) userService.getAllUsers();
        for (User user : allUsers) {
            Link selfLink = linkTo(UserController.class).withSelfRel();
            user.add(selfLink);
        }
        CustomResponseMessage result = new CustomResponseMessage();
        result.add(linkTo(UserController.class).withSelfRel());
        result.setHttpStatus(HttpStatus.ACCEPTED);
        result.setMessage("Success");
        result.setResult(allUsers);
        return result;
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public CustomResponseMessage /*Collection<Barang>*/ getAllBarang(@RequestHeader String apiKey) {
    try {//ww  w  . jav a2  s .c  om

        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }
        LogRequest temp = DependencyFactory.createLog(apiKey, "Get");

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }
        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        List<Barang> allBarang = (List<Barang>) barangService.getAllBarang();
        for (Barang barang : allBarang) {
            Link selfLink = linkTo(BarangController.class).withSelfRel();
            barang.add(selfLink);
        }
        CustomResponseMessage result = new CustomResponseMessage();
        result.add(linkTo(BarangController.class).withSelfRel());
        result.setHttpStatus(HttpStatus.FOUND);
        result.setMessage("Success");
        result.setResult(allBarang);
        return result;
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.FORBIDDEN, ex.getMessage());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.UserController.java

@RequestMapping(value = "/find/{id}", method = RequestMethod.GET, produces = "application/json")
public CustomResponseMessage getUser(@RequestHeader String apiKey, @PathVariable("id") long id) {
    try {//ww  w  . j  av  a2 s.  co m

        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Get");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        User user = userService.getUser(id);
        Link selfLink = linkTo(UserController.class).withSelfRel();
        user.add(selfLink);
        List<User> listUser = new ArrayList<User>();
        listUser.add(user);
        CustomResponseMessage result = new CustomResponseMessage();
        result.add(linkTo(UserController.class).withSelfRel());
        result.setHttpStatus(HttpStatus.ACCEPTED);
        result.setMessage("Success");
        result.setResult(listUser);
        return result;
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(value = "/find/{id}", method = RequestMethod.GET, produces = "application/json")
public CustomResponseMessage findBarang(@RequestHeader String apiKey, @PathVariable("id") long id) {
    try {/* ww w  . ja v a2 s .c  o m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }
        LogRequest temp = DependencyFactory.createLog(apiKey, "Get");

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        List<Barang> rsBarang = new ArrayList<>();
        Barang barang = barangService.getBarang(id);
        Link selfLink = linkTo(UserController.class).withSelfRel();
        barang.add(selfLink);
        rsBarang.add(barang);
        CustomResponseMessage result = new CustomResponseMessage();
        result.add(linkTo(BarangController.class).withSelfRel());
        result.setHttpStatus(HttpStatus.FOUND);
        result.setMessage("Success");
        result.setResult(rsBarang);
        return result;
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.getMessage());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.UserController.java

@RequestMapping(value = "/auth", method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage authLogin(@RequestHeader String apiKey,
        @RequestBody UserAuthRequest userAuthRequest) {
    try {/* w w w . j av  a 2s. c  o m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }
        LogRequest temp = DependencyFactory.createLog(apiKey, "Post");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        User user = userService.authLoginUser(userAuthRequest.getEmail(), userAuthRequest.getPassword());
        List<User> listUser = new ArrayList<User>();
        if (user == null) {
            return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Login Failed", listUser);
        }
        listUser.add(user);
        CustomResponseMessage result = new CustomResponseMessage();
        result.setResult(listUser);
        result.setHttpStatus(HttpStatus.ACCEPTED);
        result.setMessage("Auth Success");
        return result;
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, "Please use your api key to authentication");
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage addBarang(@RequestHeader String apiKey, @RequestBody BarangRequest barangRequest) {
    try {//from   w w w.j a v a  2 s . co  m
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Post");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        Barang barang = new Barang();
        barang.setJumlah(barangRequest.getJumlahBarang());
        barang.setKategoriBarang(kategoriBarangService.getKategoriBarang(barangRequest.getIdKategoriBarang()));
        barang.setNama(barangRequest.getNama());
        barang.setStatus(barangRequest.getStatus());
        barang.setUrl_image(barangRequest.getUrl_image());
        barang.setUser(userService.getUser(barangRequest.getIdUserPemilik()));
        barangService.addBarang(barang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Insert Success");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }

}

From source file:plbtw.klmpk.barang.hilang.controller.UserController.java

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage addUser(@RequestHeader String apiKey, @RequestBody UserRequest userRequest) {
    try {//from  w ww .  j  av  a  2  s  . c  o m
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Post");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        if (userService.checkUserExist(userRequest.getEmail()) != null) {
            return new CustomResponseMessage(HttpStatus.METHOD_NOT_ALLOWED, "Email Already Used");
        }

        User user = new User();
        user.setUsername(userRequest.getUsername());
        user.setEmail(userRequest.getEmail());
        user.setPassword(userRequest.getPassword());
        user.setAlamat(userRequest.getAlamat());
        user.setNoHp(userRequest.getNoHp());
        userService.addUser(user);
        return new CustomResponseMessage(HttpStatus.CREATED, "User Has Been Created");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.PUT, produces = "application/json")
public CustomResponseMessage updateBarang(@RequestHeader String apiKey,
        @RequestBody BarangRequest barangRequest) {
    try {//from w  ww . j a v  a 2 s  .  c om
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Put");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        Barang barang = barangService.getBarang(barangRequest.getId());
        barang.setJumlah(barangRequest.getJumlahBarang());
        barang.setKategoriBarang(kategoriBarangService.getKategoriBarang(barangRequest.getIdKategoriBarang()));
        barang.setNama(barangRequest.getNama());
        barang.setStatus(barangRequest.getStatus());
        barang.setUrl_image(barangRequest.getUrl_image());
        barang.setUser(userService.getUser(barangRequest.getIdUserPemilik()));
        barangService.updateBarang(barang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Update Barang Successfull");
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.UserController.java

@RequestMapping(method = RequestMethod.PUT, produces = "application/json")
public CustomResponseMessage updateUser(@RequestHeader String apiKey, @RequestBody UserRequest userRequest) {
    try {/*from   ww w .  j av  a2  s . c  o  m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Put");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        User userUpdate = userService.getUser(userRequest.getId());
        userUpdate.setUsername(userRequest.getUsername());
        userUpdate.setAlamat(userRequest.getAlamat());
        userUpdate.setEmail(userRequest.getEmail());
        userUpdate.setNoHp(userRequest.getNoHp());
        userUpdate.setPassword(userRequest.getPassword());
        userService.updateUser(userUpdate);
        return new CustomResponseMessage(HttpStatus.CREATED, "Update User successfuly");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.DELETE, produces = "application/json")
public CustomResponseMessage deleteBarang(@RequestHeader String apiKey,
        @RequestBody BarangRequest barangRequest) {
    try {/*from w ww . jav  a  2 s.co m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Delete");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);
        barangService.deleteBarang(barangRequest.getId());
        return new CustomResponseMessage(HttpStatus.CREATED, "Delete Barang successfull");
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}