org.springframework.http.ResponseEntity.status()

Here are the examples of the java api org.springframework.http.ResponseEntity.status() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1810 Examples 7

19 View Source File : DockerhealthcheckApplication.java
License : Apache License 2.0
Project Creator : zq2599

@RequestMapping(value = "/getstate", method = RequestMethod.GET)
public ResponseEnreplacedy<String> getState() {
    if (isHealth) {
        log.info("step probe return success");
        return ResponseEnreplacedy.status(200).build();
    } else {
        log.info("step probe return fail");
        return ResponseEnreplacedy.status(403).build();
    }
}

19 View Source File : LimiterExceptionAdvice.java
License : MIT License
Project Creator : zidoshare

@ExceptionHandler(LimiterException.clreplaced)
@OriginalResponse
public ResponseEnreplacedy<Object> handleLimiterException(LimiterException e) {
    return ResponseEnreplacedy.status(HttpStatus.TOO_MANY_REQUESTS).body(factory.error(CommonErrorCode.LIMIT, e.getMessage()));
}

19 View Source File : UserController.java
License : Apache License 2.0
Project Creator : zhuoqianmingyue

/**
 * 添加用户
 */
@PostMapping("/")
public ResponseEnreplacedy<User> add(@Valid User user) {
    log.info("添加用户成功:" + "name:{},age:{}", user.getName(), user.getAge());
    return ResponseEnreplacedy.status(HttpStatus.CREATED).body(user);
}

19 View Source File : CustomWebResponseExceptionTranslator.java
License : Apache License 2.0
Project Creator : zhoutaoo

@Override
public ResponseEnreplacedy<OAuth2Exception> translate(Exception e) {
    OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
    return ResponseEnreplacedy.status(oAuth2Exception.getHttpErrorCode()).body(new CustomOauthException(oAuth2Exception));
}

19 View Source File : FileUtil.java
License : MIT License
Project Creator : zhaojun1998

public static ResponseEnreplacedy<Object> export(File file) {
    if (!file.exists()) {
        return ResponseEnreplacedy.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND");
    }
    MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
    HttpHeaders headers = new HttpHeaders();
    headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
    headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName()));
    headers.add("Pragma", "no-cache");
    headers.add("Expires", "0");
    headers.add("Last-Modified", new Date().toString());
    headers.add("ETag", String.valueOf(System.currentTimeMillis()));
    return ResponseEnreplacedy.ok().headers(headers).contentLength(file.length()).contentType(mediaType).body(new FileSystemResource(file));
}

19 View Source File : FileUtil.java
License : MIT License
Project Creator : zhaojun1998

public static ResponseEnreplacedy<Object> export(File file, String fileName) {
    if (!file.exists()) {
        return ResponseEnreplacedy.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND");
    }
    MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
    HttpHeaders headers = new HttpHeaders();
    headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
    if (StringUtils.isNullOrEmpty(fileName)) {
        fileName = file.getName();
    }
    headers.setContentDispositionFormData("attachment", URLUtil.encode(fileName));
    headers.add("Pragma", "no-cache");
    headers.add("Expires", "0");
    headers.add("Last-Modified", new Date().toString());
    headers.add("ETag", String.valueOf(System.currentTimeMillis()));
    return ResponseEnreplacedy.ok().headers(headers).contentLength(file.length()).contentType(mediaType).body(new FileSystemResource(file));
}

19 View Source File : MssWebResponseExceptionTranslator.java
License : MIT License
Project Creator : yuuki80code

@Override
public ResponseEnreplacedy translate(Exception e) {
    ResponseEnreplacedy.BodyBuilder status = ResponseEnreplacedy.status(HttpStatus.OK);
    Response response = new Response();
    response.setCode(Response.FAILD_CODE);
    String message = "认证失败";
    log.error(message, e);
    if (e instanceof UnsupportedGrantTypeException) {
        message = "不支持该认证类型";
        response.setMsg(message);
        return status.body(response);
    }
    if (e instanceof InvalidGrantException) {
        if (StringUtils.containsIgnoreCase(e.getMessage(), "Invalid refresh token")) {
            message = "refresh token无效";
            response.setMsg(message);
            return status.body(response);
        }
        if (StringUtils.containsIgnoreCase(e.getMessage(), "locked")) {
            message = "用户已被锁定,请联系管理员";
            response.setMsg(message);
            return status.body(response);
        }
        message = e.getMessage();
        response.setMsg(message);
        return status.body(response);
    }
    response.setMsg(message);
    return status.body(response);
}

