SOA
Building SOA Solutions with SCA - Service Component Architecture
Part One of a Two-Part Article
Jan. 24, 2006 09:00 AM
Listing 2:
public class CreditApprovalImpl implements CreditRequest {
public DataObject calulateCreditScore(DataObject creditApp) {
ServiceManager serviceManager = new ServiceManager();
BOFactory bof =
(BOFactory)serviceManager.locateService("com/ibm/websphere/bo/BOFactory");
DataObject creditRating = bof.create("http://CreditApproval", "CreditRating");
creditRating.setString("customerId", creditApp.getString("customerId"));
creditRating.setInt("creditScore", 750);
creditRating.setDouble("creditLimit", 10000d);
return creditRating;
}
}
In this implementation class, we use the CreditApplication input to create a simple CreditRating business object that we then return to the caller.
A service component is defined in a Service Component Definition Language (SCDL) file. A component file created with SCDL is roughly analogous to an EJB deployment descriptor, in that it defines the interface, implementation, and several qualities of service requirements of an SCA component. The SCDL file for the Java classes above would look like this:
Listing 3:
<?xml version="1.0" encoding="UTF-8"?>
<scdl:component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:java="http://www.ibm.com/xmlns/prod/websphere/scdl/java/6.0.0"
xmlns:ns1=
"http://CreditApproval/CreditRequest"
xmlns:scdl="http://www.ibm.com/xmlns/prod/websphere/scdl/6.0.0"
xmlns:wsdl="http://www.ibm.com/xmlns/prod/websphere/scdl/wsdl/6.0.0"
displayName="CreditApproval" name="CreditApproval">
<interfaces>
<interface xsi:type="java:JavaInterface" interface="CreditRequest " >
<method name="calulateCreditScore"/>
</interface>
</interfaces>
<implementation xsi:type="java:JavaImplementation" class=" CreditApprovalImpl"/>
</scdl:component>
Similarly, we could have used WSDL to represent the interface as shown here:
Listing 4:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:bons1="http://CreditApproval"
xmlns:tns="http://CreditApproval/CreditRequest"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CreditRequest"
targetNamespace="http://CreditApproval/CreditRequest">
<wsdl:types>
<xsd:schema targetNamespace="http://CreditApproval/CreditRequest"
xmlns:bons1="http://CreditApproval"
xmlns:tns="http://CreditApproval/CreditRequest"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://CreditApproval"
schemaLocation="xsd-includes/http.CreditApproval.xsd"/>
<xsd:element name="calulateCreditScore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CreditApp" nillable="true"
type="bons1:CreditApp"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="calulateCreditScoreResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CreditRating" nillable="true"
type="bons1:CreditRating"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="calulateCreditScoreRequestMsg">
<wsdl:part element="tns:calulateCreditScore"
name="calulateCreditScoreParameters"/>
</wsdl:message>
<wsdl:message name="calulateCreditScoreResponseMsg">
<wsdl:part element="tns:calulateCreditScoreResponse"
name="calulateCreditScoreResult"/>
</wsdl:message>
<wsdl:portType name="CreditRequest">
<wsdl:operation name="calulateCreditScore">
<wsdl:input message="tns:calulateCreditScoreRequestMsg"
name="calulateCreditScoreRequest"/>
<wsdl:output message="tns:calulateCreditScoreResponseMsg"
name="calulateCreditScoreResponse"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
The implementation class could look the same (except it would obviously not implement any Java interface since it is defined as WSDL).
Our SCDL file would bind the interface to a WSDL document:
Listing 5:
<?xml version="1.0" encoding="UTF-8"?>
<scdl:component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:java="http://www.ibm.com/xmlns/prod/websphere/scdl/java/6.0.0"
xmlns:ns1="http://CreditApproval/CreditRequest"
xmlns:scdl="http://www.ibm.com/xmlns/prod/websphere/scdl/6.0.0"
xmlns:wsdl="http://www.ibm.com/xmlns/prod/websphere/scdl/wsdl/6.0.0"
displayName="CreditApproval" name="CreditApproval">
<interfaces>
<interface xsi:type="wsdl:WSDLPortType" portType="ns1:CreditRequest">
<method name="calulateCreditScore"/>
</interface>
</interfaces>
<implementation xsi:type="java:JavaImplementation" class="CreditApprovalImpl"/>
</scdl:component>
About Roland BarciaRoland Barcia is a consulting IT specialist for IBM Software Services for WebSphere in the New York/New Jersey Metro area. He is the author of one of the most popular article series on the developerWorks WebSphere site, www-106.ibm.com/developerworks/websphere/techjournal/0401_barcia/barcia.html, and is also a coauthor of IBM WebSphere: Deployment and Advanced Configuration. You can find more information about him at http://web.njit.edu/~rb54
About Jeff BrentJeff Brent is an Advisory Software Engineer for the WebSphere Business Integration Competency Center (WBICC). His responsibilities include helping independent software vendors develop integration strategies for WebSphere products.