You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by fahim salim <sa...@gmail.com> on 2008/11/27 11:17:34 UTC

Re: References to remote services

Hello All

I would be interested to have an exemple of an application which is not SCA
aware accessing a remote SCA service which is exposed as a POJO component
I understood it's possible but what kind of binding will be used in this
case ?

For example, how can I access the Service exposed by
CalculatorServiceCompoent   from a client which is not SCA aware ?

Thanks
Fahim


2008/10/17 Luciano Resende <lu...@gmail.com>

> Just trying to add here, there was a thread about running the
> calculator-distributed from different machines, please take a look
>
> [1] http://markmail.org/message/qlirdpi46aydoa5b
>
> On Thu, Oct 16, 2008 at 8:01 AM, Simon Laws <si...@googlemail.com>
> wrote:
> >
> >
> > On Thu, Oct 16, 2008 at 1:17 PM, Seamus Kerrigan (skerriga)
> > <sk...@cisco.com> wrote:
> >>
> >> Hi,
> >>
> >> I'm a relative newbie to Tuscany and I have been looking at how to use
> >> an SCA domain across multiple JVMs (web servers) and machine boundaries.
> >> I've seen some of the nice examples that show how to add a remote
> >> reference (e.g. calculator-distributed) but in all these examples the
> >> Java code for each of the nodes are all on the same build path and
> >> therefore the components can easily reference each others Java
> >> interfaces e.g. CalculatorServiceImpl has direct access to AddService.
> >>
> >> However, I'm imagining that you may want to add a reference to a related
> >> Tuscany component where it's code would in a separate project or even
> >> source code repository. For example, what if AddService was written by
> >> another team and deployed separately to a web server. How could the
> >> remote component be referenced to build a composite in this case? Do I
> >> still need access to the remote Java interface or else have to publish
> >> the remote service via SOAP and generate client stubs?
> >>
> >> Thanks in advance,
> >> Seamus
> >
> > Hi Seamus
> >
> > The short answer is yes.
> >
> > If the client side component is going to reference a (remote) component
> then
> > it needs to understand the target components interface. Tuscany supports
> two
> > mechanisms for describing a service interface, interface.java or
> > interface.wsdl. So either one of these will do.
> >
> > If the remote service provider gives you WSDL to describe the service you
> > are trying to communicate with and if you are using implementation.java
> for
> > the client component then you will need to generate a java interface from
> > the WSDL you have been given. You need this in order to type the
> reference
> > inside your client component. Other programming models may not need this,
> > for example, BPEL.
> >
> > Hope this helps.
> >
> > Simon
> >
>
>
>
> --
> Luciano Resende
> Apache Tuscany, Apache PhotArk
> http://people.apache.org/~lresende <http://people.apache.org/%7Elresende>
> http://lresende.blogspot.com/
>

Re: References to remote services

Posted by fahim salim <sa...@gmail.com>.
Hello Simon

Now I'm sure having understood what I was thinking concerning the way to
acces an SCA implemented service.

Thanks for your explanations.
Fahim

2008/11/27 Simon Laws <si...@googlemail.com>

