You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by "Borshtein, Ofer" <of...@hp.com> on 2011/06/19 16:34:43 UTC

batch proccessing

Hi
Using a custom handler, how can I get the message body, and invoke resources ?

More info:
I want to implement some way of batch requests in REST.

The input: a message body of JSON/XML, that contain several entries.
Each Entry consists of the target URI and the message body.

Ex:
--boundary
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for a resource ... </uri> <user>... body ...</user>
--boundary
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for a resource ... </uri> <user>... body ...</user>
--boundary-

For that, I want to write my own handler, to read above input, parse it, and invoke each entry.

How do I do that?



Re: batch proccessing

Posted by Bryant Luk <br...@gmail.com>.
Hi,

I inlined some of the responses to make it easier.

On Wed, Jun 22, 2011 at 3:16 AM, Borshtein, Ofer <of...@hp.com> wrote:
> Thanks.
> Few follow up questions:
>
> 1. You wrote: " Your user handler should come before CreateInvocationParametersHandler"
> But according to wink, user handlers are inserted after CreateInvocationParametersHandler, so how can I insert it before it?

Right, you can also use a custom deployment configuration init param
to change all of the handlers (see the DeploymentConfiguration class
and the methods with handler in them). It is changing some of the
internal code but it might be required depending on how you want to
process the parameters when you invoke the resources.

> 2. You wrote: ", create the invocation parameters and then invoke the method for that part.".
> I can parse each part and create invocation params (actually I already did it in my POC), but the big questions still remain:
>        a. I have the resource name in each part. How do I find the method that I need to invoke?
>        b. How do I invoke it, in such a way that I'll invoke each part and aggregate all the responses back to the client?

You'd probably have to re-wire significant parts of the handler chain.

Once you have your handler, you have to implement a
handle(MessageContext context, HandlersChain chain) method. You can
get the ResourceRegistry by invoking
context.getAttribute(ResourceRegistry.class). The ResourceRegistry
maintains information about all of the resources available in the
application. You can look at the
org.apache.wink.server.internal.handlers.FindRootResourceHandler class
for how regular matches from URIs to root resources are done. Then, to
find the method to invoke on the Java object, you can look at what the
FindResourceMethodHandler class does.

You can potentially aggregate all these method invocation results
(i.e. keep the returned Java objects after every method invocation) in
a custom type. Set the custom type instance as the response entity on
the context.setResponseEntity(). Then you would have a new
MessageBodyWriter for that custom type. The writer could re-use the
standard MessageBodyWriters by having a @Context Providers (as a
field) to find writers for all the returned Java objects in the custom
type.

There would be limitations with this approach (e.g. you couldn't just
give the HttpServletRequest InputStream as a resource parameter). As
an alternative, you could also write a standard servlet filter to
dispatch individual requests and aggregate the response but I don't
think that would necessarily be any easier.

