problems with passing url defined parameters through a forwarded intercept

70 views
Skip to first unread message

bailey

unread,
Apr 22, 2010, 5:48:12 PM4/22/10
to caelum-vraptor-en
I'm new to VRaptor and I encountered a problem.

I'm setting up a project where the second url parameter is the
identifier for the type of style sheet I'll be using. An example would
be /ccp/{customer.id}/home

I got that working correctly so I then installed a security
interceptor based on the one in the demo application.

public void intercept(InterceptorStack stack, ResourceMethod method,
Object resourceInstance)
throws InterceptionException {
/**
* You can use the result even in interceptors.
*/
if (info.getUser() == null) {
// remember added parameters will survive one more request, when
there is a redirect
result.include("errors", Arrays.asList(new
ValidationMessage("user is not logged in", "user")));
result.forwardTo(AccessController.class).login(null);
}
}

with AccessController.login(null) being:

public void login(Client client) {
result.include("clientId", client.getId());
}

What I was hoping would happen that when I called /ccp/{customer.id}/
home it would come back with a login page customized with the
customer.id. However, even though I can see the client.id being
populated in the logs it's not being passed through the Interceptor.
All attempts to call this results in an error as the Client is null.

TIA.


--
Subscription settings: http://groups.google.com/group/caelum-vraptor-en/subscribe?hl=en

Lucas Cavalcanti

unread,
Apr 22, 2010, 5:59:10 PM4/22/10
to caelum-v...@googlegroups.com
Do you need the client.id in order to go to login page?
Do all of your logics have a Client parameter?

If so, you can access the logic parameters (the objects) via MethodInfo#getParameters()
If not, you should redirect to a login page that doesn't depend on client, or redirect directly
to login page, without invoking the login logic:

result.of(AccessController).login(null);

[]'s
Lucas

bailey

unread,
Apr 22, 2010, 9:07:08 PM4/22/10
to caelum-vraptor-en
I need the client.id for the login page as the login page will look
substantially different depending on who the client is.

Can you give me an example of MethodInfo and where/how I can interact
with it? I checked the documentation and it doesn't mention it and the
code was sparse in details as well.

thanks.


On Apr 22, 5:59 pm, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> Do you need the client.id in order to go to login page?
> Do all of your logics have a Client parameter?
>
> If so, you can access the logic parameters (the objects) via
> MethodInfo#getParameters()
> If not, you should redirect to a login page that doesn't depend on client,
> or redirect directly
> to login page, without invoking the login logic:
>
> result.of(AccessController).login(null);
>
> []'s
> Lucas
>

Lucas Cavalcanti

unread,
Apr 22, 2010, 9:22:02 PM4/22/10
to caelum-v...@googlegroups.com
MethodInfo is a part of the VRaptor's internal API, so it will not be on the regular documentation,
and it lacks javadoc, sorry...

You can get an instance of MethodInfo via constructor:

public MyInterceptor(...., MethodInfo info) {
    this.info = info;
}

If you have the logic: public void myLogic(Client client),
info.getParameters() => [client]

i.e, info.getParameters() is the array of the populated parameters of your logic.

you can also receive an HttpServletRequest on your constructor, and use
request.getParameter("client.id")   -- even if this parameter comes from the URI

[]'s

bailey

unread,
Apr 25, 2010, 7:16:30 PM4/25/10
to caelum-vraptor-en
I really appreciate the help with this.

I tried using MethodInfo during the constructor and that didn't work.
The extra parameters didn't show up. The servlet request did work,
but that actually led me to a cleaner solution.
When I set up the servlet request , I realized what I was actually
receiving was the VRaptorRequest which contained the additional
parameter. I then tracked it and realized that in my view rendering
servlet I was receiving a VRapotorRequest as well.

The documentation seems to indicate that the only way you can add
values to the request is through a result.include() When in fact any
parameter defined in the URL is included as well, it's just not
necessarily converted into an object. So I may not have gotten an
object Client but I should have been receiving a String of client.id

That "client.id" still wasn't showing up, a little additional trouble
shooting led me to the realization that VRaptorRequest included these
as parameters and the servlet I had was looking at attributes.

So a little fiddling to look for clientId ( a string ) rather then an
object of client with a particular id. And a small change to pull in
parameters rather then attributes and everything looks good.

Thanks!
Reply all
Reply to author
Forward
0 new messages