>
>
> On Thu, Nov 27, 2008 at 10:17 AM, fahim salim <sa...@gmail.com> wrote:
>
>> Hello All
>>
>> I would be interested to have an exemple of an application which is not
>> SCA aware accessing a remote SCA service which is exposed as a POJO
>> component
>> I understood it's possible but what kind of binding will be used in this
>> case ?
>>
>> For example, how can I access the Service exposed by
>> CalculatorServiceCompoent   from a client which is not SCA aware ?
>>
>> Thanks
>> Fahim
>>
>>
>> 2008/10/17 Luciano Resende <lu...@gmail.com>
>>
>>> Just trying to add here, there was a thread about running the
>>> calculator-distributed from different machines, please take a look
>>>
>>> [1] http://markmail.org/message/qlirdpi46aydoa5b
>>>
>>> On Thu, Oct 16, 2008 at 8:01 AM, Simon Laws <si...@googlemail.com>
>>> wrote:
>>> >
>>> >
>>> > On Thu, Oct 16, 2008 at 1:17 PM, Seamus Kerrigan (skerriga)
>>> > <sk...@cisco.com> wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I'm a relative newbie to Tuscany and I have been looking at how to use
>>> >> an SCA domain across multiple JVMs (web servers) and machine
>>> boundaries.
>>> >> I've seen some of the nice examples that show how to add a remote
>>> >> reference (e.g. calculator-distributed) but in all these examples the
>>> >> Java code for each of the nodes are all on the same build path and
>>> >> therefore the components can easily reference each others Java
>>> >> interfaces e.g. CalculatorServiceImpl has direct access to AddService.
>>> >>
>>> >> However, I'm imagining that you may want to add a reference to a
>>> related
>>> >> Tuscany component where it's code would in a separate project or even
>>> >> source code repository. For example, what if AddService was written by
>>> >> another team and deployed separately to a web server. How could the
>>> >> remote component be referenced to build a composite in this case? Do I
>>> >> still need access to the remote Java interface or else have to publish
>>> >> the remote service via SOAP and generate client stubs?
>>> >>
>>> >> Thanks in advance,
>>> >> Seamus
>>> >
>>> > Hi Seamus
>>> >
>>> > The short answer is yes.
>>> >
>>> > If the client side component is going to reference a (remote) component
>>> then
>>> > it needs to understand the target components interface. Tuscany
>>> supports two
>>> > mechanisms for describing a service interface, interface.java or
>>> > interface.wsdl. So either one of these will do.
>>> >
>>> > If the remote service provider gives you WSDL to describe the service
>>> you
>>> > are trying to communicate with and if you are using implementation.java
>>> for
>>> > the client component then you will need to generate a java interface
>>> from
>>> > the WSDL you have been given. You need this in order to type the
>>> reference
>>> > inside your client component. Other programming models may not need
>>> this,
>>> > for example, BPEL.
>>> >
>>> > Hope this helps.
>>> >
>>> > Simon
>>> >
>>>
>>>
>>>
>>> --
>>> Luciano Resende
>>> Apache Tuscany, Apache PhotArk
>>> http://people.apache.org/~lresende<http://people.apache.org/%7Elresende>
>>> http://lresende.blogspot.com/
>>>
>>
>>
> Hi Fahim
>
> When an application is not SCA aware you will be dealing with existing
> remote protocols such as SOAP web services. To strip this down to a very
> basic sample. Imagine a service defined like
>
>
>     <component name="HelloWorldServiceWSComponent">
>         <implementation.java class="helloworld.HelloWorldServiceImpl"
> requires="tuscany:identity"/>
>         <service name="HelloWorldService" requires="authentication">
>             <interface.java interface="helloworld.HelloWorldService"/>
>             <binding.ws uri="
> http://localhost:8085/HelloWorldServiceWSComponent"/>
>         </service>
>     </component>
>
> Then I could send an XML SOAP request to
> http://localhost:8085/HelloWorldServiceWSComponent and expect to get and
> answer. So in a very basic and static way I could do something like.
>
>     public void testWSViaNonSCAClient() {
>
>         try {
>             String token ="MyToken";
>             String encToken = Base64.encode(token.getBytes());
>
>             String response = callService("
> http://L3AW203:8085/HelloWorldServiceWSComponent",
>                                           "<?xml version='1.0'
> encoding='UTF-8'?>" +
>                                             "<soapenv:Envelope
> xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\<http://schemas.xmlsoap.org/soap/envelope/%5C>">"
> +
>                                              "<soapenv:Header>" +
>                                                "<ns2:Token xmlns:ns2=\"
> http://helloworld/\ <http://helloworld/%5C>">" + encToken + "</ns2:Token>"
> +
>                                              "</soapenv:Header>" +
>                                              "<soapenv:Body>" +
>                                                "<ns2:getGreetings
> xmlns:ns2=\"http://helloworld/\ <http://helloworld/%5C>">" +
>                                                  "<arg0>Simon</arg0>" +
>                                                "</ns2:getGreetings>" +
>                                              "</soapenv:Body>" +
>                                             "</soapenv:Envelope>" );
>             System.out.println(">>>" + response);
>         } catch(Exception ex) {
>             System.out.println(ex.toString());
>         }
>     }
>
>
>     public String callService(String url, String requestString) throws
> Exception {
>         System.out.println("Request = " + requestString);
>         WebConversation wc   = new WebConversation();
>         wc.setAuthorization("Me", "MyPasswd");
>         WebRequest request   = new PostMethodWebRequest( url,
>                                                          new
> ByteArrayInputStream(requestString.getBytes("UTF-8")),"text/xml");
>         request.setHeaderField("SOAPAction", "");
>         WebResponse response = wc.getResource(request);
>         System.out.println("Response= " +
> response.getText());
>         Assert.assertEquals(200, response.getResponseCode());
>         return response.getText();
>     }
>
> Which I cut from a Tuscany itest [1] and which uses httpunit to send a
> static string to our SCA service. The static string just happens to be an
> XML/SOAP request. I'm not suggesing you write you code in this static way.
> Would be much better to use a web services client API as is provided by Axis
> or JAXWS rather than doing this static stuff.
>
> Hopefully though this makes the point that if you have a client that wants
> to talk to an SCA component then, as long as you inderstand which binding
> has been chosen in the SCA application, you client is free to do what it
> likes as long as the messages it sends are appropriate for the chosen
> protocol.
>
> Regards
>
> Simon
>
> [1]
> http://svn.apache.org/repos/asf/tuscany/branches/sca-java-1.x/itest/policy-security-token/
>

