You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@synapse.apache.org by Wayne Keenan <wa...@gmail.com> on 2008/04/14 13:24:09 UTC

Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Inlining Groovy scripts is thankfully easy. For reasons such as tidyness,
reuse, in-flight updates and sanity sake it is arguably be better to store
the
scripts as external entities in a repository.  For the benefit of others I
have collected the info I found elsewhere and some experimentation

in one place to show how it's done:

Below is a simple inliine script that builds a static XML document :

<sequence name="service_dispatch_out" trace="enable">
<script language="groovy">

                mc.setPayloadXML('''<hello
xmlns="http://grails-exchange.com
"><to>Everyone</to><from>Paul</from></hello>''')
</script>
<send/>
</sequence>

For an script in a repository follow this 'pattern':


Synapse XML:

<sequence name="service_dispatch_out" trace="enable">
        <script language="groovy"
key="samples/scripts/staticXMLresponse.groovy"/>
        <send/>
</sequence>


Repository XML:



<x><![CDATA[
static void mediate (mc) {

    mc.setPayloadXML('''<hello xmlns="http://grails-exchange.com
"><to>Everyone</to><from>Paul</from></hello>''')
}
]]></x>

Notice there needs to be a root tag, to support the (implied) XInclude I
guess, and that the script needs to adhere to an interface to be able to be
passed the MessageContext (mc) which gives programmatic access to the
current synapase message and sequence.

For interesting things you can do with the MessgeContext please have a look
at:
http://synapse.apache.org/apidocs/org/apache/synapse/mediators/bsf/ScriptMessageContext.html


All the best

Wayne

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Ruwan Linton <ru...@gmail.com>.
Wayne,

On Mon, Apr 14, 2008 at 5:23 PM, Wayne Keenan <wa...@gmail.com>
wrote:

> Hi,
>
> I have signed up to esbsite.com and have submitted an article, I hope that
> is what you meant in this instance by blog it?


Cool, in away yes... :-)

Ruwan


>
>
> Regards
> Wayne
>
> On Mon, Apr 14, 2008 at 12:36 PM, Ruwan Linton <ru...@gmail.com>
> wrote:
>
> > Hi Wayne,
> >
> > Thanks for sharing this and it would be nice to see this interesting
> > snippet
> > goes as a blog entry as well.
> >
> > Thanks,
> > Ruwan
> >
> > On Mon, Apr 14, 2008 at 4:54 PM, Wayne Keenan <wa...@gmail.com>
> > wrote:
> >
> > > Inlining Groovy scripts is thankfully easy. For reasons such as
> > tidyness,
> > > reuse, in-flight updates and sanity sake it is arguably be better to
> > store
> > > the
> > > scripts as external entities in a repository.  For the benefit of
> others
> > I
> > > have collected the info I found elsewhere and some experimentation
> > >
> > > in one place to show how it's done:
> > >
> > > Below is a simple inliine script that builds a static XML document :
> > >
> > > <sequence name="service_dispatch_out" trace="enable">
> > > <script language="groovy">
> > >
> > >                mc.setPayloadXML('''<hello
> > > xmlns="http://grails-exchange.com
> > > "><to>Everyone</to><from>Paul</from></hello>''')
> > > </script>
> > > <send/>
> > > </sequence>
> > >
> > > For an script in a repository follow this 'pattern':
> > >
> > >
> > > Synapse XML:
> > >
> > > <sequence name="service_dispatch_out" trace="enable">
> > >        <script language="groovy"
> > > key="samples/scripts/staticXMLresponse.groovy"/>
> > >        <send/>
> > > </sequence>
> > >
> > >
> > > Repository XML:
> > >
> > >
> > >
> > > <x><![CDATA[
> > > static void mediate (mc) {
> > >
> > >    mc.setPayloadXML('''<hello xmlns="http://grails-exchange.com
> > > "><to>Everyone</to><from>Paul</from></hello>''')
> > > }
> > > ]]></x>
> > >
> > > Notice there needs to be a root tag, to support the (implied) XInclude
> I
> > > guess, and that the script needs to adhere to an interface to be able
> to
> > > be
> > > passed the MessageContext (mc) which gives programmatic access to the
> > > current synapase message and sequence.
> > >
> > > For interesting things you can do with the MessgeContext please have a
> > > look
> > > at:
> > >
> > >
> >
> http://synapse.apache.org/apidocs/org/apache/synapse/mediators/bsf/ScriptMessageContext.html
> > >
> > >
> > > All the best
> > >
> > > Wayne
> > >
> >
> >
> >
> > --
> > Ruwan Linton
> > http://www.wso2.org - "Oxygenating the Web Services Platform"
> >
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Wayne Keenan <wa...@gmail.com>.
Hi,

