users@jersey.java.net

[Jersey] Re: Add attributes to Jersey Client Requests

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Thu, 31 Oct 2013 12:18:21 -0400

Hi Eric,

     I don't think you're guaranteed ordering for ContainerRequestFilter
but again you can find workarounds by specifying ordering in your
header, buffering the results on the server end, and then sending a
final header to re-organizing things. It sounds to me like you're well
on your way. Feel free to ask any other questions you might have.

Gili

On 31/10/2013 6:29 AM, Eric Stein wrote:
> No, sorry, I was confusing. I'm using ResourceConfig to specify what folders to scan for Jersey annotations. I stick an @Provider on my ContainerRequestFilter and specify it's package in the ResourceConfig, then Jersey loads it up automagically. I could (should?) have left off 2. My real issue is specifying the ordering if there are multiple instances of ContainerRequestFilter.
>
> Eric
>
> -----Original Message-----
> From: cowwoc [mailto:cowwoc_at_bbs.darktech.org]
> Sent: Thursday, October 31, 2013 12:18 AM
> To: users_at_jersey.java.net
> Subject: [Jersey] Re: Add attributes to Jersey Client Requests
>
> Hi Eric,
>
> Something doesn't make sense here. ResourceConfig is initialized once across the lifetime of your application. This occurs before any HTTP request so you don't have access to HTTP headers.
>
> If you're trying to pass initialization parameters to the server at startup, take a look at this issue:
> http://stackoverflow.com/q/19596592/14731
>
> Some solutions have been proposed on the list (most notably using JNDI or other singletons) but don't consider them a clean solution. I'm still looking for a way to read servlet init parameters from ResourceConfig.
>
> Gili
>
> On 30/10/2013 8:14 PM, Eric Stein wrote:
>> Yes, I'm trying to get a value to be returned from HttpServletRequest#getAttribute().
>>
>> It sounds like I need to:
>> 0. Have my unit tests include a HTTP header, say X-userid.
>> 1. Put a ContainerRequestFilter in my src/test/java/... package which turns the header into an attribute.
>> 2. Set up my ResourceConfig to scan that package.
>>
>> Is that what you're proposing?
>>
>> Let's say I have another ContainerRequestFilter which relies on that attribute being set. How do I make sure that the filters run in the order I need them to?
>>
>> Eric
>>
>> -----Original Message-----
>> From: cowwoc [mailto:cowwoc_at_bbs.darktech.org]
>> Sent: Wednesday, October 30, 2013 8:04 PM
>> To: users_at_jersey.java.net
>> Subject: [Jersey] Re: Add attributes to Jersey Client Requests
>>
>> On 30/10/2013 7:52 PM, Eric Stein wrote:
>>> I'm trying to do some testing using the Jersey client. I would like to put an attribute into the request, but I don't see any way to do that in the documentation or the javadocs. An internet search was less than helpful. Is this possible?
>>>
>>> Thanks,
>>> Eric
>> What do you mean by "attribute"? Are you trying to set a value to be returned by ServletRequest.getAttribute()? If so, you cannot pass such values directly from client to server. These attributes must be set on the server side (perhaps using a request filter). One approach would be to pass HTTP headers from the client to server, intercept them in the request filter and pass them into the ServletRequest.setAttribute().
>>
>> Gili