Saturday, October 1, 2011

SCA (Service Component Architecture)- Part 3

This is the part 3 in the series of articles that will cover SCA(Service Component Architecture). Refer Part 1 and Part 2 before you read this.


How do I use SCA?
Even though SCA composites rely on a domain to handle the intra-component communication, the components by themselves can expose Web Services and allow consumers to interact with them using those Web Services.


Accessing services from SCA component
SCA components can use other SCA components within the same domain by using references.


Accessing services from non-SCA component implementations
Non-SCA components, which are part of the SCA module, get access to services using Module Context. They use ModuleContext in their implementations to find services. The non-SCA component implementation would include a line like the following to get access to the module context:

ModuleContext moduleContext = CurrentModuleContext.getContext().


Accessing services from non-SCA Client
A client can also use the OASIS SCAClient API to invoke a service in a remote SCA domain.The client could be a plain Java SE class with a main method which uses the OASIS SCAClient API to invoke a service in a remote SCA domain.


For instance, we can use the below client assuming, we have a helloworld service running in a SCA domain somewhere. The client needs access to the HelloWorld Interface.


Helloworld OASIS Client


package abc;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
import org.oasisopen.sca.client.SCAClientFactory;


public class HelloworldSCAClient {


    public static void main(String[] args) throws NoSuchDomainException, NoSuchServiceException {


        String domainURI = "uri:default" //or could be uri:default?wka=127.0.0.1:7654
        if (domainURI == null || domainURI.length() < 1) {
            domainURI = ;
        }


        System.out.println("HelloworldSCAClient, using domainURI " + domainURI);
        SCAClientFactory factory = SCAClientFactory.newInstance(URI.create(domainURI));


        String name = args.length < 1 ? "world" : args[0];
        System.out.println("Calling HelloworldComponent.sayHello(\"" + name + "\"):");
        Helloworld service = factory.getService(Helloworld.class, "HelloworldComponent");
        System.out.println(service.sayHello(name));
     }

}




SCA Policy Framework


SCA defines a policy framework that has:


  • Interaction Policies
Policies that might apply to bindings, for instance Security etc.
  • Implementation Policies
Local policies that apply to how a component behaves within the SCA domain. For instance the requirement that there be a transaction for this component. The intersection set between two components policies determine how they communicate with each other. Typically one domain has one security policy( double check)

These policies can be defined using WS-Policy for communication outside the domain. Communication inside the domain are not defined by the spec, so the SCA runtime is free to choose the mechanism.


Example:
PolicySet defines the list of policies and the service/reference/binding indicates which policies to apply.



<service name="MyService“ promote=“SomeComponent” requires="sca:myAuthPolicy">
   <interface.java interface="someInterface"/>
   <binding.ws port="http://host/Myservice"/>
</service>
<reference name="MyServiceRef“ promote=“SomeComponent/someService”>
   <interface.java interface="someInterface2"/>
   <binding.ws port="http://host/Myservice2" requires=“sca:myAuthPolicy”/>
</reference>




<policySet name="sca:MyUserNameToken" provides="sca:myAuthPolicy" appliesTo="sca:binding.ws">
   <wsp:Policy>
        <sp:SupportingToken>
            <wsp:Policy>
             <sp:UserNameToken>
              </sp:UserNameToken>
             </wsp:Policy>
       </sp:SupportingToken>
    </wsp:Policy>
</policySet>

The opinions and statements in this communication are my own and do not necessarily reflect the opinions or policies of CA.

No comments:

Post a Comment