aspose file tools*
The moose likes Servlets and the fly likes how to inject a resource using custom annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to inject a resource using custom annotation" Watch "how to inject a resource using custom annotation" New topic
Author

how to inject a resource using custom annotation

shwetank singh
Greenhorn

Joined: Apr 02, 2007
Posts: 26
Hello Ranchers!

Please help understand how can i use a custom annotation to inject ServletRequest into an object.
is this understanding i have correct? :
a) only resources managed by container can be derived or injected
b) if i define an annotation, i should have the annotation processor for it
c) i need something like:


where myAnnotation should be able to inject ServletRequest into myRequest

now,
1) is my understanding correct?
2) if it is, how to achieve this, how do i wire it together?
3) how is annotation state maintained?
4) can i guarantee each object will receive its own copy from container, with its association to servlet request?

please move the post to correct module, i can't see something dedicated to annotations.

help! : )
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

As far as I know, the only way to wrap ServletRequest (and ServletResponse) is to perform the wrapping inside a Filter. You there create an instance of a ServetRequestWrapper / HttpServletRequestWrapper sub class and pass that as the first argument to the FilterChain's doFilter method:
You then need to make sure this filter's called for each request you want it to be called for; applying it in the web.xml file for url-pattern /* should take care of that.

I'll move this thread to our Servlets forum, as I think that's a better location for it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shwetank singh
Greenhorn

Joined: Apr 02, 2007
Posts: 26
Thanks Rob!
Yes i agree we can use a filter and then use the cascaded request object. The problem is, the architecture i am dealing with for this problem won't hand over the object passed this way (or any other manner).
i am specifically looking to implement injection based mechanisms for this. i think this request object can be derived from container and added to a state which can then be injected anywhere i wish to.
the problem is i am unable to figure that out : )
Much thanks for help!
 
 
subject: how to inject a resource using custom annotation