ValidateCodeHandler.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.ruoyi.gateway.handler;
  2. import java.io.IOException;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.http.HttpStatus;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.web.reactive.function.BodyInserters;
  7. import org.springframework.web.reactive.function.server.HandlerFunction;
  8. import org.springframework.web.reactive.function.server.ServerRequest;
  9. import org.springframework.web.reactive.function.server.ServerResponse;
  10. import com.ruoyi.common.core.exception.CaptchaException;
  11. import com.ruoyi.common.core.web.domain.AjaxResult;
  12. import com.ruoyi.gateway.service.ValidateCodeService;
  13. import reactor.core.publisher.Mono;
  14. /**
  15. * 验证码获取
  16. *
  17. * @author ruoyi
  18. */
  19. @Component
  20. public class ValidateCodeHandler implements HandlerFunction<ServerResponse>
  21. {
  22. @Autowired
  23. private ValidateCodeService validateCodeService;
  24. @Override
  25. public Mono<ServerResponse> handle(ServerRequest serverRequest)
  26. {
  27. AjaxResult ajax;
  28. try
  29. {
  30. ajax = validateCodeService.createCaptcha();
  31. }
  32. catch (CaptchaException | IOException e)
  33. {
  34. return Mono.error(e);
  35. }
  36. return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
  37. }
  38. }