You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Andrew Borley <aj...@gmail.com> on 2006/12/21 22:57:29 UTC

[C++] Named arguments

Hi all,

I was looking to put together another "real-world" sample for SCA C++,
using Sebastien's REST support to invoke the Yahoo REST services.
Unfortunately, this won't currently work due to how we support
arguments - currently they're indexed purely by number.

The Yahoo REST services need an HTTP GET call like:
http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=Tuscany&results=2

If we have the Yahoo service configured in a SCA reference using the
REST binding and then call webSearch("YahooDemo", "Tuscany", 2) on a
SCA reference object in some component code, the HTTP GET call
generated is:
http://search.yahooapis.com/WebSearchService/V1/webSearch?param1=YahooDemo&param2=Tuscany&param3=2

In another example, if we want to use a SOAP service which has a
request schema containing a bunch of non-required elements like:
<xs:element name="myMethod">
  <xs:complexType>
     <xs:sequence>
       <xs:element name="anArgument" minOccurs="0" type="xs:string"/>
       <xs:element name="anotherArgument" minOccurs="0" type="xs:string"/>
       <xs:element name="lastArgument" minOccurs="0" type="xs:string"/>
     </xs:sequence>
  </xs:complexType>
</xs:element>

And this is again configured as an SCA reference (using the WS
binding). A component calling this operation would have to call
myMethod("", "", "some data") - which would mean the first 2 elements
get sent in the SOAP message with empty data (rather than being left
out completely) and only the "lastArgument" element would contain
anything useful. Doing this may also cause errors at the server as
elements are received without any data to work on.

I think we can fix these case pretty easily (in some circumstances) by
adding a parameter name index to the tuscany::sca::core::Operation
object - so parameters have a number and an optional name. For scagen
generated C++ proxy objects, the parameter names can be based on those
provided by the header and set inside the proxy. For Python you can
use named arguments when calling methods like myMethod(
lastArgument="someData" ) or webSearch(appid="YahooDemo",
query="Tuscany", results=2). I don't think Ruby supports named
arguments, but there may be ways of using a Ruby dictionary object to
do this.

If the Operation object passed to the ws or rest bindings contains
named arguments we can  use them in creating the right SOAP message or
HTTP call.

Any thoughts on this? Is it worth doing?

Cheers
Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: [C++] Named arguments

