Skip to main content

Configure WSO2 DSS with Cassandra

Here are the steps to setup DSS and Cassandra integration

Setup 1: download and install Cassandra
WSO2 DSS 3.5.0 is based on WSO2 Carbon 4.4.2 and Cassandra version 2.0 is recommended
WSO2 DSS 3.2.2 is based on WSO2 Carbon 4.2.0 and Cassandra version 2.0 is recommended

Step 2: download and install WSO2DSS
http://wso2.com/products/data-services-server/
https://docs.wso2.com/display/DSS322/WSO2+Data+Services+Server+Documentation

Step 3: configure following operations in DSS
Create Key space - UserKS
CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}
Create column family - User (id, name, country)
CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))
addUser
INSERT INTO UserKS.User (id, name, country) values (?,?,?)
getUsers
SELECT * FROM UserKS.User
updateUser
UPDATE UserKS.User SET country = ? WHERE id =?
deleteUser
DELETE FROM UserKS.User WHERE id = ?

You can try the above command using cqlsh tool resides in cassandra/bin

Option1: Going through the WSO2DSS Management Console Wizard and configure
Option2: Use Developer Studio, create a CAR file and deploy it on WSO2DSS.

https://docs.wso2.com/display/DVS371/Creating+Data+Services+Server+Artifacts

Note: DSS generates a .dbs file which contains all the configurations, which you can find out in wso2dss-3.2.2\repository\deployment\server\dataservices location

Step 4: execute Cassandra queries from Soap UI
Get the WSDL from the WSO2DSS Management console, add it to the Soap UI and invoke

Contents of .dbs file
<data name="UserDS" transports="http https local">
    <config id="UserDataSource">
        <property name="cassandraServers">localhost</property>
    </config>
    <query id="createKeySpace" useConfig="UserDataSource">
        <expression>CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}</expression>
    </query>
    <query id="dropKeySpace" useConfig="UserDataSource">
        <expression>DROP KEYSPACE UserKS</expression>
    </query>
    <query id="createUserTable" useConfig="UserDataSource">
        <expression>CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))</expression>
    </query>
    <query id="addUser" useConfig="UserDataSource">
        <expression>INSERT INTO UserKS.User (id, name, country) values (?,?,?)</expression>
        <param name="id" ordinal="1" sqlType="STRING"/>
        <param name="name" ordinal="2" sqlType="STRING"/>
        <param name="country" ordinal="3" sqlType="STRING"/>
    </query>
    <query id="getUsers" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
    </query>
    <query id="updateUser" useConfig="UserDataSource">
        <expression>UPDATE UserKS.User SET country = ? WHERE id =?</expression>
        <param name="country" sqlType="STRING"/>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="deleteUser" useConfig="UserDataSource">
        <expression>DELETE FROM UserKS.User WHERE id = ?</expression>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="getUserById" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User where id = ?</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
        <param name="id" sqlType="STRING"/>
    </query>
    <operation name="createKeySpace">
        <call-query href="createKeySpace"/>
    </operation>
    <operation name="dropKeySpace">
        <call-query href="dropKeySpace"/>
    </operation>
    <operation name="createUserTable">
        <call-query href="createUserTable"/>
    </operation>
    <operation name="addUser">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </operation>
    <operation name="getUsers">
        <call-query href="getUsers"/>
    </operation>
    <operation name="updateUser">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="deleteUser">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="getUserById">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <resource method="GET" path="user/get">
        <call-query href="getUsers"/>
    </resource>
    <resource method="GET" path="user/get/{id}">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="PUT" path="user/add/{id}/{name}/{country}">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </resource>
    <resource method="POST" path="user/update/{country}/{id}">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="DELETE" path="user/delete/{id}">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
</data>

Comments

Popular posts from this blog

How to generate random unique number in SOAP UI request

eg 1: ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} eg 2: ${=java.util.UUID.randomUUID()} ${=java.util.UUID.randomUUID()} ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf

Tips on using environment variables in WSO2 Integration Cloud

Environment variables allow you to change an application's internal configuration without changing its source code. Let’s say you want to deploy the same application in development, testing  and production environments. Then database related configs and some other internal configurations may change from one environment to another. If we can define these configurations as an environment variables we can easily set those without changing the source code of that application. When you deploy your application in WSO2 Integration Cloud, it lets you define environment variables via the UI. Whenever you change the values of environment variables, you just need to redeploy the application for the changes to take effect. Predefined environment variables Key Concepts - Environment Variables   provides you some predefined set of environment variables which will be useful when deploying applications in WSO2 Integration Cloud. Sample on how to use environment variables U se

VFS access SFTP with special character password

Learn WSO2 ESB VFS Transport https://docs.wso2.com/display/ESB481/VFS+Transport When we need to access the FTP server using SFTP, VFS connection-specific URL need to be given as : <parameter name="transport.vfs.FileURI">vfs:sftp://username:p@ssword@ftp.server.com/filePath?vfs.passive=true</parameter> When the password contains a special characters (eg: p@ssword), it gives the following error. 2015-03-27 13:06:03,766  [-]   [PassThroughMessageProcessor-5]  ERROR VFSTransportSender cannot resolve replyFile org.apache.commons.vfs2.FileSystemException: Invalid absolute URI "sftp://username:***@ftp.server.com/filePath?vfs.passive=true". Solution 1: Replace the special characters with the respective hex representation. <parameter name="transport.vfs.FileURI">vfs:sftp://username:p%40ssword@ftp.server.com/filePath?vfs.passive=true</parameter> Char Hex Code ------- -------- [space] %20 &