Im working with Java backend using Tomcat and trying to connect to a hosted instance of couchbase. I have setup up the path to my config directory in ../tomcat/Catalina/localhost/context.xml.default
<Parameter name="CONFIG_DIRECTORY" value="/opt/platform/conf" override="false"/>
Also I have set a CLASSPATH param in ../tomcat/bin/setenv.sh
CLASSPATH=/opt/platform/conf/
Below is the snippet of code I am working with :
String initialNodes = RuntimeData.INSTANCE.getConfigurationValue("MYNODES");
String bucketId = RuntimeData.INSTANCE.getConfigurationValue("MYBUCKET");
System.out.println("Creating cluster for " + initialNodes);
try {
System.out.println("HOST INET ADDRESS : " + InetAddress.getByName(initialNodes));
} catch (UnknownHostException e) {
System.out.println("UNKNOWN HOST EXCEPTION : " + initialNodes);
}
cluster = CouchbaseCluster.create(initialNodes.split(","));
System.out.println("Creating bucket for " + bucketId);
bucket = cluster.openBucket(bucketId, 10, TimeUnit.SECONDS);
System.out.println("Creating graph.");
graph = new CBGraph();
In this code I have some debug logging and I can confirm that I do pull the correct values in for the initialNodes and the bucket. My issue currently comes in on the last line when I try to create a new CBGraph().
I get this error:
Caused by: com.couchbase.client.core.config.ConfigurationException: No valid node found to bootstrap from. Please check your network configuration.
My guess is that somehow the properties file that contains all of the connection info for my couchbase server is either not getting loaded into the classpath ... or it is getting loaded later than I need it too.
The only verification I have been able to do that adding the CLASSPATH setting to setenv.sh is that once tomcat is running I do see the path in classpath if I do ps auxw|grep tomcat.
Any help with this issue is welcome. I have looked at some other posts but im not sure exactly the issue im trying to solve here other than the error I get.
ADDITION:
Looking at the INFO logs at runtime I can verify that the dir containing my couchbase .properties file IS in the classpath. BUT ... it looks like couchbase is trying to initialize using default values (copied below)
INFO: Using the following configuration ...
Oct 24, 2016 3:08:09 PM com.couchbase.graph.conn.ConnectionFactory createCon
INFO: hosts = ubuntu-local
The adresses you are specifying might not be valid hostnames (or ip addresses), and you should also see one of these INFO log messages:
https://github.com/couchbase/couchbase-jvm-core/blob/4127377b8bd057ed291176d568a1e868796e4e5a/src/main/java/com/couchbase/client/core/message/cluster/SeedNodesRequest.java#L85-L102
Related
In a java service, I'm trying to upload a file in an azure storage directory; therefore I've written a code like this :
import com.azure.core.util.*;
import com.azure.storage.file.share.*;
import com.azure.storage.file.share.models.*;
//Create connexion string
String connectStr ="DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=" + endpoint;
//ShareDirectoryClient
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(proxyOptions).buildDirectoryClient();
// Create empty file
dirClient.createFile(fileName, body.length());
The HTTPS request must goes through a proxy server, so, I get this error :
"Could not run 'sendFileInDirectoryProxyTest'
reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: "
I can't set/use a global setting.
To set a proxy in the Java code, I've tried several things, like using the Configuration Class :
Configuration configuration = new Configuration();
configuration.put("java.net.useSystemProxies", "true");
configuration.put("https.proxyHost", "xxxxxxxxx");
configuration.put("https.proxyPort", "xxxx");
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(configuration).buildDirectoryClient();
But it did not solve the issue.
I'm sure it is pretty simple, any help would be appreciated.
Thanks. Charles de Saint Andre.
You need to configure ProxyOptions and set them on the httpClientBuilder. All our Storage client builders have a .httpClient() method that accepts a client, and you can build a client with all defaults + the proxy options using a NettyAsyncClientBuilder(), which has a .proxyOptions() method. Please give that a try and let me know if you have any more issues.
Sample : azure-sdk-for-java/sdk/storage/azure-storage-blob at main ยท Azure/azure-sdk-for-java (github.com)
I tried Connecting the AWS Neptune with this Java code and got the error , NoHostAvailable Exception
approach 1:
public static void main(String[] args) throws Exception {
Cluster.Builder builder = Cluster.build();
builder.addContactPoint("endpoint");
builder.port(8182);
builder.enableSsl(true);
builder.keyStore("pem-file");
Cluster cluster = builder.create();
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster));
System.out.println(g.V().limit(10).toList());
cluster.close();
}}
approach 2:
Cluster cluster = Cluster.build("endpoint").
enableSsl(true).keyStore("pem").
handshakeInterceptor( r -> {
NeptuneNettyHttpSigV4Signer sigV4Signer = null;
try {
sigV4Signer = new NeptuneNettyHttpSigV4Signer("us-east-2", new
DefaultAWSCredentialsProviderChain());
} catch (NeptuneSigV4SignerException e) {
e.printStackTrace();
}
try {
sigV4Signer.signRequest(r);
} catch (NeptuneSigV4SignerException e) {
e.printStackTrace();
}
return r;
}).create();
Client client=Cluster.open("src\\conf\\remote-objects.yaml").connect();
client.submit("g.V().limit(10).toList()").all().get();
what ever I do, I am getting this error:
Sep 02, 2021 3:18:34 PM io.netty.channel.ChannelInitializer exceptionCaught
WARNING: Failed to initialize a channel. Closing:
java.lang.RuntimeException: java.lang.NullPointerException
org.apache.tinkerpop.gremlin.driver.Channelizer$AbstractChannelizer.initChannel(Channelizer.java:117)
Caused by: org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException: All hosts
are considered unavailable due to previous exceptions. Check the error log to find the actual
reason.
I need the code or the document to connect my Gremlin code in .java file to AWS neptune. I am struggling and tried various number of ways,
1.created EC2 instance and did installed maven and apache still got error and code is running in Server(EC2), i want code to present in IntelliJ
it would be more helpful, if I get the Exact Code any way. what should be added in remote-objects.yaml.
if we require Pem-file to access Amazon Neptune, please help with the creation of it.
Assuming SSL is enabled but IAM is not, in terms of Java code, this is all you need to create the connection.
Cluster.Builder builder = Cluster.build();
builder.addContactPoint("localhost");
builder.port(8182);
builder.enableSsl(true);
builder.serializer(Serializers.GRAPHBINARY_V1D0);
cluster = builder.create();
drc = DriverRemoteConnection.using(cluster);
g = traversal().withRemote(drc);
You may need to add an entry to your /etc/hosts file to get the SSL certs to resolve correctly such as:
127.0.0.1 localhost my-neptune-cluster.us-east-1.neptune.amazonaws.com
If you find that using localhost with SSL enabled does not work then use the actual Neptune cluster DNS name and make the edit to your /etc/hosts file.
The last thing you will need to do is create access to the Neptune VPC from your local machine. One way is using an SSH tunnel as explained in this post
I am trying to fetch last modified date of a file from FTP environment.The result is not as expected.
By using ftpClient.getModificationTime("File path") I am getting null.
By using FTPFile.getTimestamp().getTime() I am getting wrong last modified (i.e. real last modified is of today and I am getting Wed Feb 18 02:55:22 EST 2004).
How to get correct last modified?File at FTP
Thanks in advance.
FTPClient.getModificationTime returns null when the server returns an error response to MDTM command. Typically that would mean either that:
"File path" does not exists; or
the FTP server does not support MDTM command.
Check FTPClient.getReplyString().
If it turns out that the FTP server does not support MDTM command, you will have to use another method to retrieve the timestamps. If MDTM is not supported, MLSD won't be either.
In that case the only other way is using LIST command to retrieve listing of all files and lookup the file you need - Use FTPClient.listFiles().
FTPFile[] remoteFiles = ftpClient.listFiles(remotePath);
Arrays.sort(remoteFiles,
Comparator.comparing((FTPFile remoteFile) -> remoteFile.getTimestamp()).reversed());
FTPFile latestFile = remoteFiles[0];
System.out.println(
"Latest file is " + latestFile.getName() +
" with timestamp " + latestFile.getTimestamp().getTime().toString());
See also Make FTP server return files listed by timestamp with Apache FTPClient.
I found the mistake I was doing.
I was working on a SFTP Environment instead of FTP Environment. I had to use jar files and other functions of SFTP not of FTP.
Thanks.
I'm trying to get all the database on my server. But specifying my server name in getDbDirectory() parameter as NALLN304/40/LLN/IBM gives me a error.
Directory NALLN304/40/LLN/IBM!! does not exist
it always add two exclamation mark at the end. I tried also as server name and mail file adding .nsf format at the end of mail file. NALLN304/40/LLN/IBM!!data0\126\1000031540.nsf also gives me the same error.
Snipper code below:
Session session = null;
Database db = null;
DbDirectory dir = null;
try
{
NotesThread.sinitThread();
session = NotesFactory.createSession();
System.out.println("User = " + session.getUserName());
dir = session.getDbDirectory("NALLN304/40/LLN/IBM");
System.out.println(dir.getName());
db = dir.getFirstDatabase(DbDirectory.DATABASE);
do
{
System.out.println("Title: " +db.getTitle());
}
while(dir.getNextDatabase() != null);
}
catch(NotesException ex)
{
ex.printStackTrace();
}
The error always points out to the db = dir.getFirstDatabase(DbDirectory.DATABASE); because dir.getFirstDatabase(DbDirectory.DATABASE) expects .nsf file even I specify the file format. Any reasons why I got this error?
Your problem is that your ID is not authenticating with the server. You need to take the output from this line:
System.out.println("User = " + session.getUserName());
And take it to your server administrators, ask why it is not being allowed to access the server, and ask them to assist you either by granting the necessary permissions or by giving you another ID that you can use.
Check the logs for server connection errors. Even if the server has to connect to itself. Faced the same problem. The server gave an error because it did not find a route for the connection. Added a new connection for the server to itself and everything was fixed
I have created a java application in netbeans, and I intend to create an installer for the project.
For this I have created a jar file of the application, but I'm using the mysql database localhost.
How can I generate Jar File with Mysql localhost .
Can anyone help me please?
Thanks and regards
-----------------------------Edit---------------------------------------
Maybe not the best way to express myself, what I mean is that the database is created locally (localhost).
The connection of the application with the database is done this way:
Class.forName("com.mysql.jdbc.Driver");
return driverManager.getConnection("jdbc:mysql://localhost/database","root", "root");
I want to create a jar file of my application that has a database created locally.
I am going to explain a few things:
You do not need to hard - code the Connect URL into your code. This is why you are asking for ways of creating the database as localhost. I suggest you do not hard code the Connect URL in the code. Instead write it in an editable File either a Properties file or even a text file. Let the Application read the Editable file and pass the Parameters to the Code.
An Application running in your Local Machine where the database is will connect using Localhost. But a the same Application running remotely from another Machine whether in the Internet or Local access network will not Connect this way.That is why I am insisting on NOT Hard-Coding the Connect String.
The database Name, user, and Password Including the Host will change from time to Time depending on which environment the Application is running in. So again if the environment changes and the variables are not the same the Application will Not Connect to the database.
Suggestion:
User a Properties file:
db.host=192.168.1.23
db.user=root
db.password=root
db.dbname=database
Load the file as a Properties file:
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("db.host"));
System.out.println(prop.getProperty("db.user"));
System.out.println(prop.getProperty("db.password"));
System.out.println(prop.getProperty("db.dbname"));
//PASS YOUR CONNECT STRING
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://" + prop.getProperty("db.host") + "/" + prop.getProperty("db.dbname"), prop.getProperty("db.user"), prop.getProperty("db.password"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This way you will never have to worry about what database the application is running on as you will just have to edit the config.properties and the Application will do the rest.
I hope I gave you an answer or better still other ideas on how to handle your situation.