19 View Source File : ResponseEntityPro.java
License : Apache License 2.0
Project Creator : yujunhao8831

private static ResponseEnreplacedy.BodyBuilder buildStatus(int status) {
    return ResponseEnreplacedy.status(status);
}

19 View Source File : ResultErrorController.java
License : Apache License 2.0
Project Creator : yl-yue

@Override
public ResponseEnreplacedy<Map<String, Object>> error(HttpServletRequest request) {
    Throwable error = errorAttributes.getError(new ServletWebRequest(request));
    Result<?> result = R.getResult(error);
    if (error != null) {
        log.debug("【异常响应控制器】拦截到异常类型:{},异常信息:{},处理后响应内容:{}", error.getClreplaced().getName(), error.getMessage(), result);
    } else {
        log.debug("【异常响应控制器】拦截到异常类型:{},异常信息:{},处理后响应内容:{}", 404, result.getMsg(), result);
    }
    return ResponseEnreplacedy.status(result.getCode()).body(Convert.toJSONObject(result));
}

19 View Source File : Result.java
License : Apache License 2.0
Project Creator : yl-yue

// -------- result convert --------
public ResponseEnreplacedy<Result<?>> castToResponseEnreplacedy() {
    return ResponseEnreplacedy.status(getCode()).body(this);
}

19 View Source File : ParticleController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("verify3")
public ResponseEnreplacedy<String> verify3(String phone) throws Throwable {
    // 先请求重复检查
    return barrierLimiter.limit(phone, 60L, (particle) -> {
        // 判断是否被限制
        if (particle.isLimited()) {
            // 如果是去重限制类型
            if (particle.getType() == IdempotentLimiter.clreplaced) {
                return ResponseEnreplacedy.status(406).body("请求勿重复请求");
            } else if (particle.getType() == TimesLimiter.clreplaced) {
                // 次数限制类型
                return ResponseEnreplacedy.status(406).body("超过使用次数:" + particle.getValue() + "次");
            }
        }
        // 模拟业务处理耗时
        Thread.sleep(6000);
        return ResponseEnreplacedy.ok("发送成功,当前次数:" + particle.getValue());
    });
}

19 View Source File : ParticleController.java
License : MIT License
Project Creator : yizzuide

// 基于注解的拦截链组合方式
@RequestMapping("verify2")
@Limit(name = "user:send", key = "#phone", expire = 60L, limiterBeanClreplaced = BarrierLimiter.clreplaced)
public ResponseEnreplacedy<String> verify2(String phone, Particle particle) throws /*这个状态值自动注入*/
Throwable {
    log.info("verify2: phone={}", phone);
    // 判断是否被限制
    if (particle.isLimited()) {
        // 如果是去重限制类型
        if (particle.getType() == IdempotentLimiter.clreplaced) {
            return ResponseEnreplacedy.status(406).body("请求勿重复请求");
        } else if (particle.getType() == TimesLimiter.clreplaced) {
            // 次数限制类型
            return ResponseEnreplacedy.status(406).body("超过使用次数:" + particle.getValue() + "次");
        }
    }
    // 模拟业务处理耗时
    Thread.sleep(5000);
    return ResponseEnreplacedy.ok("发送成功,当前次数:" + particle.getValue());
}

19 View Source File : ParticleController.java
License : MIT License
Project Creator : yizzuide

// 方法嵌套调用的组合方式
@RequestMapping("verify")
public ResponseEnreplacedy<String> verify(String phone) throws Throwable {
    // 先请求重复检查
    return idempotentLimiter.limit(phone, 60L, (particle) -> {
        // 判断是否被限制
        if (particle.isLimited()) {
            return ResponseEnreplacedy.status(406).body("请求勿重复请求");
        }
        // 再检测次数
        return timesLimiter.limit(phone, (p) -> {
            if (p.isLimited()) {
                return ResponseEnreplacedy.status(406).body("超过使用次数:" + p.getValue() + "次");
            }
            // 模拟业务处理耗时
            Thread.sleep(5000);
            return ResponseEnreplacedy.ok("发送成功,当前次数:" + p.getValue());
        });
    });
}

