You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Simon Gaeremynck <ga...@gmail.com> on 2009/12/15 13:17:57 UTC

Dispatching a request with new RequestParameters

I have to write a batchpost mechanism that allows our UI guys to do a single
POST to our servlet with a set of endpoints and data for it.
Imagine something like:

[
{url: /foo/a, data: {a: 1, b: 2}},
{url: /foo/b, data: {alfa: 1, test: 2}},
{url: /foo/c, data: {name: "Simon", b: 2}},
]

So what I did was the following:

Create a SlingHttpServletRequestWrapper and SlingHttpServletResponseWrapper
for each endpoint.
I've overriden the default servlet getParameter, getParameterNames, ...
methods and returned my own data for them.

The requests goes trough fine, but it uses the original request parameters
instead of the newly defined ones.

I guess I need to override the methods that return sling's
RequestParameter's as well as the request seems to be unwrapped in
RequestData.java (~420)
Now the entire mechanisme of setting request parameters is in the
implementation of the sling engine and I don't really know how to set these
in my bundle.

Is there an easier way of doing this kind of behavior or is this strongly
discouraged?

Kind regards,


Simon

Re: Dispatching a request with new RequestParameters

Posted by Simon Gaeremynck <ga...@gmail.com>.
Response inline :)

Simon

(btw, I'm not getting any mails from the user@sling list?)

On 16 Dec 2009, at 12:42, Vidar Ramdal-2 [via Apache Sling] wrote:

> On Wed, Dec 16, 2009 at 12:47 PM, Simon Gaeremynck wrote:
>
> >
> > Thanks, but that is not exactly what I'm looking for.
> > My previous explanation wasn't clear enough.
> >
> > I want to be able to do posts to both nodes and registered servlets.
> > I then went to grab the response and send that back.  From what I  
> can tell,
> > this doesn't seem to work for servlets.
> > ex:
> > - Nodes
> >  Set properties on the nodes or do any of the @Delete, @Move  
> things sling
> > provides
> > - Servlets
> >  Do a request to the servlet, let the servlet do it's thing and  
> get the
> > response that I can send back to the user.
> >
> > This is why I wanted to wrap both the request and response.
>
> Ok, I see. Sounds to me like you can get some way with a servlet
> filter, but I think it will be tricky to modify request parameters.
>

Hmm, OK. I think it would work if I would be able return valid  
RequestParameter's in the SlingHttpServletRequestWrapper. But since  
these all get created in impl I can't get to it.

I don't really want to using filters for this.


> > As a little sidenode, I wrote a small patch [1] that allowed you  
> to send a
> > couple of properties to multiple nodes and apply those. It would  
> use the
> > applyTo parameter. I also added the possibility to make applyTo a  
> query as
> > discussed at [2].
> > I didn't submit it because it was something I just hacked together  
> which we
> > didn't really need it in the end plus I hadn't really thoroughly  
> tested.
>
> Ah yes, that one :)
> From just a brief look, the patch looks fine to me. I'll take a closer
> look when I have more time, maybe others can check it out as well?
>
> (If you want to commit it, I'm sure Bertrand would be happy if you
> include some automated tests)

I'll see what I can do. :)

>
> -- 
> Vidar S. Ramdal <[hidden email]> - http://www.idium.no
> Sommerrogata 13-15, N-0255 Oslo, Norway
> + 47 22 00 84 00 / +47 21 531941, ext 2070
>
>
> View message @ http://n3.nabble.com/Dispatching-a-request-with-new-RequestParameters-tp91233p92141.html
> To unsubscribe from Re: Dispatching a request with new  
> RequestParameters, click here.
>


Re: Dispatching a request with new RequestParameters

