Extract query params before Resources are hit

4 views
Skip to first unread message

Xuemin Guan

unread,
Jul 1, 2014, 12:58:28 PM7/1/14
to utter...@googlegroups.com
hi all, hope someone can help me here.

I have a uri with a queryparam which looks like this:


What I want to do is to extract value of the queryparam name before any Resource is hit and have this value inject into the request scope, so that my resource can look like this:

public class GreetingResource {
   public GreetingResource(String name) {
         this.name = name;
   }

    @GET
    @Path("/GreetingResource")
    public Response sayHello() {
        return ResponseBuilder.response(OK).entity("hello " + name).build();
    }

}

The reason I want to do this is because I need to extract this value across the board for many methods on many resources. 

Can someone help me on this please?

Your help is much appreciated!

Xuemin

Matt Savage

unread,
Jul 1, 2014, 1:06:17 PM7/1/14
to utterlyidle

You can create a tiny type with an activator or constructor that depends on Request, then extract the query param value there. Is that what you're after?

--
You received this message because you are subscribed to the Google Groups "utterlyidle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to utterlyidle...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Xuemin (Shuemin) Guan

unread,
Jul 1, 2014, 1:28:18 PM7/1/14
to utter...@googlegroups.com
Matt, I think that would work! I will give it a go.

Thank you so much! The queryparam had your name in it, you just had to help me :)

Matt Savage

unread,
Jul 1, 2014, 2:58:54 PM7/1/14
to utterlyidle
You left me no choice there ;)
Reply all
Reply to author
Forward
0 new messages