0

This is in a reference of

Return HTTP error from RESTeasy interface

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. 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 ?

Thank you

0

1 Answer 1

2

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. You need to check the http status value vs 403.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.