0

当我尝试在服务器上使用 API 运行我的 Citrus v.2.7.5 测试时遇到问题,该服务器将自定义的 HTTP-Status-Codes 响应到我的 citrus 客户端。我的测试抛出 IllegalArgument 异常,因为服务器使用 520 Http-Status-Code 响应消息。

我认为问题在于 Citrus 使用的 spring-web v.4.3.14 框架。spring-web 包含一个带有有效状态码枚举的 HttpStatus 类。当您尝试为非“有效”的自定义状态代码创建 valueOf() 时,它将引发错误:

/**
 * Return the enum constant of this type with the specified numeric value.
 * @param statusCode the numeric value of the enum to be returned
 * @return the enum constant with the specified numeric value
 * @throws IllegalArgumentException if this enum has no constant for the specified numeric value
 */
public static HttpStatus valueOf(int statusCode) {
    HttpStatus status = resolve(statusCode);
    if (status == null) {
        throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
    }
    return status;

}

在 spring-web 的较新版本(5.x)中,此错误已修复,您可以使用自定义 http-status-codes 但 citrus 适用于此旧版本....也许我错了,异常被抛出到其他地方,但它与自定义的 http-status-code 有关,因为如果我们得到 200 HTTP-Status-code 一切正常。

有谁知道如何用柑橘解决这个问题?

4

0 回答 0