java NCache - GeneralFailureException: No server is available to process the request - java

I use NCache java API for connecting to NCache server but it throws an exception:
com.alachisoft.ncache.runtime.exceptions.GeneralFailureException: No server is available to process the request.
I also tried some suggestion from this site
but cannot solve the problem.
Here are the java codes.
String cacheId = "mycache";
try {
cache = NCache.initializeCache(cacheId);
} catch (Exception ex) {
ex.printStackTrace();
log.log(Level.SEVERE, "NCacheConnection()", ex.getMessage());
}

Related

Unable to connect to Oracle database using the JAR file

I'm using eclipse 2020 edition and I've added all libraries I need to connect to Oracle server like ojdbc7.jar and my code is like this:
public Connection SetDatabaseConnection() {
writeInLog("Connecting to IRB", 0);
if(openConnection()){
try {
productionPool.setDriverType("thin");
productionPool.setUser(username);
productionPool.setPassword(password);
productionPool.setPortNumber(Integer.parseInt(port));
productionPool.setServerName(IP);
productionPool.setServiceName(serviceName);
productionPool.setURL("jdbc:oracle:thin:#"+ _connStr.substring(_connStr.indexOf(":")+1));
productionPooledConnection = productionPool.getPooledConnection();
if (productionPooledConnection != null) {
//return true;
currentConnection = productionPooledConnection.getConnection();
logger.info("Connected to IRB server");
return currentConnection;
}
} catch (SQLException ex) {
logger.info("Unable to connect to IRB server, SQLException: "+ex.getMessage());
System.out.println(" (IRB-Exception) DB Exception: \n"+ ex);
}
}
}
my problem is: i can connect to the server while debugging or running the application in the eclipse but when I exported a JAR file the application stopped in this step.
in addition:
my code to open a connection:
private boolean openConnection(){
try {
productionPool = new OracleConnectionPoolDataSource();
productionPooledConnection = new OraclePooledConnection();
logger.info("openConnection(): Connected to IRB server \n");
return true;
} catch (SQLException e) {
e.printStackTrace();
logger.info("Unable to connect to IRB server , SQLException: "+e.getMessage());
}
logger.info("openConnection(): Unable to connect to IRB server \n");
return false;
}
The application never throws any excption it only write in the log file this statment: writeInLog("Connecting to IRB", 0);
I couldn't find the exact reason why this happened but I removed the JARs that cause the error FAT Jar Export: couldn't find the class-path for ...etc and import them again. It worked successfully.

Adding new user to ejabberd through Smack android api

I have installed ejabberd on my local server. This was then tested in spark for its functionality and it worked fine. Now I want to add a new user through the android app.
I tried adding a new user through spark and it worked fine. The fields I have given are uesrname, password, confirm password, server. But when I tried to do it using the smack api in the android app it gave the following error:
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: forbidden - auth
I was using createAccount(), seen in the code I was using below, to create the new account in smack.
AccountManager accountManager = AccountManager.getInstance(conn1);
try {
accountManager.createAccount("tryuser", "qwerty");
Log.i("log", "created user successfully");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
I have checked if it supports new account creation by supportsAccountCreation() and it returned true.
I have changed my register rule to allow all in ejabberd server. and i don't think it has any problem because i can create account from spark, but getting error in smack.
I have looked into the following SO questions related to this topic but no luck.
Ejabberd can't register new user
How to register a new user on XMPP using (a)Smack library
Does anyone have any suggestions on how to solve this?
Please give a try with below -
AccountManager accountManager = AccountManager.getInstance(connection);
try {
if (accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount("userName", "password");
}
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
And you also need to set below in ejabberd.cfg (config file)
{access, register, [{allow, all}]}.
which means - In-band registration allows registration of any possible username. To disable in-band registration, replace 'allow' with 'deny'.
And in mod_register (module in same config file) please set below -
{access_from, register}
& before that please check you are connected to XMPP server.
Probably this will resolve your issue.

pass Ctrl+] over socket connection using java

I have connected telnet server using socket, I am passing various command using this connection, now as per my requirement after getting output I have to pass command like "Ctrl+]" over socket using java.
can you anyone explain me how I pass the same command using java.
below are the method for reference:
public void logout(){
System.out.println("TelnetHelper : Inside logout()");
try {
telnetWrapper.send("\u001d");
telnetWrapper.send("quit");
} catch (IOException e) {
System.out.println("logout() : IOExcepton - "+e.getMessage());
} catch (Exception e) {
System.out.println("logout() : General Excepton - "+e.getMessage());
}
System.out.println("TelnetHelper : logout() Finished");
}
But this is not working in my case
Just close the connection, I suppose that would be telnetWrapper.close();
I think you may want to send \u001b ...
http://wiki.bash-hackers.org/scripting/terminalcodes

JavaMail : FolderClosedException coming frequently

I'm using java mail to connect with gmail and I'm keeping one store for the all actions. (Store is set to static.).
And the IMAPFolder instances are attached with imap listeners. So the folders are kept always open. (Folder close is not called any time) But while running after few minutes I'm getting FolderClosedException. After that exception, though the folder can be reopened but the idle() command cannot be issued again, which will result in NullPointerException.
Is there any wrong with keeping folders open always?
Thanks in advance.
===================================================================
[Edit]
Here I'm pasting the actual code i'm doing POC with. The NullPointerException comes when I check .isConnected() after reconnecting the store. Below is the run method of Thread which sends idle() command to the store.
public void run() {
while (true) {
try {
System.out.println("Checking connectivity...");
if (store.isConnected()) {
store.idle();
System.out.println("IDLE send...");
} else {
Thread.sleep(5000);
System.out.println("Tring to connect...");
//Trying to reconnect to the store.
store.connect();
System.out.println("Previous store connected again");
}
} catch (InterruptedException ex) {
System.out.println("InterruptedException...");
} catch (StoreClosedException ex) {
System.out.println("StoreClosedException...");
} catch (MessagingException ex) {
System.out.println("MessagingException...");
}
}
}
Here is the stack trace:
Exception in thread "Thread-1" java.lang.NullPointerException
at com.sun.mail.imap.IMAPStore.waitIfIdle(IMAPStore.java:1881)
at com.sun.mail.imap.IMAPStore.getStoreProtocol(IMAPStore.java:946)
at com.sun.mail.imap.IMAPStore.isConnected(IMAPStore.java:1347)
at pocworks.POCWorks1$IDLEThread.run(POCWorks1.java:125)
Generally, mail servers don't like you to keep connections open when you're not using them. Typical IMAP servers will give you 30 minutes before they time out an unused connection; Gmail may be more aggressive.

Java connection timeout exception (server is in virtual machine)

I'm havin this situation. I have server running in CentOS (CentOS is in my virtual machine VMware). In host (win7) I have java program that needs to make GET method to server on CentOS. I've manage connection between host and virtual machine and thing works from browser and java program in CentOS and from browser in host (win7) but not from java program in host which is what I need.
If I turn off virtual machine I still get timeout exception.
I've turn off firewall on win7 but i can't turn it off in CentOS because I don't have admin permission.
This is my java code for GET method (192.168.11.128 is IP of virtual machine) :
private static void getMethod(){
// Create a method instance.
GetMethod method = new GetMethod("http://192.168.11.128");
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
Thanks for any help!

Categories