19 View Source File : NeutronController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("add")
public ResponseEnreplacedy<?> add() {
    Neutron.addJob(jobName, NeutronJob.clreplaced, "1/5 * * * * ?");
    // 动态添加实现
    // String clazzName = 从数据库读取配置的clreplaced
    // Clreplaced clazz = Clreplaced.forName(clazzName)
    // Neutron.addJob(jobName, (Clreplaced<? extends Job>)clazz, "1/5 * * * * ?")
    return ResponseEnreplacedy.status(HttpStatus.OK).build();
}

19 View Source File : NeutronController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("update")
public ResponseEnreplacedy<?> update() {
    Neutron.modifyJobTime(jobName, "* * * * * ?");
    return ResponseEnreplacedy.status(HttpStatus.OK).build();
}

19 View Source File : NeutronController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("remove")
public ResponseEnreplacedy<?> remove() {
    Neutron.removeJob(jobName);
    return ResponseEnreplacedy.status(HttpStatus.OK).build();
}

19 View Source File : NeutronController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("startNow")
public ResponseEnreplacedy<?> startNow() {
    Neutron.startJobNow(jobName);
    return ResponseEnreplacedy.status(HttpStatus.OK).build();
}

19 View Source File : OrderController.java
License : MIT License
Project Creator : yizzuide

@RequestMapping("del")
public ResponseEnreplacedy<?> del(String orderId) {
    orderService.deleteById(orderId);
    return ResponseEnreplacedy.status(200).build();
}

19 View Source File : PulsarRunner.java
License : MIT License
Project Creator : yizzuide

/**
 * 对线程调度运行方法增强,使用装饰模式来支持统一捕获异常
 */
@Override
public void run() {
    try {
        Object value = callable.call();
        deferredResult.setResult(Optional.ofNullable(value).orElse(ResponseEnreplacedy.status(HttpStatus.OK).build()));
    } catch (Exception e) {
        log.error("pulsar:- PulsarRunner catch a error with message: {} ", e.getMessage(), e);
        if (null != deferredResult && null != PulsarHolder.getErrorCallback()) {
            deferredResult.setErrorResult(PulsarHolder.getErrorCallback().apply(e));
        }
    }
}

19 View Source File : ConfigMapResource.java
License : Apache License 2.0
Project Creator : xm-online

@PutMapping(value = "/config")
@Timed
public ResponseEnreplacedy<Void> updateConfiguration(@RequestBody Configuration configuration, @RequestParam(name = OLD_CONFIG_HASH, required = false) String oldConfigHash) {
    try {
        configurationService.updateConfiguration(configuration, oldConfigHash);
    } catch (ConcurrentConfigModificationException e) {
        log.warn("Error update configuration", e);
        return ResponseEnreplacedy.status(CONFLICT).build();
    }
    return ResponseEnreplacedy.ok().build();
}

19 View Source File : LoginController.java
License : MIT License
Project Creator : woowacourse-teams

@GetMapping("/check")
public ResponseEnreplacedy<JwtTokenResponse> loginCheck(@RequestParam(value = "access_token", required = false) final String token, @RequestParam final boolean success, @RequestParam(value = "is_created") final boolean isCreated) {
    if (success) {
        return ResponseEnreplacedy.ok(JwtTokenResponse.of(token, isCreated));
    }
    return ResponseEnreplacedy.status(HttpStatus.UNAUTHORIZED).build();
}

19 View Source File : AppController.java
License : MIT License
Project Creator : woowacourse-teams

@GetMapping("/races/{raceId}")
public ResponseEnreplacedy<Void> redirectRacePage(@PathVariable final String raceId, final HttpServletResponse response) throws IOException {
    response.sendRedirect(String.format("intent:#Intent;scheme=peloton:///home/races/%s;package=com.woowaguys.peloton;end", raceId));
    return ResponseEnreplacedy.status(HttpStatus.FOUND).build();
}

19 View Source File : ApiGlobalExceptionHandler.java
License : Apache License 2.0
Project Creator : webauthn4j

@Override
protected ResponseEnreplacedy<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
    final Object apiError;
    if (body == null) {
        // exceptionCodeResolver.resolveExceptionCode(ex);
        String errorCode = "";
        apiError = createApiError(request, errorCode, ex.getLocalizedMessage());
    } else {
        apiError = body;
    }
    return ResponseEnreplacedy.status(status).headers(headers).body(apiError);
}

