Does anyone know how to connect to cassandra using JDBC connection string in SoapUI.
I have tried from my side, but not able to connect. Based on the research I came
I was able to do it with a creation of Cassandra cluster and using it to connect to the cassandra as following:
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
def rs;
//query
def qry = "select id soapuikeyspace.users where id='aaa';"
//create cluster for cassandra
Cluster cluster = new Cluster.Builder().addContactPoint("localhost").withCredentials("cassandra", "cassandra").withPort(9042).build();
//get seesionm from cassandra claster
session = cluster.connect();
//get result set
rs = session.execute(qry);
Required jar's:
This was fun, I have never worked with Cassandra before so it took me sometime to figure this one out and I think i have.
To use Cassandra you need multiple jar files, below is a screenshot of the ones i used.
I used the cassandra-cli to find out the correct port number, in my case it was 9160
.
The correct connection string is jdbc:cassandra://localhost:9160/soapuikeyspace
and the correct driver is org.apache.cassandra.cql.jdbc.CassandraDriver
.
When i tried to access Cassandra from teh JDBC step i was able to succesfully connect to Cassandra but when i tried to run a select query i got
Error getting response
and the following error trace in the soapUI logs
Sat Apr 05 17:33:09 ADT 2014:ERROR:java.sql.SQLFeatureNotSupportedException
java.sql.SQLFeatureNotSupportedException
at org.apache.cassandra.cql.jdbc.CassandraResultSet$CResultSetMetaData.getTableName(CassandraResultSet.java:1307)
at com.eviware.soapui.support.xml.XmlUtils.addResultSetXmlPart(XmlUtils.java:1712)
at com.eviware.soapui.support.xml.XmlUtils.createJdbcXmlResult(XmlUtils.java:1651)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcResponse.<init>(JdbcResponse.java:38)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.createResponse(JdbcSubmit.java:334)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.runQuery(JdbcSubmit.java:199)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.run(JdbcSubmit.java:161)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
So that approach was a bust.
It wasn't a complete failure because I was able to access Cassandra and run queries against it. I used the below code to do that.
import java.sql.DriverManager;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import javax.sql.DataSource;
import org.apache.cassandra.cql.jdbc.*;
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("org.apache.cassandra.cql.jdbc.CassandraDriver");
def con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/soapuikeyspace"); //keyspace has to be in lowercase
def stmt = con.createStatement();
//add data
def qry = "insert into users (user_id, lname, fname) values (1747,'Abhishek','Asthana');"
def rs = stmt.executeUpdate(qry)
The most important thing to remember when using this code is to write the keyspace name in lowercase.
For anyone interested, i wrote a blog about all this.
These days Thrift is dead in terms of a Cassandra interface, and you need to be using the native CQL protocol to be doing anything useful. Fortunately there is a JDBC wrapper available if that's your only integration option, and the native driver's concepts will map a lot better to JDBC than the old Thrift protocol.
JDBC driver class : com.github.adejanovski.cassandra.jdbc.CassandraDriver
JDBC URL : jdbc:cassandra://host1--host2--host3:9042/keyspace
Where 9042 is the default native transport port, configurable via cassandra.yaml.
There does also appear to be an updated version of the Thrift-based JDBC driver for use with Cassandra 3.x, but it is no longer supported by Apache or the Cassandra developers.
As the other answers here have been sharing fixed lists of (sometimes spurious) dependencies I thought I'd better mention proper dependency management, as a lot of things won't work if the different jar versions don't all match up (in particular, 2.x to 3.x is a breaking change for both Cassandra itself and cassandra-driver-core).
The wrapper project mentioned above contains a pom.xml that specifies all the dependencies and is published to Maven Central. You should be able to use any number of dependency-management tools -- including maven, ivy or grape -- to resolve and download all the jars you will need for a particular driver version.
Alternatively, it appears the developer provides a single jar containing all the necessary dependencies, but this will be tied to a specific driver version.
I successfully connected to Cassandra 3.x with a SoapUI version 5.3.0 by cql connection.
Here are my steps:
copy these jars into bin/ext:
dse-java-driver-core-1.4.0
dse-java-driver-mapping-1.4.0
metrics-core-3.0.2
netty-all-4.1.6.Final
update guava jar from lib:
guava-18.0
launch soapui and create groovy script:
import com.datastax.driver.core.*;
Cluster cluster = null;
cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9042).build();
Session session = cluster.connect();
PreparedStatement statement = session.prepare("select * from keyspace.exemple_table");
ResultSet rs = session.execute(statement.bind());
Row row = rs.one();