Re: References to remote services

Posted by Simon Laws <si...@googlemail.com>.
On Thu, Nov 27, 2008 at 10:17 AM, fahim salim <sa...@gmail.com> wrote:

> Hello All
>
> I would be interested to have an exemple of an application which is not SCA
> aware accessing a remote SCA service which is exposed as a POJO component
> I understood it's possible but what kind of binding will be used in this
> case ?
>
> For example, how can I access the Service exposed by
> CalculatorServiceCompoent   from a client which is not SCA aware ?
>
> Thanks
> Fahim
>
>
> 2008/10/17 Luciano Resende <lu...@gmail.com>
>
>> Just trying to add here, there was a thread about running the
>> calculator-distributed from different machines, please take a look
>>
>> [1] http://markmail.org/message/qlirdpi46aydoa5b
>>
>> On Thu, Oct 16, 2008 at 8:01 AM, Simon Laws <si...@googlemail.com>
>> wrote:
>> >
>> >
>> > On Thu, Oct 16, 2008 at 1:17 PM, Seamus Kerrigan (skerriga)
>> > <sk...@cisco.com> wrote:
>> >>
>> >> Hi,
>> >>
>> >> I'm a relative newbie to Tuscany and I have been looking at how to use
>> >> an SCA domain across multiple JVMs (web servers) and machine
>> boundaries.
>> >> I've seen some of the nice examples that show how to add a remote
>> >> reference (e.g. calculator-distributed) but in all these examples the
>> >> Java code for each of the nodes are all on the same build path and
>> >> therefore the components can easily reference each others Java
>> >> interfaces e.g. CalculatorServiceImpl has direct access to AddService.
>> >>
>> >> However, I'm imagining that you may want to add a reference to a
>> related
>> >> Tuscany component where it's code would in a separate project or even
>> >> source code repository. For example, what if AddService was written by
>> >> another team and deployed separately to a web server. How could the
>> >> remote component be referenced to build a composite in this case? Do I
>> >> still need access to the remote Java interface or else have to publish
>> >> the remote service via SOAP and generate client stubs?
>> >>
>> >> Thanks in advance,
>> >> Seamus
>> >
>> > Hi Seamus
>> >
>> > The short answer is yes.
>> >
>> > If the client side component is going to reference a (remote) component
>> then
>> > it needs to understand the target components interface. Tuscany supports
>> two
>> > mechanisms for describing a service interface, interface.java or
>> > interface.wsdl. So either one of these will do.
>> >
>> > If the remote service provider gives you WSDL to describe the service
>> you
>> > are trying to communicate with and if you are using implementation.java
>> for
>> > the client component then you will need to generate a java interface
>> from
>> > the WSDL you have been given. You need this in order to type the
>> reference
>> > inside your client component. Other programming models may not need
>> this,
>> > for example, BPEL.
>> >
>> > Hope this helps.
>> >
>> > Simon
>> >
>>
>>
>>
>> --
>> Luciano Resende
>> Apache Tuscany, Apache PhotArk
>> http://people.apache.org/~lresende <http://people.apache.org/%7Elresende>
>> http://lresende.blogspot.com/
>>
>
>
Hi Fahim

