users@jersey.java.net

[Jersey] Re: Add attributes to Jersey Client Requests

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 5 Nov 2013 20:43:22 +0100

Assuming we're talking about Jersey 2.x / JAX-RS 2.0, you can use the standard javax.annotation.Priority annotation to set the provider (filter/interceptor) priority, e.g.:
https://jersey.java.net/documentation/latest/filters-and-interceptors.html#d0e6998

Marek

On 31 Oct 2013, at 11:29, Eric Stein <steine_at_locustec.com> 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
>