19 View Source File : AuthPwdController.java
License : Apache License 2.0
Project Creator : WeBankFinTech

@RequestMapping(value = "/encrypt", method = RequestMethod.POST)
public ResponseEnreplacedy<String> encrypt(@RequestBody Map<String, String> map) {
    String srcPwd = map.get(ENCRYPT_PWD_KEY);
    if (StringUtils.isBlank(srcPwd)) {
        return ResponseEnreplacedy.status(403).body("");
    }
    String encryptPwd = "";
    try {
        String keyContent = FileCopyUtils.copyToString(new BufferedReader(new InputStreamReader(new FileInputStream(secretKeyPath))));
        if (StringUtils.isNotBlank(keyContent)) {
            encryptPwd = AESUtils.encrypt(srcPwd, Base64.getDecoder().decode(keyContent));
        } else {
            return ResponseEnreplacedy.status(500).body("");
        }
    } catch (Exception e) {
        LOG.error(e.getMessage());
        return ResponseEnreplacedy.status(500).body("");
    }
    return ResponseEnreplacedy.ok(encryptPwd);
}

19 View Source File : CustomRestTemplate.java
License : GNU General Public License v3.0
Project Creator : voyages-sncf-technologies

private <T> ResponseEnreplacedy<T> wrapForEnreplacedy(ResponseEnreplacedy<String> stringResponseEnreplacedy, Type responseType) {
    ResponseEnreplacedy<T> responseEnreplacedy = ResponseEnreplacedy.status(stringResponseEnreplacedy.getStatusCodeValue()).headers(stringResponseEnreplacedy.getHeaders()).body(this.wrap(stringResponseEnreplacedy.getBody(), responseType));
    testContext.setResponseEnreplacedy(responseEnreplacedy);
    return responseEnreplacedy;
}

@ExceptionHandler({ ForbiddenOperationException.clreplaced, AccessDeniedException.clreplaced })
public ResponseEnreplacedy handleForbidden(Exception exception) {
    beforeHandling(exception);
    return ResponseEnreplacedy.status(HttpStatus.FORBIDDEN).body(exception.getMessage());
}

19 View Source File : OpenOAuth2WebResponseExceptionTranslator.java
License : MIT License
Project Creator : uhonliu

@Override
public ResponseEnreplacedy translate(Exception e) {
    HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
    ResultBody responseData = OpenGlobalExceptionHandler.resolveException(e, request.getRequestURI());
    return ResponseEnreplacedy.status(responseData.getHttpStatus()).body(responseData);
}

19 View Source File : ResponseFactory.java
License : Apache License 2.0
Project Creator : turms-im

public static <T> ResponseEnreplacedy<ResponseDTO<Collection<T>>> okIfTruthy(Collection<T> data) {
    if (data != null) {
        if (data.isEmpty()) {
            return ResponseEnreplacedy.status(TurmsStatusCode.NO_CONTENT.getHttpStatusCode()).body(new ResponseDTO<>(TurmsStatusCode.NO_CONTENT, null));
        } else {
            return ResponseEnreplacedy.ok(new ResponseDTO<>(TurmsStatusCode.OK, data));
        }
    } else {
        return ResponseEnreplacedy.status(TurmsStatusCode.NO_CONTENT.getHttpStatusCode()).body(new ResponseDTO<>(TurmsStatusCode.NO_CONTENT, null));
    }
}

19 View Source File : MottoController.java
License : MIT License
Project Creator : TrainingByPackt

/**
 * Append to list of mottos, but only if the motto is unique
 */
@PostMapping
public ResponseEnreplacedy<Message> uniqueAppend(@RequestBody Message message, UriComponentsBuilder uriBuilder) {
    // Careful, this lookup is O(n)
    if (motto.contains(message)) {
        return ResponseEnreplacedy.status(HttpStatus.CONFLICT).build();
    } else {
        motto.add(message);
        UriComponents location = MvcUriComponentsBuilder.fromMethodCall(on(MottoController.clreplaced).retrieveById(motto.size())).build();
        return ResponseEnreplacedy.created(location.toUri()).header("X-Copyright", "Packt 2018").body(new Message("Accepted #" + motto.size()));
    }
}

