About
This sample demonstrates the Demonstrate CRUD operation with data service of the Enterprise Integrator.
This sample creates an DSS config project that consists of a Data Service called StudentDataService and a Composite application project which is used to package and export the artifacts created within the DSS solution project.
Next Steps
Setup database and insert some bogus records
CREATE TABLE `students` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`school` varchar(50) DEFAULT NULL,
`grade` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO students (name, school, grade) VALUES
('Tim', 'Summer School', 7),
('Peter', 'Burnley High School', 10);
Update database URL and credentials in the StudentDataService.dbs file.
Executing the sample
-
Configure EI server
Attach an EI server runtime into the Developer Studio following the instructions given below (if you haven’t already done).
Navigate to the Developer Studio Dashboard and click Server under Add Server.
In the ‘Define a New Server’ dialog box, expand the WSO2 folder, and select the respective product and version.
Click Next, click Browse that is next to CARBON_HOME, and select the WSO2 EI distribution directory, to define the server runtime environment and click Next.
Review the default port details for the ESB profile of WSO2 EI. Typically, you can leave these unchanged, but if you are already running another server on these ports, specify unused ports here. Click Next.
-
Deploy the CApp project
To deploy the CApp project in the ESB server that we just added, select relevant project from the list, click Add to move it into the Configured list, and then click Finish.
The ESB server of WSO2 EI is now added inside Eclipse tooling.
-
Start the server
You will see that the server is currently stopped. Click Play button on the toolbar to start the server.
If you are prompted to save changes to any of the artifact files, click Yes.
As the server starts, the Console tab will appear. You should see messages indicating that the C-App was successfully deployed. The C-App will now be available in the ESB profile's management console (Manage -> Carbon Applications -> List).
-
Invoke the service
Use an HTTP client like cURL to invoke the service.
Create Students
curl -X POST -d @request.xml http://localhost:8280/services/StudentDataService -H "Content-Type: text/xml" -H "SOAPAction: urn:CreateStudents"The request.xml can be a file which has following content.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> <soapenv:Header/> <soapenv:Body> <dat:CreateStudents> <dat:name>Sam</dat:name> <dat:school>Mary College</dat:school> <dat:grade>8</dat:grade> </dat:CreateStudents> </soapenv:Body> </soapenv:Envelope>Read students
curl -X POST -d @request.xml http://localhost:8280/services/StudentDataService -H "Content-Type: text/xml" -H "SOAPAction: urn:ReadStudents"The request.xml can be a file which has following content.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> <soapenv:Header/> <soapenv:Body> <dat:ReadStudents/> </soapenv:Body> </soapenv:Envelope>Update students
curl -X POST -d @request.xml http://localhost:8280/services/StudentDataService -H "Content-Type: text/xml" -H "SOAPAction: urn:UpdateStudents"The request.xml can be a file which has following content.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> <soapenv:Header/> <soapenv:Body> <dat:UpdateStudents> <dat:name>Sam</dat:name> <dat:school>Mary College</dat:school> <dat:grade>6</dat:grade> <dat:id>3</dat:id> </dat:UpdateStudents> </soapenv:Body> </soapenv:Envelope>Delete students
curl -X POST -d @request.xml http://localhost:8280/services/StudentDataService -H "Content-Type: text/xml" -H "SOAPAction: urn:DeleteStudents"The request.xml can be a file which has following content.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> <soapenv:Header/> <soapenv:Body> <dat:DeleteStudents> <dat:id>3</dat:id> </dat:DeleteStudents> </soapenv:Body> </soapenv:Envelope>