[英]resteasy return 403 not handle in junit
This is in a reference of 这是参考
Return HTTP error from RESTeasy interface 从RESTeasy界面返回HTTP错误
I am doing the same just for reference 我这样做只是为了参考
@Path("/foo")
public class FooBar {
@GET
@Path("/bar")
@Produces("application/json")
public Object testMethod(@HeaderParam("var_1") @DefaultValue("") String var1,
@HeaderParam("var_2") @DefaultValue("") String var2 {
if (var1.equals(var2)) {
return "All Good";
} else {
throw new WebApplicationException(HttpURLConnection.HTTP_FORBIDDEN);
}
}
}
But when it throws the error I can not catch it in my junit test. 但是当它抛出错误时我无法在我的junit测试中捕获它。 It is not comming in any asserts below.
它不会出现在下面的任何断言中。
@Test
@RunAsClient
public void test403() {
try {
Object obj = fooBarService.testMethod("test2", "test");
Assert.assertFalse(true);
} catch(WebApplicationException ex) {
Assert.assertTrue(true);
}
}
How to check the 403 ? 如何检查403?
Thank you 谢谢
The client doesn't get the exception - that is turned in to an HTTP STATUS = 403 that is part of the response object you get back from the request. 客户端没有得到异常 - 它被转入HTTP STATUS = 403,它是从请求中返回的响应对象的一部分。 You need to check the http status value vs 403.
您需要检查http状态值与403。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.