Posted by Vidar Ramdal <vi...@idium.no>.
On Wed, Dec 16, 2009 at 12:47 PM, Simon Gaeremynck
<ga...@gmail.com> wrote:
>
> Thanks, but that is not exactly what I'm looking for.
> My previous explanation wasn't clear enough.
>
> I want to be able to do posts to both nodes and registered servlets.
> I then went to grab the response and send that back.  From what I can tell,
> this doesn't seem to work for servlets.
> ex:
> - Nodes
>  Set properties on the nodes or do any of the @Delete, @Move things sling
> provides
> - Servlets
>  Do a request to the servlet, let the servlet do it's thing and get the
> response that I can send back to the user.
>
> This is why I wanted to wrap both the request and response.

Ok, I see. Sounds to me like you can get some way with a servlet
filter, but I think it will be tricky to modify request parameters.

> As a little sidenode, I wrote a small patch [1] that allowed you to send a
> couple of properties to multiple nodes and apply those. It would use the
> applyTo parameter. I also added the possibility to make applyTo a query as
> discussed at [2].
> I didn't submit it because it was something I just hacked together which we
> didn't really need it in the end plus I hadn't really thoroughly tested.

Ah yes, that one :)
>From just a brief look, the patch looks fine to me. I'll take a closer
look when I have more time, maybe others can check it out as well?

(If you want to commit it, I'm sure Bertrand would be happy if you
include some automated tests)

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 21 531941, ext 2070

Re: Dispatching a request with new RequestParameters

Posted by Simon Gaeremynck <ga...@gmail.com>.
Thanks, but that is not exactly what I'm looking for.
My previous explanation wasn't clear enough.

I want to be able to do posts to both nodes and registered servlets.
I then went to grab the response and send that back.  From what I can tell,
this doesn't seem to work for servlets.
ex:
- Nodes
  Set properties on the nodes or do any of the @Delete, @Move things sling
provides
- Servlets
  Do a request to the servlet, let the servlet do it's thing and get the
response that I can send back to the user.

This is why I wanted to wrap both the request and response.



As a little sidenode, I wrote a small patch [1] that allowed you to send a
couple of properties to multiple nodes and apply those. It would use the
applyTo parameter. I also added the possibility to make applyTo a query as
discussed at [2].
I didn't submit it because it was something I just hacked together which we
didn't really need it in the end plus I hadn't really thoroughly tested.


Thanks for your help,

Simon



[1] http://codereview.appspot.com/176047/show
[2] http://www.mail-archive.com/dev@sling.apache.org/msg01906.html
-- 
View this message in context: http://n3.nabble.com/Dispatching-a-request-with-new-RequestParameters-tp91233p92106.html
Sent from the Sling - Users mailing list archive at Nabble.com.

Re: Dispatching a request with new RequestParameters

Posted by Vidar Ramdal <vi...@idium.no>.
On Tue, Dec 15, 2009 at 1:17 PM, Simon Gaeremynck <ga...@gmail.com> wrote:
> I have to write a batchpost mechanism that allows our UI guys to do a single
> POST to our servlet with a set of endpoints and data for it.
> Imagine something like:
>
> [
> {url: /foo/a, data: {a: 1, b: 2}},
> {url: /foo/b, data: {alfa: 1, test: 2}},
> {url: /foo/c, data: {name: "Simon", b: 2}},
> ]

> Is there an easier way of doing this kind of behavior or is this strongly
> discouraged?

If I understand correctly, you want to mainpulate several nodes in a
single request?
The data you have listed above can be posted with an HTML form like this:
<form method="post" action="/">
  <input type="text" name="/foo/a/a" value="1" />
  <input type="text" name="/foo/a/b" value="2" />
  <input type="text" name="/foo/b/alfa" value="1" />
  <input type="text" name="/foo/b/test" value="2" />
  <input type="text" name="/foo/c/name" value="Simon" />
  <input type="text" name="/foo/c/b" value="2" />
  <button type="submit">Submit</button>
</form>

Notice how the "name" attribute of the input elements are in fact
paths to properties.

Submitting that form to the SlingPostServlet should result in these nodes:
/foo/a, with properties a=1 and b=2
/foo/b, with properties alfa=1 and test=2
/foo/c, with properties name=Simon and b=2

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 21 531941, ext 2070