I developed an email website using javamail and apache-james and it works well mostly. But some user got Open failed Exception and cannot receive new mail.
The code of receive email:
Session mailSession = Session.getInstance(System.getProperties(), null);
mailSession.setDebug(false);
Store store = null;
Folder folder = null; //javax.mail.Folder
try {
store = mailSession.getStore(SParam.PROTOCOL);
store.connect(Property.getPop3(), userName, password);
logger.info("trying to receive emails from james server...");
folder = store.getFolder("INBOX");
try {
if (!folder.isOpen()) {
folder.open(Folder.READ_WRITE); //the point of throwing the exception
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
//receive email from james server.
} catch (Exception e) {
logger.error("Email Receive Error!" + StackTraceStr.st2str(e));
try {
folder.close(true);
} catch (Exception e2) {
}
} finally {
try {
store.close();
} catch (Exception cloex) {
}
}
In most cases, it works just fine. But still got the error occasionally:
javax.mail.MessagingException: Open failed;
nested exception is:
java.io.IOException: STAT command failed: null
at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:228)
at com.csc.mail.jsh.mail.core.ReceiveMail.receive(ReceiveMail.java:82)
at com.csc.mail.jsh.mail.core.ReceiveMail.run(ReceiveMail.java:222)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.IOException: STAT command failed: null
at com.sun.mail.pop3.Protocol.stat(Protocol.java:366)
at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:203)
... 3 more
Waiting your help and thanks a lot!
I debug and debug, finally found the STAT command failed! when STAT command got an error, there's an exception of james, but that makes no sence!
21/11/12 14:39:16 ERROR pop3server: Exception during connection from 127.0.0.1
(127.0.0.1) : An exception occurred getting a database connection.
org.apache.avalon.framework.CascadingRuntimeException: An exception occurred getting a database connection.
at org.apache.james.userrepository.AbstractJdbcUsersRepository.openConnection(AbstractJdbcUsersRepository.java:617)
at org.apache.james.userrepository.AbstractJdbcUsersRepository.getUserByName(AbstractJdbcUsersRepository.java:521)
at org.apache.james.userrepository.AbstractUsersRepository.test(AbstractUsersRepository.java:270)
at org.apache.james.core.LocalUsersRepository.test(LocalUsersRepository.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.avalon.phoenix.components.application.BlockInvocationHandler.invoke(BlockInvocationHandler.java:134)
at $Proxy4.test(Unknown Source)
at org.apache.james.pop3server.POP3Handler.doPASS(POP3Handler.java:537)
at org.apache.james.pop3server.POP3Handler.parseCommand(POP3Handler.java:479)
at org.apache.james.pop3server.POP3Handler.handleConnection(POP3Handler.java:277)
at org.apache.james.util.connection.ServerConnection$ClientConnectionRunner.run(ServerConnection.java:432)
at org.apache.excalibur.thread.impl.ExecutableRunnable.execute(ExecutableRunnable.java:55)
at org.apache.excalibur.thread.impl.WorkerThread.run(WorkerThread.java:116)
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was: 192.168.250.23:1521:csmis
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.apache.james.util.dbcp.JdbcDataSource.getConnection(JdbcDataSource.java:220)
at org.apache.james.userrepository.AbstractJdbcUsersRepository.openConnection(AbstractJdbcUsersRepository.java:614)
... 15 more
All application runs on the same server, and there's only a few users online(when I test it, only me use it). The error just appear occasionally. Why?
It seems to be a mail server issue. STAT command is used to show number of messages. Normally STAT is the first command to run after successfully connected to the mail server.
Try to use mailSession.setDebug(true) to enter debug mode to get more error logs.
I had contact with Apache James and finally found the answer. You can find it at here: STAT command failed occasionally. At the end of the page, the thread had been listed.
Related
I have set of DB connection statements in my java file which takes the driver name, url, username and password from my property file and then try to make a connection. But I am keep getting error exactly in this try block . My code is
try {
Class.forName(properties.getProperty("DB2.database.driver"));
} catch (Exception e) {
System.err.println("Unable to locate database driver:" + e);
return null;
}
The error message is
Unable to locate database `driver:java.lang.ClassNotFoundException:
May i know why it is keep getting this error?
I have JAVA application which work as service on Tomcat server. I need to develope service for receiving mail from GMAIL pop3 server. I use Javamail. I have written usual code, but when I deploy it on server I am getting
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
As for development my Tomcat started on Localhost.
And this problemm looks like concerned with certificate.
My code is
public void downloadMail() {
try {
// connects to the message store and opens the inbox folder
Store store = session.getStore(protocol);
store.connect(username, password);
Folder folderInbox = store.getFolder(inbox);
folderInbox.open(Folder.READ_WRITE);
// fetches new messages from server
Message[] messages = folderInbox.getMessages();
for (int i = 0; i < messages.length; i++) {
Mail mail = extractMail(messages[i]);
messages[i].setFlag(Flags.Flag.DELETED, true);
}
// disconnect
folderInbox.close(false);
store.close();
} catch (NoSuchProviderException ex) {
System.out.println( "No provider for pop3.");
ex.printStackTrace();
} catch (MessagingException ex) {
System.out.println( "Could not connect to the message store");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println( "Can not save file or open directory");
ex.printStackTrace();
}
}
I am getting exception on line store.connect(username, password);
I use properties:
mail.pop3.host=pop.gmail.com
mail.pop3.port=995
mail.pop3.ssl.enable=true
mail.pop3.protocol=pop3
mail.pop3.inbox=INBOX
Please help me to solve this problem. I never worked with Tomcat and certificates before!
I have the same code written in Java and in Android to connect to a mysql-server.
The same code in Java works, but in android it doesn't.
My Code:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
String url1 = "jdbc:mysql://192.168.178.91:3306/db_meinungskanal?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
String user = "user1";
String password = "root";
connection = DriverManager.getConnection(url1, user, password);
if (connection != null) {
System.out.println("Connected to the database");
}
} catch (SQLException ex) {
System.out.println("An error occurred. Maybe user/password is invalid");
ex.printStackTrace();
}
In my android app I have granted acces to the internet with permissions, so I'm able to connect to internet.
If I run the code in android it doesn't work and I get the following:
System.out: An error occurred. Maybe user/password is invalid 02-11
20:29:13.261 17036-17036/camelgmbh.com.meinungskanal W/System.err:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure 02-11 20:29:13.261
17036-17036/camelgmbh.com.meinungskanal W/System.err: The last packet
sent successfully to the server was 0 milliseconds ago. The driver has
not received any packets from the server.
Need help ;D
Android is not supporting MYSQL.You can utilize SQLite or Create web services to access MySQL data from the app.
I have deployed a secure ejb on machine1, when I run the client code on the same machine, it works fine. But when I run the client code on any other machine it throws an error. which is pasted below.
In the error it can be seen that its not taking the ip: that is provided but instead it looks in the client machine itself. Where is the problem is it in the client code or am I missing some settings in WebSphere.
package org.was.tutorial.security.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.was.tutorial.security.bean.Calculator;
public class Client
{
public static void main(String[] args) throws Exception
{
//Establish the proxy with an incorrect security identity
Properties env = new Properties();
//username and password
//String username="teacher1";
//String password="teacher";
String username="student1";
String password="student";
//setting up environment properties..
env.setProperty(Context.SECURITY_PRINCIPAL, username);
env.setProperty(Context.SECURITY_CREDENTIALS, password);
env.setProperty(javax.naming.Context.PROVIDER_URL, "iiop://10.94.13.18:2809");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
//javax.rmi.PortableRemoteObject.narrow(ctx.lookup("CalculatorBean/remote"), Calculator.class);
Calculator calculator =null;
try{
calculator = (Calculator)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("CalculatorBean/remote"), Calculator.class);
if(calculator==null){
System.out.println("This is not going anywhere");
}else
System.out.println("Good. we made a progress.");
}catch (Exception e) {
e.printStackTrace();
}
System.out.println("User "+username);
System.out.println("Addition can be performed by all");
try
{
System.out.println("1 + 1 = " + calculator.add(1, 1));
}
catch (Exception ex)
{
System.out.println("Saw expected SecurityException: " + ex.getMessage());
}
System.out.println("Subtraction- can be performed by students only.");
try
{
System.out.println("16- 4 ="+calculator.subtract(16, 4));
}catch (Exception ex)
{
System.out.println(ex.getMessage());
}
System.out.println("Division- can be performed by teachers only.");
try
{
System.out.println("16/4 ="+calculator.divide(16, 4));
}catch (Exception ex)
{
System.out.println(ex.getMessage());
}
///cool
}
}
Error:
Exception in thread "P=13152:O=0:CT" javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1552)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:1042)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:962)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:614)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:128)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:765)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:164)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:423)
at com.temenos.services.ofsconnector.ejb.IntegrationFrameworkServiceClient.main(IntegrationFrameworkServiceClient.java:50)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1109)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1463)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1001)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1429)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1618)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1385)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:458)
at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1549)
... 9 more
Caused by: org.omg.CORBA.COMM_FAILURE: CONNECT_FAILURE_ON_SSL_CLIENT_SOCKET - JSSL0130E: java.io.IOException: Signals that an I/O exception of some sort has occurred. Reason: Connection refused: connect Remote Host: 127.0.0.1 Remote Port: 9403 vmcid: 0x49421000 minor code: 80 completed: No
at com.ibm.ws.security.orbssl.WSSSLClientSocketFactoryImpl.tryToCreateConnectedSSLSocket(WSSSLClientSocketFactoryImpl.java:357)
at com.ibm.ws.security.orbssl.WSSSLClientSocketFactoryImpl.createSSLSocket(WSSSLClientSocketFactoryImpl.java:219)
at com.ibm.ws.orbimpl.transport.WSSSLTransportConnection.createSocket(WSSSLTransportConnection.java:236)
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:348)
at com.ibm.ws.orbimpl.transport.WSTransport$1.run(WSTransport.java:503)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.orbimpl.transport.WSTransport.getConnection(WSTransport.java:500)
at com.ibm.CORBA.transport.TransportBase.getConnection(TransportBase.java:181)
at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:97)
at com.ibm.rmi.iiop.GIOPImpl.getConnection(GIOPImpl.java:134)
at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:230)
at com.ibm.rmi.corba.ClientDelegate.locate(ClientDelegate.java:1696)
at com.ibm.rmi.corba.ClientDelegate._createRequest(ClientDelegate.java:1721)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1023)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1105)
... 17 more
Update
I have created the node and profile using the following script:
File1:setUpEnv.bat
set WAS_HOME=C:\IBM\WebSphere\AppServer
set HOST_NAME=localhost
set PROFILE_NAME=AppSrv01
set NODE_NAME=%PROFILE_NAME%Node01
set CELL_NAME=%NODE_NAME%Cell
set SERVER_NAME=server1
set DMGR_USER=user1
set DMGR_PASSWORD=123456
set DMGR_HOST=localhost
set DMGR_PORT=8879
File2:
CALL ./setUpEnv.bat
set WAS_HOME=C:\IBM\WebSphere\AppServer
CALL %WAS_HOME%\bin\manageprofiles.bat -create -profileName %PROFILE_NAME% - profilePath %WAS_HOME%\profiles\%PROFILE_NAME% -templatePath %WAS_HOME%\profileTemplates\default -serverName %SERVER_NAME% -cellName %CELL_NAME% -nodeName %NODE_NAME% -hostName %HOST_NAME% -enableAdminSecurity true -adminUserName %DMGR_USER% -adminPassword %DMGR_PASSWORD%
The 9403 is correct port for RMI/IIOP SSL communication (CSIV2_ SSL_ SERVERAUTH_ LISTENER_ ADDRESS). It might happen that you incorrectly installed WAS using localhost, and it sends to the client redirection for the localhost instead for its host name.
Double check WAS configuration for example via web console, in the Server -> Administration -> ports section.
If you installed WAS using localhost, you will either have to change host, or recreate provile (the second might be easier if you are a new to WAS).
I am trying to connect to my company IMAP server using following program but I am getting SSLException.
import javax.mail.*;
import java.util.Properties;
/**
* Created by SDuraisamy on 6/18/2014.
*/
public class Test {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getInstance(props, null);
Store store = null;
try {
store = session.getStore();
// store.connect("imap.gmail.com","mygmailaccount#gmail.com","password");
store.connect("exchange_server", "account2", "password");
Folder inbox = store.getFolder("INBOX");
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
I am getting following Exception
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at Test.main(Test.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
How can I resolve this error?
The same code works when I connect to my gmail account(source commented above), I am able to connect and read messages through my program.
Any setting required at exchange server end to download messages through IMAP? I already have IMAP enabled on my exchange server.
Changing
props.setProperty("mail.store.protocol", "imaps");
to
props.setProperty("mail.store.protocol", "imap");
resolved the issue