I have signed up to esbsite.com and have submitted an article, I hope that
is what you meant in this instance by blog it?

Regards
Wayne

On Mon, Apr 14, 2008 at 12:36 PM, Ruwan Linton <ru...@gmail.com>
wrote:

> Hi Wayne,
>
> Thanks for sharing this and it would be nice to see this interesting
> snippet
> goes as a blog entry as well.
>
> Thanks,
> Ruwan
>
> On Mon, Apr 14, 2008 at 4:54 PM, Wayne Keenan <wa...@gmail.com>
> wrote:
>
> > Inlining Groovy scripts is thankfully easy. For reasons such as
> tidyness,
> > reuse, in-flight updates and sanity sake it is arguably be better to
> store
> > the
> > scripts as external entities in a repository.  For the benefit of others
> I
> > have collected the info I found elsewhere and some experimentation
> >
> > in one place to show how it's done:
> >
> > Below is a simple inliine script that builds a static XML document :
> >
> > <sequence name="service_dispatch_out" trace="enable">
> > <script language="groovy">
> >
> >                mc.setPayloadXML('''<hello
> > xmlns="http://grails-exchange.com
> > "><to>Everyone</to><from>Paul</from></hello>''')
> > </script>
> > <send/>
> > </sequence>
> >
> > For an script in a repository follow this 'pattern':
> >
> >
> > Synapse XML:
> >
> > <sequence name="service_dispatch_out" trace="enable">
> >        <script language="groovy"
> > key="samples/scripts/staticXMLresponse.groovy"/>
> >        <send/>
> > </sequence>
> >
> >
> > Repository XML:
> >
> >
> >
> > <x><![CDATA[
> > static void mediate (mc) {
> >
> >    mc.setPayloadXML('''<hello xmlns="http://grails-exchange.com
> > "><to>Everyone</to><from>Paul</from></hello>''')
> > }
> > ]]></x>
> >
> > Notice there needs to be a root tag, to support the (implied) XInclude I
> > guess, and that the script needs to adhere to an interface to be able to
> > be
> > passed the MessageContext (mc) which gives programmatic access to the
> > current synapase message and sequence.
> >
> > For interesting things you can do with the MessgeContext please have a
> > look
> > at:
> >
> >
> http://synapse.apache.org/apidocs/org/apache/synapse/mediators/bsf/ScriptMessageContext.html
> >
> >
> > All the best
> >
> > Wayne
> >
>
>
>
> --
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"
>

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Wayne,

Thanks for sharing this and it would be nice to see this interesting snippet
goes as a blog entry as well.

Thanks,
Ruwan

On Mon, Apr 14, 2008 at 4:54 PM, Wayne Keenan <wa...@gmail.com>
wrote:

> Inlining Groovy scripts is thankfully easy. For reasons such as tidyness,
> reuse, in-flight updates and sanity sake it is arguably be better to store
> the
> scripts as external entities in a repository.  For the benefit of others I
> have collected the info I found elsewhere and some experimentation
>
> in one place to show how it's done:
>
> Below is a simple inliine script that builds a static XML document :
>
> <sequence name="service_dispatch_out" trace="enable">
> <script language="groovy">
>
>                mc.setPayloadXML('''<hello
> xmlns="http://grails-exchange.com
> "><to>Everyone</to><from>Paul</from></hello>''')
> </script>
> <send/>
> </sequence>
>
> For an script in a repository follow this 'pattern':
>
>
> Synapse XML:
>
> <sequence name="service_dispatch_out" trace="enable">
>        <script language="groovy"
> key="samples/scripts/staticXMLresponse.groovy"/>
>        <send/>
> </sequence>
>
>
> Repository XML:
>
>
>
> <x><![CDATA[
> static void mediate (mc) {
>
>    mc.setPayloadXML('''<hello xmlns="http://grails-exchange.com
> "><to>Everyone</to><from>Paul</from></hello>''')
> }
> ]]></x>
>
> Notice there needs to be a root tag, to support the (implied) XInclude I
> guess, and that the script needs to adhere to an interface to be able to
> be
> passed the MessageContext (mc) which gives programmatic access to the
> current synapase message and sequence.
>
> For interesting things you can do with the MessgeContext please have a
> look
> at:
>
> http://synapse.apache.org/apidocs/org/apache/synapse/mediators/bsf/ScriptMessageContext.html
>
>
> All the best
>
> Wayne
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by indika kumara <in...@gmail.com>.
Hi Wayne

Now ,you can use  native scripts in the registry as it is . You never want
to wrapping the native script source inside a XML tag.

Thanks
Indika

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Paul Fremantle <pz...@gmail.com>.
Indika

