【发布时间】:2016-11-16 09:22:17
【问题描述】:
一些背景信息:我的设置是browser -> api gateway -> ec2 (using spring mvc)。
我想返回 200 以外的 http 状态。在 google 中进行了大量搜索后,我知道我已经在 api gatway 上进行了一些配置。以下是我的配置:
- 在
Method Response中,添加http状态400 - 在
Integration Response->HTTP status regex,添加.*httpStatus":400.* - 在 ec2(使用 spring mvc)中,我总是返回 http 状态 400,并带有以下 json 作为响应体(用于测试)
{
"errorMessage": "{\"errorType\":\"Bad Request\",\"requestId\":\"12345\",\"httpStatus\":400,\"message\":\"你有错误\"}"
}
但是,当我测试 api 时(使用 api 网关中的“测试”按钮),它仍然返回 http 状态 200。(我希望它应该是 400)
当我将正则表达式更改为 .*400.* 时,它会按预期返回 http 状态 400。
当我将正则表达式更改为 .*httpStatus.* 时,它返回 http 状态 200。(我希望它应该是 400)
为什么正则表达式 .*httpStatus":400.* 不能识别我的 json?即使我将正则表达式简化为.*httpStatus.*。
但是正则表达式 .*400.* 可以识别 int 400 ...
PS:我永远不会忘记在 api 网关发生任何更改后部署 api
这是日志
Execution log for request test-request
Wed Jul 13 15:38:22 UTC 2016 : Starting execution for request: test-invoke-request
Wed Jul 13 15:38:22 UTC 2016 : HTTP Method: POST, Resource Path: /graphql
Wed Jul 13 15:38:22 UTC 2016 : Method request path: {}
Wed Jul 13 15:38:22 UTC 2016 : Method request query string: {}
Wed Jul 13 15:38:22 UTC 2016 : Method request headers: {}
Wed Jul 13 15:38:22 UTC 2016 : Method request body before transformations: null
Wed Jul 13 15:38:22 UTC 2016 : Endpoint request URI: http://awseb-e-e-AWSEBLoa-1OSQBKG0O3J75-968940376.ap-northeast-1.elb.amazonaws.com/graphql
Wed Jul 13 15:38:22 UTC 2016 : Endpoint request headers: {x-amzn-apigateway-api-id=kymhygbqwa, Accept=application/json, User-Agent=AmazonAPIGateway_kymhygbqwa}
Wed Jul 13 15:38:22 UTC 2016 : Endpoint request body after transformations: null
Wed Jul 13 15:38:22 UTC 2016 : Endpoint response body before transformations: {"errorMessage":"{\"errorType\":\"Bad Request\",\"requestId\":\"12345\",\"httpStatus\":400,\"message\":\"you got error\"}"}
Wed Jul 13 15:38:22 UTC 2016 : Endpoint response headers: {date=Wed, 13 Jul 2016 15:38:22 GMT, server=Apache-Coyote/1.1, expires=0, transfer-encoding=chunked, access-control-allow-headers=Origin, X-Requested-With, Content-Type, Accept, x-frame-options=DENY, access-control-allow-methods=POST, GET, PUT, OPTIONS, DELETE, pragma=no-cache, access-control-allow-origin=*, access-control-max-age=3600, x-content-type-options=nosniff, x-xss-protection=1; mode=block, content-type=application/json;charset=UTF-8, connection=keep-alive, cache-control=no-cache, no-store, max-age=0, must-revalidate}
Wed Jul 13 15:38:22 UTC 2016 : Method response body after transformations: {"errorMessage":"{\"errorType\":\"Bad Request\",\"requestId\":\"12345\",\"httpStatus\":400,\"message\":\"you got error\"}"}
Wed Jul 13 15:38:22 UTC 2016 : Method response headers: {Content-Type=application/json}
Wed Jul 13 15:38:22 UTC 2016 : Successfully completed execution
Wed Jul 13 15:38:22 UTC 2016 : Method completed with status: 200
【问题讨论】:
标签: amazon-web-services aws-api-gateway