19 View Source File : MottoController.java
License : MIT License
Project Creator : TrainingByPackt

/**
 * Append to list of mottos, but only if the motto is unique
 */
@PostMapping
public ResponseEnreplacedy<Message> uniqueAppend(@RequestBody Message message, UriComponentsBuilder uriBuilder) {
    // Careful, this lookup is O(n)
    if (motto.contains(message)) {
        return ResponseEnreplacedy.status(HttpStatus.CONFLICT).build();
    } else {
        motto.add(message);
        URI location = uriBuilder.path("/api/mottos/{id}").build(motto.size());
        return ResponseEnreplacedy.created(location).header("X-Copyright", "Packt 2018").body(new Message("Accepted #" + motto.size()));
    }
}

19 View Source File : ExampleController.java
License : Apache License 2.0
Project Creator : tomsun28

@GetMapping("/auth/error")
public ResponseEnreplacedy<String> authError(@RequestHeader(value = "statusCode") String statusCode, @RequestHeader(value = "errorMsg") String errorMsg) {
    return ResponseEnreplacedy.status(Integer.parseInt(statusCode)).body(cleanXss(errorMsg));
}

19 View Source File : DirectoryService.java
License : Apache License 2.0
Project Creator : tmobile

/**
 * Search the LDAP with displayName.
 * @param ntId
 * @return
 */
public ResponseEnreplacedy<DirectoryObjects> searchByDisplayNameAndId(String ntId) {
    DirectoryObjects objectsByDisplayName = searchBydisplayName(ntId);
    if (objectsByDisplayName.getData().getValues().length > 0) {
        return ResponseEnreplacedy.status(HttpStatus.OK).body(objectsByDisplayName);
    }
    DirectoryObjects objectsByCN = searchByNTId(ntId);
    return ResponseEnreplacedy.status(HttpStatus.OK).body(objectsByCN);
}

19 View Source File : UserController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 用户注册
 *
 * @param user
 * @param code
 * @return
 */
@PostMapping("/register")
public ResponseEnreplacedy<Void> register(@Valid User user, @RequestParam("code") String code) {
    Boolean boo = this.userService.register(user, code);
    if (boo == null || !boo) {
        return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).build();
    }
    return new ResponseEnreplacedy<>(HttpStatus.CREATED);
}

19 View Source File : UserController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 根据用户名和密码查询用户
 *
 * @param username
 * @param preplacedword
 * @return
 */
@GetMapping("/query")
public ResponseEnreplacedy<User> queryUser(@RequestParam("username") String username, @RequestParam("preplacedword") String preplacedword) {
    User user = this.userService.queryUser(username, preplacedword);
    if (user == null) {
        return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).build();
    }
    return ResponseEnreplacedy.ok(user);
}

19 View Source File : UserController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 校验数据是否可用
 * 实现用户数据的校验,主要包括对:手机号、用户名的唯一性校验
 *
 * @param data
 * @param type
 * @return
 */
@GetMapping("/check/{data}/{type}")
public ResponseEnreplacedy<Boolean> checkUserData(@PathVariable("data") String data, @PathVariable(value = "type") Integer type) {
    Boolean boo = this.userService.checkData(data, type);
    if (boo == null) {
        return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).build();
    }
    return ResponseEnreplacedy.ok(boo);
}

19 View Source File : GoodsController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 修改商品信息
 *
 * @param spuBo
 * @return
 */
@PutMapping("/goods")
public ResponseEnreplacedy<Void> updateGoods(@RequestBody SpuBo spuBo) {
    this.goodsService.updateGoods(spuBo);
    return ResponseEnreplacedy.status(HttpStatus.NO_CONTENT).build();
}

19 View Source File : CategoryController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 根据parentId父Id查询类目
 *
 * @param pid
 * @return
 */
