1

I don't know how to pass object data from container request filter to any other resources, by using CDI, because I cannot get my data in the resource. Any idea?

@Provider
public class AuthFilter implements ContainerRequestFilter {
    @Inject
    private SomeBean bean;

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        bean.setData("test");
    }
}

@ManagedBean
@RequestScoped
public class SomeBean
{
    private String data;

    public String getData() {
        return data;
    }
}

And in my resource class I have the following:

@Inject
private SomeBean bean;

@GET
public Response someMethod() {
    return Response.ok(bean.getData()).build();
}
duns
  • 83
  • 1
  • 16
  • I am guessing but one approach is to use `@SessionScoped` or `@ApplicationScoped` bean so that on injection the data will still be available. – Buhake Sindi Mar 09 '16 at 14:52
  • Just curious, what kind of *data* do you need to pass from a request filter to other resources? – cassiomolin Mar 09 '16 at 16:33
  • 1
    For example the current user logged in and the current organization data. I don't use principal and jaas to authenticate user – duns Mar 09 '16 at 17:08
  • 1
    This answer might be useful: http://stackoverflow.com/a/26778123/1426227 – cassiomolin Mar 09 '16 at 19:45

0 Answers0