When we originally designed the API, we expected the API to be a
bridge from the registry world to the Synapse world. And since most
Synapse config is in XML, we made the assumption that Axiom would be a
good API. Especially because the Registry API caches objects, so we
wanted to cache the parsed built object not the underlying content. So
I think the right thing to do here is for us to automatically wrap any
text in the right CDATA section so it is properly held in Axiom. The
other approach would be to set the content into a binary wrapper
within Axiom using a DataHandler.

I guess what I'm saying is that the implementation of the URLRegistry
is wrong but I think the API is ok - it may be a little painful but it
was designed that way for a reason.

Paul

On Tue, Apr 15, 2008 at 5:29 AM, indika kumara <in...@gmail.com> wrote:
> Hi Paul
>
>  The issue here is , we cannot build a OMNode from a text if it is doesn't
>  represent a valid XML, even text had wrapped with CDATA . If the AXIOM adds
>  this capability , then we can use the existing API. By the way , I believe
>  that  the registry  API  need to avoid tight coupling with AXIOM.
>
>  Thanks
>  Indika
>
>
>
>
>  On Tue, Apr 15, 2008 at 4:05 AM, Paul Fremantle <pz...@gmail.com> wrote:
>
>  > Indika
>  >
>  > Can't an OMNode be an OMText? In which case the content can just be text?
>  >
>  > Paul
>  >
>  > On Mon, Apr 14, 2008 at 2:31 PM, indika kumara <in...@gmail.com>
>  > wrote:
>  > > Hi Wayne,
>  > >
>  > >  Whether the underlying registry is the wso2registry or simple URL
>  > registry ,
>  > >  synapse uses its registry API . The current registry API tightly
>  > couples
>  > >  with OMNode as its API has a 'lookup' method which expects to be
>  > returned a
>  > >  OMNode as the result. In order to support non-XML content as registry
>  > >  resources , it is needed refactoring the current API by removing OMNode
>  > >  dependency and providing more an abstract API.
>  > >
>  > >  I will do the required changes.
>  > >
>  > >  By the way , wso2registry is a dedicated product for the Registry space
>  > , so
>  > >  , it will be an obvious alternative for the simple URL Registry.
>  > >  Currently,you cannot plug the wso2regustry in to the synapse but you
>  > can use
>  > >  the wso2registry with the wso2 ESB(https://wso2.org/projects/esb/java)
>  > which
>  > >  wraps the core as synapse as it is and provides a management console.
>  > >
>  > >  Thanks
>  > >  Indika
>  > >
>  >
>  >
>  >
>  > --
>  > Paul Fremantle
>  > Co-Founder and CTO, WSO2
>  > Apache Synapse PMC Chair
>  > OASIS WS-RX TC Co-chair
>  >
>  > blog: http://pzf.fremantle.org
>  > paul@wso2.com
>  >
>  > "Oxygenating the Web Service Platform", www.wso2.com
>  >
>



-- 
Paul Fremantle
Co-Founder and CTO, WSO2
Apache Synapse PMC Chair
OASIS WS-RX TC Co-chair

blog: http://pzf.fremantle.org
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by indika kumara <in...@gmail.com>.
Hi Paul

The issue here is , we cannot build a OMNode from a text if it is doesn't
represent a valid XML, even text had wrapped with CDATA . If the AXIOM adds
this capability , then we can use the existing API. By the way , I believe
that  the registry  API  need to avoid tight coupling with AXIOM.

Thanks
Indika


On Tue, Apr 15, 2008 at 4:05 AM, Paul Fremantle <pz...@gmail.com> wrote:

> Indika
>
> Can't an OMNode be an OMText? In which case the content can just be text?
>
> Paul
>
> On Mon, Apr 14, 2008 at 2:31 PM, indika kumara <in...@gmail.com>
> wrote:
> > Hi Wayne,
> >
> >  Whether the underlying registry is the wso2registry or simple URL
> registry ,
> >  synapse uses its registry API . The current registry API tightly
> couples
> >  with OMNode as its API has a 'lookup' method which expects to be
> returned a
> >  OMNode as the result. In order to support non-XML content as registry
> >  resources , it is needed refactoring the current API by removing OMNode
> >  dependency and providing more an abstract API.
> >
> >  I will do the required changes.
> >
> >  By the way , wso2registry is a dedicated product for the Registry space
> , so
> >  , it will be an obvious alternative for the simple URL Registry.
> >  Currently,you cannot plug the wso2regustry in to the synapse but you
> can use
> >  the wso2registry with the wso2 ESB(https://wso2.org/projects/esb/java)
> which
> >  wraps the core as synapse as it is and provides a management console.
> >
> >  Thanks
> >  Indika
> >
>
>
>
> --
> Paul Fremantle
> Co-Founder and CTO, WSO2
> Apache Synapse PMC Chair
> OASIS WS-RX TC Co-chair
>
> blog: http://pzf.fremantle.org
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Paul Fremantle <pz...@gmail.com>.
Indika

Can't an OMNode be an OMText? In which case the content can just be text?

Paul

On Mon, Apr 14, 2008 at 2:31 PM, indika kumara <in...@gmail.com> wrote:
> Hi Wayne,
>
>  Whether the underlying registry is the wso2registry or simple URL registry ,
>  synapse uses its registry API . The current registry API tightly couples
>  with OMNode as its API has a 'lookup' method which expects to be returned a
>  OMNode as the result. In order to support non-XML content as registry
>  resources , it is needed refactoring the current API by removing OMNode
>  dependency and providing more an abstract API.
>
>  I will do the required changes.
>
>  By the way , wso2registry is a dedicated product for the Registry space , so
>  , it will be an obvious alternative for the simple URL Registry.
>  Currently,you cannot plug the wso2regustry in to the synapse but you can use
>  the wso2registry with the wso2 ESB(https://wso2.org/projects/esb/java) which
>  wraps the core as synapse as it is and provides a management console.
>
>  Thanks
>  Indika
>



-- 
Paul Fremantle
Co-Founder and CTO, WSO2
Apache Synapse PMC Chair
OASIS WS-RX TC Co-chair

blog: http://pzf.fremantle.org
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by indika kumara <in...@gmail.com>.
Hi Wayne,

Whether the underlying registry is the wso2registry or simple URL registry ,
synapse uses its registry API . The current registry API tightly couples
with OMNode as its API has a 'lookup' method which expects to be returned a
OMNode as the result. In order to support non-XML content as registry
resources , it is needed refactoring the current API by removing OMNode
dependency and providing more an abstract API.

I will do the required changes.

By the way , wso2registry is a dedicated product for the Registry space , so
, it will be an obvious alternative for the simple URL Registry.
Currently,you cannot plug the wso2regustry in to the synapse but you can use
the wso2registry with the wso2 ESB(https://wso2.org/projects/esb/java) which
wraps the core as synapse as it is and provides a management console.

Thanks
Indika

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by "Asankha C. Perera" <as...@wso2.com>.
Wayne Keenan wrote:
>> This is because the built-in simple registry only supports XML resources.
>>     
> So any XML tag will work..
>
> Would it be possible to (X)include the document as Text so that it doesn't
> have to be well formed XML and just a plain old Groovy script; it makes my
> Eclipse Groovy nature projects littered with red X'es :)
>   
I guess this is a limitation of the simple URL registry we have used by 
default.. BTW, if you switch this to another Registry implementation 
that supports non-XML resources, this should work without the outer 
element.. Indika - am I right?

asankha

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Wayne,

The direct answer for this is no, because the built-in registry supports
only XML content. At the same time I must say that, this should be possible
with the new WSO2 Registry [1], even though we haven't tested this.

[1] - https://wso2.org/projects/registry

Thanks,
Ruwan

On Mon, Apr 14, 2008 at 5:27 PM, Wayne Keenan <wa...@gmail.com>
wrote:

> >This is because the built-in simple registry only supports XML resources.
> So any XML tag will work..
>
> Would it be possible to (X)include the document as Text so that it doesn't
> have to be well formed XML and just a plain old Groovy script; it makes my
> Eclipse Groovy nature projects littered with red X'es :)
>
> Regards
> Wayne
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by Wayne Keenan <wa...@gmail.com>.
>This is because the built-in simple registry only supports XML resources.
So any XML tag will work..

Would it be possible to (X)include the document as Text so that it doesn't
have to be well formed XML and just a plain old Groovy script; it makes my
Eclipse Groovy nature projects littered with red X'es :)

Regards
Wayne

Re: Groovy Script stored in a Repository snippet (Synapse 1.1.1)

Posted by "Asankha C. Perera" <as...@wso2.com>.
Hi Wayne
> For the benefit of others I have collected the info I found elsewhere and some experimentation in one place to show how it's done:
>   
Thank you for sharing this with the other users, you can even submit 
this to the community site http://esbsite.org where it would be easier 
for new users to find this out without having to search through archives.
> Repository XML:
>
> <x><![CDATA[
> static void mediate (mc) {
>
>     mc.setPayloadXML('''<hello xmlns="http://grails-exchange.com
> "><to>Everyone</to><from>Paul</from></hello>''')
> }
> ]]></x>
>
> Notice there needs to be a root tag
This is because the built-in simple registry only supports XML 
resources. So any XML tag will work..

asankha