@GetMapping("/list")
public ResponseEnreplacedy<List<Category>> queryCategoryListByParentId(@RequestParam(value = "pid", defaultValue = "0") Long pid) {
    try {
        if (pid == null || pid.longValue() < 0) {
            // pid为null或小于等于0,响应400
            return ResponseEnreplacedy.badRequest().build();
        }
        // 执行查询操作
        List<Category> categoryList = this.categoryService.queryCategoryListByParentId(pid);
        if (CollectionUtils.isEmpty(categoryList)) {
            // 返回结果集为空,响应404
            return ResponseEnreplacedy.notFound().build();
        }
        // 查询成功,响应200
        return ResponseEnreplacedy.ok(categoryList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 响应500
    return ResponseEnreplacedy.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}

19 View Source File : BrandController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 通过bid删除品牌
 * 删除tb_brand中的数据
 *
 * @param bid
 * @return
 */
@DeleteMapping("/{bid}")
public ResponseEnreplacedy<Void> deleteBrand(@PathVariable("bid") String bid) {
    this.brandService.deleteBrand(Long.parseLong(bid));
    return ResponseEnreplacedy.status(HttpStatus.OK).build();
}

19 View Source File : AuthController.java
License : Apache License 2.0
Project Creator : tiancixiong

/**
 * 验证用户信息
 *
 * @param token
 * @return
 */
@GetMapping("/verify")
public ResponseEnreplacedy<UserInfo> verifyUser(@CookieValue("LY_TOKEN") String token, HttpServletRequest request, HttpServletResponse response) {
    try {
        // 从token中解析token信息
        UserInfo userInfo = JwtUtils.getInfoFromToken(token, this.properties.getPublicKey());
        // 解析成功要重新刷新token
        token = JwtUtils.generateToken(userInfo, this.properties.getPrivateKey(), this.properties.getExpire());
        // 更新cookie中的token
        CookieUtils.setCookie(request, response, this.properties.getCookieName(), token, this.properties.getCookieMaxAge());
        // 解析成功返回用户信息
        return ResponseEnreplacedy.ok(userInfo);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 出现异常则,响应500
    return ResponseEnreplacedy.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}

19 View Source File : CustomerController.java
License : Apache License 2.0
Project Creator : testingisdocumenting

@PatchMapping("/customers/{id}")
public ResponseEnreplacedy<Customer> patchCustomer(@RequestBody Customer customer, @PathVariable long id) {
    Customer existing = customerRepository.findOne(id);
    if (existing == null) {
        return ResponseEnreplacedy.notFound().build();
    }
    if (null != customer.getFirstName()) {
        existing.setFirstName(customer.getFirstName());
    }
    if (null != customer.getLastName()) {
        existing.setLastName(customer.getLastName());
    }
    customerRepository.save(customer);
    return ResponseEnreplacedy.status(HttpStatus.NO_CONTENT).build();
}

19 View Source File : CustomerController.java
License : Apache License 2.0
Project Creator : testingisdocumenting

@PutMapping("/customers/{id}")
public ResponseEnreplacedy<Customer> updateCustomer(@RequestBody Customer customer, @PathVariable long id) {
    Customer existing = customerRepository.findOne(id);
    if (existing == null) {
        return ResponseEnreplacedy.notFound().build();
    }
    customer.setId(id);
    customerRepository.save(customer);
    return ResponseEnreplacedy.status(HttpStatus.OK).body(customer);
}

19 View Source File : CustomerController.java
License : Apache License 2.0
Project Creator : testingisdocumenting

@PostMapping("/customers")
public ResponseEnreplacedy<Customer> createCustomer(@RequestBody Customer customer) {
    return ResponseEnreplacedy.status(HttpStatus.CREATED).body(customerRepository.save(customer));
}

19 View Source File : ShipmentController.java
License : Apache License 2.0
Project Creator : teixeira-fernando

@ApiResponses(value = { @ApiResponse(code = 200, message = "Expected shipment order to a valid request", response = OrderShipment.clreplaced), @ApiResponse(code = 404, message = "Shipment order not found", response = Error.clreplaced), @ApiResponse(code = 500, message = "unexpected server error", response = Error.clreplaced) })
@GetMapping("/shipment/{id}")
public ResponseEnreplacedy<OrderShipment> getShipmentOrder(@PathVariable String id) {
    try {
        OrderShipment shipment = shipmentService.findById(id);
        return ResponseEnreplacedy.ok().header("Content-Type", "application/json").location(new URI("/shipment/" + shipment.getId())).body(shipment);
    } catch (NoSuchElementException e) {
        return ResponseEnreplacedy.notFound().build();
    } catch (URISyntaxException e) {
        return ResponseEnreplacedy.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}

19 View Source File : CarController.java
License : MIT License
Project Creator : swathisprasad

@RequestMapping(method = RequestMethod.POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public ResponseEnreplacedy uploadFile(@RequestParam(value = "files") MultipartFile[] files) {
    try {
        for (final MultipartFile file : files) {
            carService.saveCars(file.getInputStream());
        }
        return ResponseEnreplacedy.status(HttpStatus.CREATED).build();
    } catch (final Exception e) {
        return ResponseEnreplacedy.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}

19 View Source File : GlobalDefaultExceptionHandler.java
License : Apache License 2.0
Project Creator : suricate-io

/**
 * Manage the HttpRequestMethodNotSupportedException exception.
 * Throw when a user try to access a resource with a not supported Http Verb.
 *
 * @param exception The exception
 * @return The response
 */
@ExceptionHandler(HttpRequestMethodNotSupportedException.clreplaced)
public ResponseEnreplacedy<ApiErrorDto> handleRequestException(HttpRequestMethodNotSupportedException exception) {
    GlobalDefaultExceptionHandler.LOGGER.debug("An exception has occurred in the API controllers part", exception);
    return ResponseEnreplacedy.status(ApiErrorEnum.BAD_REQUEST.getStatus()).body(new ApiErrorDto(exception.getMessage(), ApiErrorEnum.BAD_REQUEST));
}

19 View Source File : ExceptionHandlers.java
License : MIT License
Project Creator : srcclr

// //////////////////////////////// Methods \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
@ExceptionHandler(BadCredentialsException.clreplaced)
public ResponseEnreplacedy<String> badCredentialsException(Exception ex) throws Exception {
    return ResponseEnreplacedy.status(HttpStatus.UNAUTHORIZED).contentType(MediaType.APPLICATION_JSON).body(buildJsonStringMessage("Unauthorized", ex.getMessage()));
}

19 View Source File : HelloController.java
License : Apache License 2.0
Project Creator : springdoc

@PostMapping(value = "/helloworld", produces = "application/json", consumes = "application/vnd.v2+json")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Successful operation", content = @Content(schema = @Schema(implementation = HelloDTO2.clreplaced))), @ApiResponse(responseCode = "400", description = "Bad name", content = @Content(schema = @Schema(implementation = ErrorDTO.clreplaced))) })
public ResponseEnreplacedy<?> hello(@RequestBody RequestV2 request) {
    final String name = request.getNameV2();
    if ("error".equalsIgnoreCase(name)) {
        return ResponseEnreplacedy.status(HttpStatus.BAD_REQUEST).body(new ErrorDTO("invalid name: " + name));
    }
    return ResponseEnreplacedy.ok(new HelloDTO2("Greetings from Spring Boot v2! " + name));
}

19 View Source File : HelloController.java
License : Apache License 2.0
Project Creator : springdoc

@Operation(description = "Download file")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "File resource", content = @Content(schema = @Schema(implementation = java.io.File.clreplaced))), @ApiResponse(responseCode = "400", description = "Wrong request", content = @Content(schema = @Schema(implementation = java.lang.Error.clreplaced))), @ApiResponse(responseCode = "500", description = "Unexpected error", content = @Content(schema = @Schema(implementation = java.lang.Error.clreplaced))) })
@GetMapping(value = "/file", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEnreplacedy<java.io.File> getFile(@NotNull @Parameter(description = "File path", required = true) @Valid @RequestParam(value = "path") String path) {
    return ResponseEnreplacedy.status(HttpStatus.NOT_IMPLEMENTED).build();
}

19 View Source File : ExceptionTranslator.java
License : Apache License 2.0
Project Creator : springdoc

private ResponseEnreplacedy<ErrorMessage> error(HttpStatus status, Exception e) {
    LOGGER.error("Exception : ", e);
    return ResponseEnreplacedy.status(status).body(new ErrorMessage(UUID.randomUUID().toString(), e.getMessage()));
}

19 View Source File : ExceptionTranslator.java
License : Apache License 2.0
Project Creator : springdoc

@SuppressWarnings("rawtypes")
@ExceptionHandler(TweetConflictException.clreplaced)
@ResponseStatus(HttpStatus.CONFLICT)
public ResponseEnreplacedy handleDuplicateKeyException(TweetConflictException ex) {
    return ResponseEnreplacedy.status(HttpStatus.CONFLICT).body(new ErrorResponse("A Tweet with the same text already exists"));
}

See More Examples