Posted by Andrew Borley <aj...@gmail.com>.
On 1/3/07, Andrew Borley <aj...@gmail.com> wrote:
> On 12/22/06, Pete Robbins <ro...@googlemail.com> wrote:
> > On 22/12/06, Jean-Sebastien Delfino <js...@apache.org> wrote:
> > >
> > > Andrew Borley wrote:
> > > > Hi all,
> > > >
> > > > I was looking to put together another "real-world" sample for SCA C++,
> > > > using Sebastien's REST support to invoke the Yahoo REST services.
> > > > Unfortunately, this won't currently work due to how we support
> > > > arguments - currently they're indexed purely by number.
> > > >
> > > > The Yahoo REST services need an HTTP GET call like:
> > > >
> > > http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=Tuscany&results=2
> > > >
> > > >
> > > > If we have the Yahoo service configured in a SCA reference using the
> > > > REST binding and then call webSearch("YahooDemo", "Tuscany", 2) on a
> > > > SCA reference object in some component code, the HTTP GET call
> > > > generated is:
> > > >
> > > http://search.yahooapis.com/WebSearchService/V1/webSearch?param1=YahooDemo&param2=Tuscany&param3=2
> > > >
> > > >
> > > > In another example, if we want to use a SOAP service which has a
> > > > request schema containing a bunch of non-required elements like:
> > > > <xs:element name="myMethod">
> > > >  <xs:complexType>
> > > >     <xs:sequence>
> > > >       <xs:element name="anArgument" minOccurs="0" type="xs:string"/>
> > > >       <xs:element name="anotherArgument" minOccurs="0"
> > > type="xs:string"/>
> > > >       <xs:element name="lastArgument" minOccurs="0" type="xs:string"/>
> > > >     </xs:sequence>
> > > >  </xs:complexType>
> > > > </xs:element>
> > > >
> > > > And this is again configured as an SCA reference (using the WS
> > > > binding). A component calling this operation would have to call
> > > > myMethod("", "", "some data") - which would mean the first 2 elements
> > > > get sent in the SOAP message with empty data (rather than being left
> > > > out completely) and only the "lastArgument" element would contain
> > > > anything useful. Doing this may also cause errors at the server as
> > > > elements are received without any data to work on.
> > > >
> > > > I think we can fix these case pretty easily (in some circumstances) by
> > > > adding a parameter name index to the tuscany::sca::core::Operation
> > > > object - so parameters have a number and an optional name. For scagen
> > > > generated C++ proxy objects, the parameter names can be based on those
> > > > provided by the header and set inside the proxy. For Python you can
> > > > use named arguments when calling methods like myMethod(
> > > > lastArgument="someData" ) or webSearch(appid="YahooDemo",
> > > > query="Tuscany", results=2). I don't think Ruby supports named
> > > > arguments, but there may be ways of using a Ruby dictionary object to
> > > > do this.
> > > >
> > > > If the Operation object passed to the ws or rest bindings contains
> > > > named arguments we can  use them in creating the right SOAP message or
> > > > HTTP call.
> > > >
> > > > Any thoughts on this? Is it worth doing?
> > > >
> > > > Cheers
> > > > Andy
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> > > > For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> > > >
> > > >
> > >
> > > Yes, you're right it's important to support named arguments specially
> > > with REST. Very good idea!
> > >
> > > --
> > > Jean-Sebastien
> >
> >
> > +1
> >
> >
> >
> > --
> > > Pete
> >
>
> See r492273 for the first part of this work - I've added support for
> argument names to the Parameter and Operation classes. I've also
> updated the Python extension to support Python keyword arguments
> (Python's name for named arguments) and updated the REST reference
> extension so that if parameter names are provided they are used
> instead of "param1", etc.
> Also see the new RestYahoo sample for a demonstration of all this working.
>
> Cheers
> Andy
>

Also see r492630 for the next part of this. I've updated SCAGEN to set
the parameter names in the generated proxy code (using the parameter
names found in the interface header), so CPP components can now make
named argument calls to Python components or REST references.

Cheers
Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: [C++] Named arguments

Posted by Andrew Borley <aj...@gmail.com>.
On 12/22/06, Pete Robbins <ro...@googlemail.com> wrote:
> On 22/12/06, Jean-Sebastien Delfino <js...@apache.org> wrote:
> >
> > Andrew Borley wrote:
> > > Hi all,
> > >
> > > I was looking to put together another "real-world" sample for SCA C++,
> > > using Sebastien's REST support to invoke the Yahoo REST services.
> > > Unfortunately, this won't currently work due to how we support
> > > arguments - currently they're indexed purely by number.
> > >
> > > The Yahoo REST services need an HTTP GET call like:
> > >
> > http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=Tuscany&results=2
> > >
> > >
> > > If we have the Yahoo service configured in a SCA reference using the
> > > REST binding and then call webSearch("YahooDemo", "Tuscany", 2) on a
> > > SCA reference object in some component code, the HTTP GET call
> > > generated is:
> > >
> > http://search.yahooapis.com/WebSearchService/V1/webSearch?param1=YahooDemo&param2=Tuscany&param3=2
> > >
> > >
> > > In another example, if we want to use a SOAP service which has a
> > > request schema containing a bunch of non-required elements like:
> > > <xs:element name="myMethod">
> > >  <xs:complexType>
> > >     <xs:sequence>
> > >       <xs:element name="anArgument" minOccurs="0" type="xs:string"/>
> > >       <xs:element name="anotherArgument" minOccurs="0"
> > type="xs:string"/>
> > >       <xs:element name="lastArgument" minOccurs="0" type="xs:string"/>
> > >     </xs:sequence>
> > >  </xs:complexType>
> > > </xs:element>
> > >
> > > And this is again configured as an SCA reference (using the WS
> > > binding). A component calling this operation would have to call
> > > myMethod("", "", "some data") - which would mean the first 2 elements
> > > get sent in the SOAP message with empty data (rather than being left
> > > out completely) and only the "lastArgument" element would contain
> > > anything useful. Doing this may also cause errors at the server as
> > > elements are received without any data to work on.
> > >
> > > I think we can fix these case pretty easily (in some circumstances) by
> > > adding a parameter name index to the tuscany::sca::core::Operation
> > > object - so parameters have a number and an optional name. For scagen
> > > generated C++ proxy objects, the parameter names can be based on those
> > > provided by the header and set inside the proxy. For Python you can
> > > use named arguments when calling methods like myMethod(
> > > lastArgument="someData" ) or webSearch(appid="YahooDemo",
> > > query="Tuscany", results=2). I don't think Ruby supports named
> > > arguments, but there may be ways of using a Ruby dictionary object to
> > > do this.
> > >
> > > If the Operation object passed to the ws or rest bindings contains
> > > named arguments we can  use them in creating the right SOAP message or
> > > HTTP call.
> > >
> > > Any thoughts on this? Is it worth doing?
> > >
> > > Cheers
> > > Andy
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> > >
> > >
> >
> > Yes, you're right it's important to support named arguments specially
> > with REST. Very good idea!
> >
> > --
> > Jean-Sebastien
>
>
> +1
>
>
>
> --
> > Pete
>

See r492273 for the first part of this work - I've added support for
argument names to the Parameter and Operation classes. I've also
updated the Python extension to support Python keyword arguments
(Python's name for named arguments) and updated the REST reference
extension so that if parameter names are provided they are used
instead of "param1", etc.
Also see the new RestYahoo sample for a demonstration of all this working.

Cheers
Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: [C++] Named arguments

Posted by Pete Robbins <ro...@googlemail.com>.
On 22/12/06, Jean-Sebastien Delfino <js...@apache.org> wrote:
>
> Andrew Borley wrote:
> > Hi all,
> >
> > I was looking to put together another "real-world" sample for SCA C++,
> > using Sebastien's REST support to invoke the Yahoo REST services.
> > Unfortunately, this won't currently work due to how we support
> > arguments - currently they're indexed purely by number.
> >
> > The Yahoo REST services need an HTTP GET call like:
> >
> http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=Tuscany&results=2
> >
> >
> > If we have the Yahoo service configured in a SCA reference using the
> > REST binding and then call webSearch("YahooDemo", "Tuscany", 2) on a
> > SCA reference object in some component code, the HTTP GET call
> > generated is:
> >
> http://search.yahooapis.com/WebSearchService/V1/webSearch?param1=YahooDemo&param2=Tuscany&param3=2
> >
> >
> > In another example, if we want to use a SOAP service which has a
> > request schema containing a bunch of non-required elements like:
> > <xs:element name="myMethod">
> >  <xs:complexType>
> >     <xs:sequence>
> >       <xs:element name="anArgument" minOccurs="0" type="xs:string"/>
> >       <xs:element name="anotherArgument" minOccurs="0"
> type="xs:string"/>
> >       <xs:element name="lastArgument" minOccurs="0" type="xs:string"/>
> >     </xs:sequence>
> >  </xs:complexType>
> > </xs:element>
> >
> > And this is again configured as an SCA reference (using the WS
> > binding). A component calling this operation would have to call
> > myMethod("", "", "some data") - which would mean the first 2 elements
> > get sent in the SOAP message with empty data (rather than being left
> > out completely) and only the "lastArgument" element would contain
> > anything useful. Doing this may also cause errors at the server as
> > elements are received without any data to work on.
> >
> > I think we can fix these case pretty easily (in some circumstances) by
> > adding a parameter name index to the tuscany::sca::core::Operation
> > object - so parameters have a number and an optional name. For scagen
> > generated C++ proxy objects, the parameter names can be based on those
> > provided by the header and set inside the proxy. For Python you can
> > use named arguments when calling methods like myMethod(
> > lastArgument="someData" ) or webSearch(appid="YahooDemo",
> > query="Tuscany", results=2). I don't think Ruby supports named
> > arguments, but there may be ways of using a Ruby dictionary object to
> > do this.
> >
> > If the Operation object passed to the ws or rest bindings contains
> > named arguments we can  use them in creating the right SOAP message or
> > HTTP call.
> >
> > Any thoughts on this? Is it worth doing?
> >
> > Cheers
> > Andy
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> >
> >
>
> Yes, you're right it's important to support named arguments specially
> with REST. Very good idea!
>
> --
> Jean-Sebastien


+1



-- 
> Pete

Re: [C++] Named arguments

Posted by Jean-Sebastien Delfino <js...@apache.org>.
Andrew Borley wrote:
> Hi all,
>
> I was looking to put together another "real-world" sample for SCA C++,
> using Sebastien's REST support to invoke the Yahoo REST services.
> Unfortunately, this won't currently work due to how we support
> arguments - currently they're indexed purely by number.
>
> The Yahoo REST services need an HTTP GET call like:
> http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=Tuscany&results=2 
>
>
> If we have the Yahoo service configured in a SCA reference using the
> REST binding and then call webSearch("YahooDemo", "Tuscany", 2) on a
> SCA reference object in some component code, the HTTP GET call
> generated is:
> http://search.yahooapis.com/WebSearchService/V1/webSearch?param1=YahooDemo&param2=Tuscany&param3=2 
>
>
> In another example, if we want to use a SOAP service which has a
> request schema containing a bunch of non-required elements like:
> <xs:element name="myMethod">
>  <xs:complexType>
>     <xs:sequence>
>       <xs:element name="anArgument" minOccurs="0" type="xs:string"/>
>       <xs:element name="anotherArgument" minOccurs="0" type="xs:string"/>
>       <xs:element name="lastArgument" minOccurs="0" type="xs:string"/>
>     </xs:sequence>
>  </xs:complexType>
> </xs:element>
>
> And this is again configured as an SCA reference (using the WS
> binding). A component calling this operation would have to call
> myMethod("", "", "some data") - which would mean the first 2 elements
> get sent in the SOAP message with empty data (rather than being left
> out completely) and only the "lastArgument" element would contain
> anything useful. Doing this may also cause errors at the server as
> elements are received without any data to work on.
>
> I think we can fix these case pretty easily (in some circumstances) by
> adding a parameter name index to the tuscany::sca::core::Operation
> object - so parameters have a number and an optional name. For scagen
> generated C++ proxy objects, the parameter names can be based on those
> provided by the header and set inside the proxy. For Python you can
> use named arguments when calling methods like myMethod(
> lastArgument="someData" ) or webSearch(appid="YahooDemo",
> query="Tuscany", results=2). I don't think Ruby supports named
> arguments, but there may be ways of using a Ruby dictionary object to
> do this.
>
> If the Operation object passed to the ws or rest bindings contains
> named arguments we can  use them in creating the right SOAP message or
> HTTP call.
>
> Any thoughts on this? Is it worth doing?
>
> Cheers
> Andy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>

Yes, you're right it's important to support named arguments specially 
with REST. Very good idea!

-- 
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org