GVExample CCardPay
Contents
Description
This service has the purpose of showing how GreenVulcano® ESB uses DataHandler to query a DB and implement Web Services.
CCardPay Service executes the following operations:
- Receives a Web Service request from client, with a credit card number to be controlled.
- If this card is locally managed, reads the data from DB using DataHandler.
- If this card is managed by an external system, forwards a Web Service request to that system.
- Returns the response to the client
VulCon Configuration
To configure CCardPay service follow these steps:
- Define Systems, Channels and Operations
- Define the Services
- Implement the flows.
Defining Systems, Channels and Operations
In order to define a System, go to VulCon core view and insert the System CREDIT. Inside of it create the Channel CHANNEL_CREDIT_WS in order to create an "internal" Participant. We also create the System CREDIT_EXTERNAL with the Channel CHANNEL_CREDIT_EXT corresponding to an "external" Participant.
Note that the easiest way to configure a Web service with VulCon® is using the Wizard. We start from a Web Service WSDL, that describes a withdrawal operation on a credit card.
From the Core view of VulCon®, right clicking the Services element, launch the Wizard Call Web Service and, after selecting the WSDL file -in this example we use ExternalCreditService.wsdl present in folder ${{gv.app.home}}/xmlconfig/wsdl-, choose the parameters to create the GreenVulcano® ESB service.
Two new Services, Pay and Query, and two ws-call operations, pay and query, will be created into the System CREDIT, channel CREDIT_EXTERNAL. We change those names to CCardPay and CCardQuery for the services, PayExternal and QueryExternal for the ws-call operations respectively. Now is possible to modify the workflow.
From the VulCon® Core view, element System "CREDIT" -> Channel "CHANNEL_CREDIT_WS", insert a dh-call operation and set its attributes and sub-elements as follow:
Element | Value |
---|---|
dh-call | name="DataHandler" |
dh-call/DBOBuilder | name="CREDIT::CCardPay" jdbc-connection-name="ds.test_gv" |
dh-call/DBOBuilder/DHVariables/DHVariable | name="decimal-separator" value="." |
dh-call/DBOBuilder/DHVariables/DHVariable | name="grouping-separator" value="," |
dh-call/DBOBuilder/DHVariables/DHVariable | name="format" value="#0.00" |
dh-call/DBOBuilder/DBOUpdate | name="CCardPay" transformation="CCardPay" type="dbo" |
dh-call/DBOBuilder/DBOUpdate/statement | id="0" type="update" update CREDIT_CARD set CREDIT= CREDIT - ? where CNUMBER=? and ENABLED='Y' and CREDIT >= ? |
The operation defined in the DataHandler makes use of the data-transformation module for the data transformations that allows to have data in XML format. So, you need to define the following parameters into the GVDataTransformation section:
Element | Attributes |
---|---|
DataSourceSet/LocalFSDataSource | formatHandled="xsl" name="XSLDataSource" repositoryHome="${{gv.app.home}}/gvdte/datasource/xsl" type="datasource" |
Transformations/XSLTransformation | name="CCardPay" DataSourceSet="Default" XSLMapName="DataHandler/CREDIT/CCardPay.xsl" type="transformation" |
Transformations/XSLTransformation | name="PayExternalInput" DataSourceSet="Default" XSLMapName="CREDIT_EXTERNAL/PayExternalInput.xsl" type="transformation" |
Transformations/XSLTransformation | name="PayExternalOutput" DataSourceSet="Default" XSLMapName="CREDIT_EXTERNAL/PayExternalOutput.xsl" type="transformation" |
Now define a ws-call operation into System CREDIT_EXTERNAL -> Channel CHANNEL_CREDIT_EXT. Its attributes and sub-elements defined will be setted as:
Attribute | Value |
---|---|
ws-call | name="PayExternal" |
ws-call/AxisWebServiceInvoker | operation="Pay" ref-dp="EXTERNAL::PayWSDataProvider" returnType="body-element" type="invoker" |
ws-call/AxisWebServiceInvoker/WSDLInfo | type="wsdlinfo" wsdl="file://${{gv.app.home}}/xmlconfig/wsdl/ExternalCreditService.wsdl" |
The ws-call operation already defined makes use of the Data provider module. So, you need to define the following parameters into the GVDataProviderManager section, present in the Adapter Core View of VulCon®:
Element | Attributes |
---|---|
Axis2MessageContextDataProvider | name="EXTERNAL::PayWSDataProvider" |
Axis2MessageContextDataProvider/Field | direction="OUT" key="message" |
Axis2MessageContextDataProvider/Field/Expression | type="ognl"
envelope.body.addChild(@org.apache.axis2.util.XMLUtils @toOM(#input.object.getDocumentElement())) |
Flow implementation
In order to define the CCardPay service Flow design it as shown in the picture:
The service receives a Web Service request from a client with a credit card number. If this card is managed locally, reads its data using DataHandler, otherwise forwards the request to an external system using Web Services.
The following table shows the parameters to be defined for each Flow node:
Attribute | Value |
---|---|
first-node | Prepare |
Conditions/GVBufferCondition | condition="isInternalCCard" |
Conditions/GVBufferCondition/Property | name="IS_INTERNAL" operator="equal" type="gvbuffer-field" value="true" value-type="text" |
ChangeGVBufferNode | dump-in-out="true" id="prepare" input="input" next-node-id="check_internal" clear-data="false" |
ChangeGVBufferNode/PropertyDef | name="CNUMBER" value="js{{gvesb::var doc=XMLUtils.parseDOM_S(new java.lang.String(object.getObject()),false,true); XMLConfig.get(doc,'//cred:cnumber')}}" |
ChangeGVBufferNode/PropertyDef | name="IS_INTERNAL" value="sql{{ds.test_gv::select decode(count(*), 1, 'true', 'false') from credit_card where cnumber=ognl{{#object.getProperty('CNUMBER')}}}}" |
GVNodeCheck | default-id="PayExternal" id="check_internal" input="input" on-exception-id="end" |
GVNodeCheck/GVRouting | condition="isInternalCCard" next-node-id="pay_internal" |
GVOperationNode | dump-in-out="false" id="pay_internal" id-system="CREDIT" input="input" next-node-id="end" op-type="call" operation-name="DataHandler" output="output" |
GVOperationNode | dump-in-out="false" id="PayExternal" id-system="CREDIT_EXTERNAL" input="input" next-node-id="end" op-type="call" operation-name="PayExternal" |
GVOperationNode/InputServices/gvdte-service | critical="yes" internal="yes" remove-fields="yes" type="service" |
GVOperationNode/InputServices/gvdte-service/map-name-param | name="map-name" value="PayExternalInput" |
GVOperationNode/InputServices/gvdte-service/gvdte-context-call | name="PayExternalInput" |
GVOperationNode/OutputServices/gvdte-service | critical="yes" internal="yes" remove-fields="yes" type="service" |
GVOperationNode/OutputServices/gvdte-service/map-name-param | name="map-name" value="PayExternalOutput" |
GVOperationNode/OutputServices/gvdte-service/gvdte-context-call | name="PayExternalOutput" |
GVEndNode | end-business-process="yes" id="end" op-type="end" output="output" |
GV Console Configuration
It is time to deploy and test your new Service. To do that follows these steps:
Suppose you have saved the VulCon Configuration file as "${{gv.app.home}}/TEST/REPG1.zip". To deploy the new Service follow this steps:
- Start GreenVulcano® ESB
- Access to the GV Console.
- In the Deploy New Service section click Sfoglia... (Browse) and select the file where you have saved the VulCon® configuration.
- Click Submit.
The section Deploy Services will be open. In this section you can select the services you want to deploy.
- Clicking on service CCardPay a new view will be open containing the files GVCore.xml present in local and in server.
- Click Deploy. Now you can save the document and write some notes about it.
- Save the Document. Saving you return to the Deploy Service section.
Now pass to the GV Console® section Utility.
- Click on Reload configuration
- Select GVCore.xml and GVAdapters.xml and then Reload. A new windows will be open to confirm the operation
- Click OK.
Go to the GV Console® section Testing. In this section you can finally test your new services:
- Into the Service voice select CCardPay
- Into the System voice select CREDIT_EXTERNAL
- Select the Payload on input containing the credit card number you want to use and the amount to reduce from.
- Click RequestReply
The Testing View will be expanded and it is also possible to view the GVBuffer Output panel where there are present some properties, among these the REC_READ property setted to 1, representing the number of record read from DB.
The file TestOutput.txt will be generated in the directory ${{gv.app.home}}/log as previously setted (see Testing area) containing information about the credit card numbers you passed in input and the number of records founded and updated.
<pre>
----------- TEST N. 0 2012.03.02 at 14:11:38 -----------
Standard Field:
system = CREDIT_EXTERNAL
service = CCardPay
id = 7F0001014F50AFC600014063
retCode = 0
GVBuffer: NULL
Properties:
REC_DISCARD = 0
IS_INTERNAL = true
REC_TOTAL = 1
REC_UPDATE = 1
REC_INSERT = 0
REC_READ = 0
CNUMBER = 1234123415555666
REC_DISCARD_CAUSE =
</pre>