How to properly handle request /<rootaction>/foo/bar?

7 views
Skip to first unread message

Cheng Bao

unread,
Sep 9, 2016, 6:59:20 PM9/9/16
to Jenkins Developers
After some trying I found getFoo(String value) could handle the request
public Object getFoo(String value){
   
// value == "bar"
   
// now what?
}

However, what to do next? without StaplerRequest and StaplerResponse parameters, after processing, how can display certain jelly file? how can I make redirection to another url?
How can I get query parameters as /foo/bar?query=xx?
How can I get more part of url as /foo/bar1/bar2?

Thanks

Daniel Beck

unread,
Sep 9, 2016, 7:13:05 PM9/9/16
to jenkin...@googlegroups.com

> On 09.09.2016, at 15:59, Cheng Bao <cb...@vmware.com> wrote:
>
> However, what to do next? without StaplerRequest and StaplerResponse parameters, after processing, how can display certain jelly file? how can I make redirection to another url?
> How can I get query parameters as /foo/bar?query=xx?
> How can I get more part of url as /foo/bar1/bar2?

The object you return can have a doIndex method, or an index.jelly view. Or, in the /foo/bar1/bar2 example, a bar2.jelly view.

I actually gave a presentation on this just a few days ago, and the recording is at https://www.youtube.com/watch?v=iAJBKFe8mMo

You can access the current request object without changing your method signature using the static Stapler.currentRequest() method.

Likewise with the response -- you should also be able to return and/or throw a HttpResponse (there are predefined ones in HttpResponses) to redirect.

Daniel

Cheng Bao

unread,
Sep 21, 2016, 3:09:34 PM9/21/16
to Jenkins Developers, m...@beckweb.net
Hi, Thanks,

Is there a way to make getFoo() method use POST method? Even in form I specifiy <form action="foo" method="POST">
Stapler.currentRequest().getMethod() will still return "GET".
and @RequirePOST annotation will always fail
Reply all
Reply to author
Forward
0 new messages