I am using DataStax driver for connecting to a Cassandra node. below is the code for the connector.
public void connect(String node, Integer port, String username, String password) throws Exception {
try {
Builder b = Cluster.builder().addContactPoint(node).withCredentials(username.trim(), password.trim());
if (port != null) {
b.withPort(port);
}
cluster = b.build();
session = cluster.connect();
} catch (Exception e) {
throw new Exception("can not connect to the node :"+e.getMessage());
}
}
I have set the authenticator in Cassandra.yaml file
authenticator: PasswordAuthenticator
on calling the connect method the following error is being shown:
Authentication error on host localhost/127.0.0.1:9042: Host localhost/127.0.0.1:9042 requires authentication, but no authenticator found in Cluster configuration
cqlsh shell is able to connect to the node using same configurations for the Cassandra. Can anyone tell what's I am missing here?
Edit : Exception Stack at
com.datastax.driver.core.AuthProvider$1.newAuthenticator(AuthProvider.java:40) at com.datastax.driver.core.Connection$5.apply(Connection.java:259) at com.datastax.driver.core.Connection$5.apply(Connection.java:244) at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:211) at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:200) at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:130) at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902) at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813) at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:655) at com.datastax.driver.core.Connection$Future.onSet(Connection.java:1302) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1083) at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1006) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:141) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:745)