When an application is not SCA aware you will be dealing with existing
remote protocols such as SOAP web services. To strip this down to a very
basic sample. Imagine a service defined like


    <component name="HelloWorldServiceWSComponent">
        <implementation.java class="helloworld.HelloWorldServiceImpl"
requires="tuscany:identity"/>
        <service name="HelloWorldService" requires="authentication">
            <interface.java interface="helloworld.HelloWorldService"/>
            <binding.ws uri="
http://localhost:8085/HelloWorldServiceWSComponent"/>
        </service>
    </component>

Then I could send an XML SOAP request to
http://localhost:8085/HelloWorldServiceWSComponent and expect to get and
answer. So in a very basic and static way I could do something like.

    public void testWSViaNonSCAClient() {

        try {
            String token ="MyToken";
            String encToken = Base64.encode(token.getBytes());

            String response = callService("
http://L3AW203:8085/HelloWorldServiceWSComponent",
                                          "<?xml version='1.0'
encoding='UTF-8'?>" +
                                            "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                                             "<soapenv:Header>" +
                                               "<ns2:Token xmlns:ns2=\"
http://helloworld/\">" + encToken + "</ns2:Token>" +
                                             "</soapenv:Header>" +
                                             "<soapenv:Body>" +
                                               "<ns2:getGreetings
xmlns:ns2=\"http://helloworld/\">" +
                                                 "<arg0>Simon</arg0>" +
                                               "</ns2:getGreetings>" +
                                             "</soapenv:Body>" +
                                            "</soapenv:Envelope>" );
            System.out.println(">>>" + response);
        } catch(Exception ex) {
            System.out.println(ex.toString());
        }
    }


    public String callService(String url, String requestString) throws
Exception {
        System.out.println("Request = " + requestString);
        WebConversation wc   = new WebConversation();
        wc.setAuthorization("Me", "MyPasswd");
        WebRequest request   = new PostMethodWebRequest( url,
                                                         new
ByteArrayInputStream(requestString.getBytes("UTF-8")),"text/xml");
        request.setHeaderField("SOAPAction", "");
        WebResponse response = wc.getResource(request);
        System.out.println("Response= " + response.getText());

        Assert.assertEquals(200, response.getResponseCode());
        return response.getText();
    }

Which I cut from a Tuscany itest [1] and which uses httpunit to send a
static string to our SCA service. The static string just happens to be an
XML/SOAP request. I'm not suggesing you write you code in this static way.
Would be much better to use a web services client API as is provided by Axis
or JAXWS rather than doing this static stuff.

Hopefully though this makes the point that if you have a client that wants
to talk to an SCA component then, as long as you inderstand which binding
has been chosen in the SCA application, you client is free to do what it
likes as long as the messages it sends are appropriate for the chosen
protocol.

Regards

Simon

[1]
http://svn.apache.org/repos/asf/tuscany/branches/sca-java-1.x/itest/policy-security-token/