> 10x again.
>
>
> -----Original Message-----
> From: Bryant Luk [mailto:bryant.luk@gmail.com]
> Sent: Tuesday, June 21, 2011 7:49 PM
> To: wink-user@incubator.apache.org
> Subject: Re: batch proccessing
>
> Hello,
>
> The classes you are probably interested in would be in the
> org.apache.wink.server.handlers.* package ( http://incubator.apache.org/wink/1.1.2/api/index.html ). To register a custom handler factory, you'll need to initialize a custom property.
>
> https://cwiki.apache.org/WINK/2-apache-wink-building-blocks.html#2ApacheWinkBuildingBlocks-CustomizationoftheHandlersChain
> https://cwiki.apache.org/WINK/57-handler-chain-runtime-extension.html
>
> may help.
>
> Your user handler should come before CreateInvocationParametersHandler and InvokeMethodHandler . You could parse each part, create the invocation parameters and then invoke the method for that part. I'm not sure if you're planning to use other types of parameters but you can look at the system handlers in
> org.apache.wink.server.internal.handlers.* like the CreateInvocationParametersHandler to understand what you would need to do.
>
> On Sun, Jun 19, 2011 at 9:34 AM, Borshtein, Ofer <of...@hp.com> wrote:
>> Hi
>>
>> Using a custom handler, how can I get the message body, and invoke
>> resources ?
>>
>>
>>
>> More info:
>>
>> I want to implement some way of batch requests in REST.
>>
>>
>>
>> The input: a message body of JSON/XML, that contain several entries.
>>
>> Each Entry consists of the target URI and the message body.
>>
>>
>>
>> Ex:
>>
>> --boundary
>>
>> Content-Type: application/xml
>>
>>
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for
>> a resource ... </uri> <user>... body ...</user>
>>
>> --boundary
>>
>> Content-Type: application/xml
>>
>>
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for
>> a resource ... </uri> <user>... body ...</user>
>>
>> --boundary-
>>
>>
>>
>> For that, I want to write my own handler, to read above input, parse
>> it, and invoke each entry.
>>
>>
>>
>> How do I do that?
>>
>>
>>
>>
>

RE: batch proccessing

Posted by "Borshtein, Ofer" <of...@hp.com>.
Thanks.
Few follow up questions:

1. You wrote: " Your user handler should come before CreateInvocationParametersHandler"
But according to wink, user handlers are inserted after CreateInvocationParametersHandler, so how can I insert it before it?

2. You wrote: ", create the invocation parameters and then invoke the method for that part.".
I can parse each part and create invocation params (actually I already did it in my POC), but the big questions still remain: 
	a. I have the resource name in each part. How do I find the method that I need to invoke?
	b. How do I invoke it, in such a way that I'll invoke each part and aggregate all the responses back to the client?

10x again.


-----Original Message-----
From: Bryant Luk [mailto:bryant.luk@gmail.com] 
Sent: Tuesday, June 21, 2011 7:49 PM
To: wink-user@incubator.apache.org
Subject: Re: batch proccessing

Hello,

The classes you are probably interested in would be in the
org.apache.wink.server.handlers.* package ( http://incubator.apache.org/wink/1.1.2/api/index.html ). To register a custom handler factory, you'll need to initialize a custom property.

https://cwiki.apache.org/WINK/2-apache-wink-building-blocks.html#2ApacheWinkBuildingBlocks-CustomizationoftheHandlersChain
https://cwiki.apache.org/WINK/57-handler-chain-runtime-extension.html

may help.

Your user handler should come before CreateInvocationParametersHandler and InvokeMethodHandler . You could parse each part, create the invocation parameters and then invoke the method for that part. I'm not sure if you're planning to use other types of parameters but you can look at the system handlers in
org.apache.wink.server.internal.handlers.* like the CreateInvocationParametersHandler to understand what you would need to do.

On Sun, Jun 19, 2011 at 9:34 AM, Borshtein, Ofer <of...@hp.com> wrote:
> Hi
>
> Using a custom handler, how can I get the message body, and invoke 
> resources ?
>
>
>
> More info:
>
> I want to implement some way of batch requests in REST.
>
>
>
> The input: a message body of JSON/XML, that contain several entries.
>
> Each Entry consists of the target URI and the message body.
>
>
>
> Ex:
>
> --boundary
>
> Content-Type: application/xml
>
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for 
> a resource ... </uri> <user>... body ...</user>
>
> --boundary
>
> Content-Type: application/xml
>
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>... uri for 
> a resource ... </uri> <user>... body ...</user>
>
> --boundary-
>
>
>
> For that, I want to write my own handler, to read above input, parse 
> it, and invoke each entry.
>
>
>
> How do I do that?
>
>
>
>

Re: batch proccessing

Posted by Bryant Luk <br...@gmail.com>.
Hello,

The classes you are probably interested in would be in the
org.apache.wink.server.handlers.* package (
http://incubator.apache.org/wink/1.1.2/api/index.html ). To register a
custom handler factory, you'll need to initialize a custom property.

https://cwiki.apache.org/WINK/2-apache-wink-building-blocks.html#2ApacheWinkBuildingBlocks-CustomizationoftheHandlersChain
https://cwiki.apache.org/WINK/57-handler-chain-runtime-extension.html

may help.

Your user handler should come before CreateInvocationParametersHandler
and InvokeMethodHandler . You could parse each part, create the
invocation parameters and then invoke the method for that part. I'm
not sure if you're planning to use other types of parameters but you
can look at the system handlers in
org.apache.wink.server.internal.handlers.* like the
CreateInvocationParametersHandler to understand what you would need to
do.

On Sun, Jun 19, 2011 at 9:34 AM, Borshtein, Ofer <of...@hp.com> wrote:
> Hi
>
> Using a custom handler, how can I get the message body, and invoke resources
> ?
>
>
>
> More info:
>
> I want to implement some way of batch requests in REST.
>
>
>
> The input: a message body of JSON/XML, that contain several entries.
>
> Each Entry consists of the target URI and the message body.
>
>
>
> Ex:
>
> --boundary
>
> Content-Type: application/xml
>
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>… uri for a
> resource … </uri> <user>… body …</user>
>
> --boundary
>
> Content-Type: application/xml
>
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><uri>… uri for a
> resource … </uri> <user>… body …</user>
>
> --boundary—
>
>
>
> For that, I want to write my own handler, to read above input, parse it, and
> invoke each entry.
>
>
>
> How do I do that?
>
>
>
>