dcsimg
a bug using ssl?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Naor_Y
Posted On:   Tuesday, October 25, 2005 01:55 PM

Hi, I'm calling doAction() one my one (in the same execution): public void doAction() { boolean success=false; Session session=Session.getDefaultInstance(getProperaties(),getAuthenticator()); Store store=null; Folder folder=null; Message[] msgs=null; int endMessageNumber=1; int startMessageNumber=1; String position=null; try { store=session.getStore(); store.connect(); //Open the Folder for read only folder=store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); int messageCount=folder.getMessageCount();    More>>

Hi,
I'm calling doAction() one my one (in the same execution):


public void doAction() {

boolean success=false;

Session session=Session.getDefaultInstance(getProperaties(),getAuthenticator());

Store store=null;

Folder folder=null;

Message[] msgs=null;

int endMessageNumber=1;

int startMessageNumber=1;


String position=null;


try {

store=session.getStore();

store.connect();

//Open the Folder for read only

folder=store.getFolder("INBOX");

folder.open(Folder.READ_ONLY);



int messageCount=folder.getMessageCount();



boolean isUID=(getMailId()==null) ? false:true;

if (isUID) {

endMessageNumber=getMessageIdByUID
(folder,getMailId());
if (endMessageNumber==-1)

throw new InvalidParameterException();

} else

endMessageNumber=messageCount;



if (endMessageNumber-getQuantity() <0) {

setQuantity(endMessageNumber);

startMessageNumber=1;

} else

startMessageNumber=endMessageNumber-
getQuantity()+1;


if (endMessageNumber!=0) {

msgs=folder.getMessages(startMessageNumber,
endMessageNumber);
if (endMessageNumber==messageCount &&
startMessageNumber==1)

position=Constants.MAILS_LIST_POSITION_NONE;
else if (startMessageNumber==1)


position=Constants.MAILS_LIST_POSITION_LAST;
else if (endMessageNumber==messageCount)


position=Constants.MAILS_LIST_POSITION_FIRST;
else
position=Constants.MAILS_LIST_POSITION_NONE;
}

else {

msgs=new Message[0];

position=Constants.MAILS_LIST_POSITION_NONE;

}



Vector mails=new Vector();

mails.add(position); //The first element is the
position of the list.
//for (int i=0;i

for (int i=msgs.length-1;i>=0;i--) {

String uid=((POP3Folder)folder).getUID(msgs
[i]);
String header=((InternetAddress)msgs
[i].getFrom()[0]).getAddress();
Mail mail=new Mail(uid,header);

mails.add(mail);

}



getResult().put
(Constants.MAILS_LIST_ELEMENT,mails);


success=true;

} catch (NoSuchProviderException e) {

e.printStackTrace();

getResult().put
(Constants.STATUS,Constants.STAT_FAIL);
getResult().put
(Constants.ERROR_ELEMENT,Constants.INTERNAL_ERROR);
success=false;

} catch(MessagingException e) {

e.printStackTrace();

getResult().put
(Constants.STATUS,Constants.STAT_FAIL);
getResult().put
(Constants.ERROR_ELEMENT,Constants.MESSAGING_EXCEPTION);
success=false;

} catch(InvalidParameterException e) {

e.printStackTrace();

getResult().put
(Constants.STATUS,Constants.STAT_FAIL);
getResult().put
(Constants.ERROR_ELEMENT,Constants.INVALID_UID);
success=false;

} finally {

getResult().put
(Constants.ACTION_ID_ELEMENT,getActionId());
if (success)

getResult().put
(Constants.STATUS,Constants.STAT_SUCCESS);
try {

if (folder!=null)

folder.close(false);

if (store!=null)

store.close();

} catch(MessagingException e) {

e.printStackTrace();

}

}

}

protected Properties getProperaties() {

//Properties props = System.getProperties();

Properties props = new Properties();

props.setProperty("mail.store.protocol", "pop3");

props.setProperty("mail.pop3.host", getPop3());

//props.put("mail.pop3.auth", "true");



if (isSecure()) {

Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
props.setProperty
("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

props.setProperty
( "mail.pop3.socketFactory.fallback", "false");
} else {

Security.removeProvider(new
com.sun.net.ssl.internal.ssl.Provider().getName());
}



return props;

}



protected Authenticator getAuthenticator() {

Authenticator pa = new Authenticator(){

public PasswordAuthentication
getPasswordAuthentication() {
return new PasswordAuthentication
(getUserName(),getPassword());
}

};

return pa;

}







In the first run of doAction(), isSecure() is true, and in
the second run, isSecure() is false.


I'm tryng to connect to mail server that don't use ssl. So
the first run throws an exception as expected, but the second run throws an exception too.. it shouldn't happen
because int the second run isSecure()=false.


The exception is (this exception was given in both of the
runs):



DEBUG: getProvider() returning javax.mail.Provider
[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG: setDebug: JavaMail version 1.3.2

DEBUG POP3: connecting to host "pop.012.net.il", port 110,
isSSL false
javax.mail.MessagingException: Connect failed;

nested exception is:

javax.net.ssl.SSLException: Unrecognized SSL message,
plaintext connection?
at com.sun.mail.pop3.POP3Store.protocolConnect
(POP3Store.java:120)
at javax.mail.Service.connect(Service.java:255)

at javax.mail.Service.connect(Service.java:134)

at javax.mail.Service.connect(Service.java:86)

at BusinessLogic.Requests.ShowMailsListRequest.doAction
(ShowMailsListRequest.java:41)
at BusinessLogic.Requests.RequestDirector.executeRequests
(RequestDirector.java:92)
at BusinessLogic.Requests.RequestDirector.runProccesses
(RequestDirector.java:16)
at BusinessLogic.BusinessLogicRunner.run
(BusinessLogicRunner.java:22)
at ServerRunner.run(ServerRunner.java:37)

at Main.main(Main.java:22)



what is the problem?

is it a bug?



Naor

   <<Less
About | Sitemap | Contact