0

I am using jaxrs 2.0 & am trying to populate an object in the ContainerRequestContext & retrive it in the business logic.

I am populating the object in the ContainerRequestContext like :

 @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {

        MyObject myObject = new MyObject(); 
        requestContext.setProperty("myObject", myObject);
}

And I am trying to read it in the business logic like :

@GET
@Path("/custom")
public String data(@Context ContainerRequestContext crc) {
    Object pco = crc.getProperty("myObject");
}

I am using this approach from the example shared in : How to inject an object into jersey request context?

However I am getting the ContainerRequestContext crc as null. Can someone tell me what I could be doing wrong ?

Suraj Menon
  • 1,486
  • 3
  • 28
  • 50
  • This works fine for me on weblogic 12.2.1 (Full Java EE 7). Can you give more info about server, `@ApplicationPath`, etc. – Rouliboy May 24 '17 at 11:12
  • I encountered this while testing using arquillian – Suraj Menon May 24 '17 at 11:31
  • Ok, you should give more information in your description as it is not obvious that it occurs during tests, so the problem is not the same. I don't know Arquillian that much so I can't help you. – Rouliboy May 24 '17 at 11:43
  • The ability to inject the ContainerRequestContext like this, I think is specific to Jersey. So if your backend is not using Jersey, then it may not work. For example arquillian with JBoss may not work, as JBoss uses RESTEasy. Glassfish or Weblogic uses Jersey. – Paul Samsotha May 25 '17 at 00:40

1 Answers1

0

I have tested the exact code asked in the question which works as it is with following setup: spring-boot-starter-parent: 2.3.4.RELEASE spring-boot-starter: inherited from parent spring-boot-starter-jersey: inherited from parent which evaluates to Spring 5.2.9.RELEASE, Jersey 2.30.1

Arquillian with Jersey can work.

Aman
  • 21
  • 3
  • This does not provide an answer to the question, please read the [tour](https://stackoverflow.com/tour) – adrisons May 31 '21 at 10:57