假设客户进行Post调用而不是GET

时间:2017-10-24 02:40:29

标签: spring netflix-zuul spring-cloud-netflix netflix-feign spring-cloud-feign

我们正在使用netflix网关API,Zuul和Feign客户端。 我们为每个用户身份验证检查请求调用security-api。 在与远程休息客户端(用于验证令牌的微服务)通信时看到意外异常。

Caused by: feign.FeignException: status 405 reading RemoteSecurityAPI#validateToken(String); content:
{"timestamp":1508809658401,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request
method 'POST' not supported","path":"/api/v1//auth/validate/token"}
        at feign.FeignException.errorStatus(FeignException.java:62) ~[feign-core-9.5.0.jar!/:na]

public class AuthenticationPreZuulFilter extends ZuulFilter
{
    @Autowired
    RemoteSecurityAPI securityAPI;
    final RequestContext requestContext = RequestContext.getCurrentContext();
    final HttpServletRequest request = requestContext.getRequest();
    final String header = request.getHeader("Authorization");
    String authToken = header.substring(7);
    securityAPI.validateToken(authToken);
}

@FeignClient(name = "martmonkey-security-api")
public interface RemoteSecurityAPI
{
    @RequestMapping(method = RequestMethod.GET, value = "${jwt.route.authentication.validate}")
    public void validateToken(@Param("authToken") String authToken);
}

jwt.route.authentication.validate = / API / V1 // AUTH /验证/令牌?令牌= {}的authToken

zuul:
  #Service will be mapped under the /api URI
  prefix: /api/v1
  strip-prefix: false
  sensitiveHeaders: Cookie,Set-Cookie,Authorization
  routes:
    martmonkey-security-api:
      path: /auth/**
      strip-prefix: false
      sensitiveHeaders: Cookie,Set-Cookie,Authorization
      serviceId: martmonkey-security-api
    martmonkey-user-api:
      path: /users/**
      serviceId: martmonkey-user-api

jwt.route.authentication.validate = / AUTH /验证/令牌

@Consumes("application/json")
@Produces("application/json")
@RestController
@RequestMapping("/api/v1")
@Api(value="Security check.", description="Operations pertaining to login.")
public class AuthenticationResource
{
    @RequestMapping(method = RequestMethod.GET, value = "${jwt.route.authentication.validate}")
    public ResponseEntity<Void> validateToken(@QueryParam("token") final String authToken)
    {
    }
}

为什么网关api正在使用方法类型'post'发出请求,尽管我们已经说过使用“method = RequestMethod.GET”。

0 个答案:

没有答案