1

我正在使用 RESTEASY 开发 Web 服务,以在遇到异常时设置响应状态代码。首先,我尝试了在本地运行良好的 resteasy 异常映射器。下面附上映射器代码。但是,当我将该 WS 上传到弹性 beantalk 时,总是返回 500(内部服务器错误)。

@Provider
public class LoadGridTileFailedExceptionMapper extends BaseExceptionMapper implements ExceptionMapper<LoadGridTileFailedException>
{
@Override
public Response toResponse(LoadGridTileFailedException e)
{
    log(e.getMessage(), e);
    return printMsg(e.getMessage(), DtmWebServiceReturnStatus.LOAD_GRID_TILE_FAILED_EXCEPTION_CODE);
}
}

然后我尝试抛出异常 WebApplicationException(ex, DtmWebServiceReturnStatus.LOAD_GRID_TILE_FAILED_EXCEPTION_CODE) 来绕过异常映射。结果是我得到了响应状态 498(LOAD_GRID_TILE_FAILED_EXCEPTION_CODE) 包裹在状态代码 500 中。

Apache Tomcat/7.0.27 - 错误报告

HTTP 状态 498 -

类型状态报告

信息

说明http.498

Apache Tomcat/7.0.27

似乎弹性 beanstalk 包装了服务器端抛出的所有异常,状态码为 500?问题是如何绕过该功能并返回我设置的状态码作为响应?谢谢你。


更新

今天早上尝试更多请求,发现一些有趣的东西:

在弹性 beantalk 日志快照中获取正确的返回状态

/var/log/tomcat7/localhost_access_log.txt

127.0.0.1 - - [09/Jan/2013:15:06:28 +0000] “GET /published/tile/003331330031 HTTP/1.1”498 22 127.0.0.1 - - [09/Jan/2013:15:06: 31 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:34 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:37 +0000] “GET /published/tile/003331330031 HTTP/1.1”498 22 127.0.0.1 - - [09/Jan/2013:15: 06:39 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:41 +0000] "GET /published/tile/003331330031 HTTP/ 1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:44 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013: 15:06:48 +0000]“GET /published/tile/003331330031 HTTP/1.1”498 22 127.0.0.1 - - [2013 年 1 月 9 日:15:06:51 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:54 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 127.0.0.1 - - [09/Jan/2013:15:06:57 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22


/var/log/httpd/elasticbeanstalk-access_log

10.28.215.233 (65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:28 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28 .215.233 (65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:31 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28。 215.233 (65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:34 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:37 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 ( 65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:39 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167 .11.254, 10.28.215.233) - - [09/Jan/2013:15:06:41 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254 , 10.28.215.233) - - [09/Jan/2013:15:06:44 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254, 10.28.215.233) - - [09/Jan/2013:15:06:48 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254, 10.28 .215.233) - - [09/Jan/2013:15:06:51 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254, 10.28. 215.233) - - [09/Jan/2013:15:06:54 +0000] "GET /published/tile/003331330031 HTTP/1.1" 498 22 "-" "-" 10.28.215.233 (65.167.11.254, 10.28.215 .233) - - [09/Jan/2013:15:06:57 +0000]“GET /published/tile/003331330031 HTTP/1.1”498 22“-”“-”

但是在客户端,仍然有 500 :-(

printMsg 方法:

protected Response printMsg(String msg, int intStatus)
{
    // Need this due to the Resteasy bug
    ServiceDataCollector.processRequest(true);

    ResponseBuilder builder = Response.status(intStatus);
    builder.type("text/plain");
    builder.entity("ERROR: " + msg);
    Response rep = builder.build();
    LOG.error(rep.getStatus() + ":" + rep.toString());
    return rep;
}
4

1 回答 1

-1

有人帮我解决问题。我将 httpd 部署在我的 AMI 中,然后是 80 的 tomcat 服务器。因此负载均衡器将与 httpd 服务器交互,从而将状态代码从 tomcat 更改为 500。禁用该 httpd 服务器将解决问题。谢谢大家的帮助。

于 2013-01-12T21:28:30.253 回答