Hi Florin,
Please find the answers to your questions and some additional comments
inline.

On Tue, Sep 29, 2009 at 4:42 PM, Florin Bejinaru
<[email protected]>wrote:

> Hello again,
>
> I want to do custom request filtering for just one of the endpoints
> mentioned in my previous mail (a port 9000 endpoint and a port 8080
> endpoint). So what I want to do is send every request to the 9000 endpoint
> and filter the requests for the 8080 endpoint based on the request content.
>
> I need to do dynamic filtering (in that you should be able to change the
> filters at run time and these should be managed centrally).
>
> I figure I can do the filtering in two ways:
> One would be to filter based on a set of xslt files located on a remote
> registry, and the other to use a "class" mediator with a custom class that
> filters based on a set of xslt files loaded through a web service, hosted
> by
> synapse preferably.
>
> To save me from trying to do both of these, could you tell me if :
>
> 1) By using a remote registry can I set a filtering xslt, to filter
> requests
> for the 8080 endpoint?
>

The most common way of implementing content based routing with Synapse is by
using the filter mediator or by using the switch mediator. Both these
mediators take an XPath expression (not XSLT) based on which to perform the
filtering. You can put these mediators into a sequence in a way so that your
filtering requirements are properly handled and then save the entire
sequence in the remote registry. Then in the main sequence you will be able
to refer to the sequence in the registry using a key. You can make
modifications to the sequence at runtime and Synapse will load the sequence
in the registry from time to time. Thus any changes you have made will take
effect at runtime.


> 2) By using a class mediator, can I host a web-service in synapse that
> saves
> files somewhere where they can be accessed by my class mediator ?
>

You cannot host Web Services in Synapse. But with the class mediator you can
write some custom code which interacts with the file system. Anyway I don't
think it's a good idea to get your mediators read/write to the file system.
That might have a significant performance hit. You should be using the
registry to store resource. Then you can benefit from our core API and the
caching features.


>
> 3) With the class mediator implementation, what are my xslt filtering
> options, what XSLT engine can I (should I) use from my Java mediator class
> ?
>

As I mentioned earlier with the class mediator you can get Synapse to
execute any piece of custom code. So you can use any third party libraries
you want when writing the custom code. But filtering is a basic feature of
Synapse and ideally you should be using the filter/switch mediators to get
this done. That is far more efficient and easier.


>
> Any help would be greatly appreciated !
>

I think you can use a configuration similar to the following to implement
your scenario:

<sequence name="main">
     <in>
           <sequence key="/key/to/dynamic/sequence"/>
      </in>
      <out>
           <send/>
      </out>
</sequence>

Dynamic sequence in the registry:

<sequence name="foo">
        <switch source="get-property('To')">
                <case regex="http://localhost:8080*";>
                        <filter source="xpath to examine the content"
regex="regular expression">
                              <send/>
                         </filter>
                         <drop/>
                 </case>
                 <case regex="http://localhost:9000*";>
                         <send/>
                 </case>
         </switch>
</sequence>

This is just one way of doing it (may be not the most elegant way). Please
have a loot at sample 1 and 2 in our  sample guide for more info.

Thanks,
Hiranya



> Thank you,
> Florin
>



-- 
Hiranya Jayathilaka
Software Engineer;
WSO2 Inc.;  http://wso2.org
E-mail: [email protected];  Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com

Reply via email to