You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by James Eliyezar <ja...@mcruncher.com> on 2012/08/14 04:34:06 UTC

Problem sending email using SSL after upgrading to Wicket 1.5

Greetings to all of you.

We recently upgraded our application to Wicket 1.5.
However, after upgrading we had problems sending email using SSL from our
application.
This may not be related to wicket at all but I promise we didn't change any
dependencies other than wicket's.
What amuses me is that it works as expected in our older versions which
still use Wicket 1.4.x.
Both the older version and the current version were run using the same JRE.

Here's the code that sends email:

<pre>
public class MailSenderTask implements Runnable
{
    private Properties smtpProperties;
    private EmailMessage message;
    private static final Logger logger =
LoggerFactory.getLogger(MailSenderTask.class);

    public MailSenderTask(Properties smtpProperties, EmailMessage message)
    {
        this.smtpProperties = smtpProperties;
        this.message = message;
    }

    public synchronized void sendMail() throws Exception
    {
        try {
            if (addSSlProvider()) {
                logger.info("Adding ssl provider");
                Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
            } else {
                logger.info("Using plain text connection as ssl/tls is not
enabled");
            }
            Session session = createSession();
            MimeMessage mimeMessage = new MimeMessage(session);
            mimeMessage.setSender(new InternetAddress(message.getSender()));
            mimeMessage.setSubject(message.getSubject());

            if (message.getRecipients().indexOf(',') > 0) {
                mimeMessage.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(message.getRecipients()));
            } else {
                mimeMessage.setRecipient(Message.RecipientType.TO, new
InternetAddress(message.getRecipients()));
            }

            MimeBodyPart bodyPart = new MimeBodyPart();
            bodyPart.setContent(message.getBody(), "text/html");

            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(bodyPart);

            if (message.getAttachments() != null &&
message.getAttachments().length > 0) {
                for (File file : message.getAttachments()) {
                    logger.debug("Adding {} as an attachment", file);
                    MimeBodyPart attachmentPart = new MimeBodyPart();
                    attachmentPart.attachFile(file);
                    multipart.addBodyPart(attachmentPart);
                }
            }

            mimeMessage.setContent(multipart);

            logger.info("Sending mail...");
            Transport.send(mimeMessage);
            logger.info("Mail sent to {}", message.getRecipients());
        } catch (Exception ex) {
            throw new EmailException("Error occurred while sending mail",
ex);
        }
    }

    private boolean addSSlProvider()
    {
        String sslEnabledProperty =
smtpProperties.getProperty("mail.smtp.starttls.enable");
        if (StringUtils.isNotEmpty(sslEnabledProperty)) {
            return Boolean.parseBoolean(sslEnabledProperty);
        }
        return false;
    }

    private Session createSession()
    {
        Session session = null;
        if
(Boolean.parseBoolean(smtpProperties.getProperty("mail.smtp.auth"))) {
            logger.info("Creating session with authentication");
            session = createSessionWithAuthentication(smtpProperties);
        } else {
            logger.info("Creating default session");
            session = createDefaultSession(smtpProperties);
        }
        return session;
    }

    private Session createDefaultSession(final Properties smtpProperties)
    {
        return Session.getInstance(smtpProperties);
    }

    private Session createSessionWithAuthentication(final Properties
smtpProperties)
    {
        return Session.getInstance(smtpProperties,
                new Authenticator()
                {
                    @Override
                    protected PasswordAuthentication
getPasswordAuthentication()
                    {
                        return new
PasswordAuthentication(smtpProperties.getProperty("smtp.username"),

smtpProperties.getProperty("smtp.password"));
                    }
                });
    }

    public void run()
    {
        if (smtpProperties != null && message != null) {
            try {
                sendMail();
            } catch (Exception ex) {
                throw new EmailException("Error", ex);
            }
        }
    }
}
</pre>

These are the SMTP properties that were set:

<pre>
mail.smtp.socketFactory.fallback:false
mail.smtp.socketFactory.class:javax.net.ssl.SSLSocketFactory
mail.transport.protocol:smtp
mail.smtp.connectiontimeout:10000
mail.smtp.host:smtp.gmail.com
mail.smtp.timeout:10000
mail.smtp.starttls.enable:true
mail.smtp.port:465
mail.smtp.auth:true
mail.smtp.socketFactory.port:465
mail.smtp.quitwait:false
smtp.username:foo@gmail.com
smtp.password: bar
</pre>

This is the exception thrown:

<pre>
Caused by: javax.mail.MessagingException: Could not connect to SMTP host:
smtp.gmail.com, port: 465
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
~[mail-1.4.4.jar:1.4.4]
    at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
~[mail-1.4.4.jar:1.4.4]
    at javax.mail.Service.connect(Service.java:297) ~[mail-1.4.jar:1.4]
    at javax.mail.Service.connect(Service.java:156) ~[mail-1.4.jar:1.4]
    at javax.mail.Service.connect(Service.java:105) ~[mail-1.4.jar:1.4]
    at javax.mail.Transport.send0(Transport.java:168) ~[mail-1.4.jar:1.4]
    at javax.mail.Transport.send(Transport.java:98) ~[mail-1.4.jar:1.4]
    at
com.mcruncher.core.module.email.util.MailSenderTask.sendMail(MailSenderTask.java:75)
~[MailSenderTask.class:2.7.0-SNAPSHOT]
    ... 56 common frames omitted
Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException:
Unexpected error: java.security.InvalidAlgorithmParameterException: the
trustAnchors parameter must be non-empty
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1692)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1675)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1204)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1181)
~[na:1.6]
    at
com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
~[mail-1.4.4.jar:1.4]
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
~[mail-1.4.4.jar:1.4]
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
~[mail-1.4.4.jar:1.4.4]
    ... 63 common frames omitted
Caused by: java.lang.RuntimeException: Unexpected error:
java.security.InvalidAlgorithmParameterException: the trustAnchors
parameter must be non-empty
    at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:57)
~[na:1.6.0_33]
    at sun.security.validator.Validator.getInstance(Validator.java:161)
~[na:1.6.0_33]
    at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:108)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:204)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
~[na:1.6]
    at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1197)
~[na:1.6]
    ... 67 common frames omitted
Caused by: java.security.InvalidAlgorithmParameterException: the
trustAnchors parameter must be non-empty
    at
java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
~[na:1.6.0_33]
    at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
~[na:1.6.0_33]
    at
java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
~[na:1.6.0_33]
    at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:55)
~[na:1.6.0_33]
    ... 78 common frames omitted
</pre>

Eagerly awaiting fellow wicket users' help....

-- 
Thanks & regards
James Selvakumar
mcruncher.com

Re: Problem sending email using SSL after upgrading to Wicket 1.5

Posted by James Eliyezar <ja...@mcruncher.com>.
It turns out that the problem was because of the custom trust store we were
using in our application.
It has nothing to do with wicket.
Sorry for bothering you all.

On Tue, Aug 14, 2012 at 3:55 PM, James Eliyezar <ja...@mcruncher.com> wrote:

> Martin,
>
> Yes I use smtp props that are similar to what you have shared. Kindly see
> my initial post for the smtp properties used by me.
> I may sound stupid but the same piece of code runs fine when using
> wicket-1.4.x.
> And I use the following wicket related dependencies:
>
>    - wicket
>    - wicket-extensions
>    - wicket-ioc
>    - wicket-spring
>    - wicket-datetime
>    - wicketstuff-annotation
>    - wicketstuff-objectautocomplete
>    - wiquery-jquery-ui
>
> All of them use the version 1.5.7. (Yes some of them don't belong to the
> wicket project at all but they depend on wicket-1.5.x)
>
> Is there a possibility of a dependency conflict?
>
> NOTE: I found that wicket-ioc depends on "cglib". But even when I excluded
> it the problem persists.
> On Tue, Aug 14, 2012 at 2:27 PM, Martin Grigorov <mg...@apache.org>wrote:
>
>> Hi,
>>
>> I don't think this is anyhow related to Wicket.
>> Here are the GMail SMTP related props I use successfully:
>>
>> mail.server.host=smtp.gmail.com
>> mail.server.port=587
>> mail.server.username=my.email@gmail.com
>> mail.server.password=my-passwd
>> mail.server.starttls.enable=true
>>
>> You may also check the docs of SMTPAppender in Logback. There are
>> examples for configuring it with GMail. I believe the problem is in
>> these settings.
>>
>> On Tue, Aug 14, 2012 at 5:34 AM, James Eliyezar <ja...@mcruncher.com>
>> wrote:
>> > Greetings to all of you.
>> >
>> > We recently upgraded our application to Wicket 1.5.
>> > However, after upgrading we had problems sending email using SSL from
>> our
>> > application.
>> > This may not be related to wicket at all but I promise we didn't change
>> any
>> > dependencies other than wicket's.
>> > What amuses me is that it works as expected in our older versions which
>> > still use Wicket 1.4.x.
>> > Both the older version and the current version were run using the same
>> JRE.
>> >
>> > Here's the code that sends email:
>> >
>> > <pre>
>> > public class MailSenderTask implements Runnable
>> > {
>> >     private Properties smtpProperties;
>> >     private EmailMessage message;
>> >     private static final Logger logger =
>> > LoggerFactory.getLogger(MailSenderTask.class);
>> >
>> >     public MailSenderTask(Properties smtpProperties, EmailMessage
>> message)
>> >     {
>> >         this.smtpProperties = smtpProperties;
>> >         this.message = message;
>> >     }
>> >
>> >     public synchronized void sendMail() throws Exception
>> >     {
>> >         try {
>> >             if (addSSlProvider()) {
>> >                 logger.info("Adding ssl provider");
>> >                 Security.addProvider(new
>> > com.sun.net.ssl.internal.ssl.Provider());
>> >             } else {
>> >                 logger.info("Using plain text connection as ssl/tls is
>> not
>> > enabled");
>> >             }
>> >             Session session = createSession();
>> >             MimeMessage mimeMessage = new MimeMessage(session);
>> >             mimeMessage.setSender(new
>> InternetAddress(message.getSender()));
>> >             mimeMessage.setSubject(message.getSubject());
>> >
>> >             if (message.getRecipients().indexOf(',') > 0) {
>> >                 mimeMessage.setRecipients(Message.RecipientType.TO,
>> > InternetAddress.parse(message.getRecipients()));
>> >             } else {
>> >                 mimeMessage.setRecipient(Message.RecipientType.TO, new
>> > InternetAddress(message.getRecipients()));
>> >             }
>> >
>> >             MimeBodyPart bodyPart = new MimeBodyPart();
>> >             bodyPart.setContent(message.getBody(), "text/html");
>> >
>> >             Multipart multipart = new MimeMultipart();
>> >             multipart.addBodyPart(bodyPart);
>> >
>> >             if (message.getAttachments() != null &&
>> > message.getAttachments().length > 0) {
>> >                 for (File file : message.getAttachments()) {
>> >                     logger.debug("Adding {} as an attachment", file);
>> >                     MimeBodyPart attachmentPart = new MimeBodyPart();
>> >                     attachmentPart.attachFile(file);
>> >                     multipart.addBodyPart(attachmentPart);
>> >                 }
>> >             }
>> >
>> >             mimeMessage.setContent(multipart);
>> >
>> >             logger.info("Sending mail...");
>> >             Transport.send(mimeMessage);
>> >             logger.info("Mail sent to {}", message.getRecipients());
>> >         } catch (Exception ex) {
>> >             throw new EmailException("Error occurred while sending
>> mail",
>> > ex);
>> >         }
>> >     }
>> >
>> >     private boolean addSSlProvider()
>> >     {
>> >         String sslEnabledProperty =
>> > smtpProperties.getProperty("mail.smtp.starttls.enable");
>> >         if (StringUtils.isNotEmpty(sslEnabledProperty)) {
>> >             return Boolean.parseBoolean(sslEnabledProperty);
>> >         }
>> >         return false;
>> >     }
>> >
>> >     private Session createSession()
>> >     {
>> >         Session session = null;
>> >         if
>> > (Boolean.parseBoolean(smtpProperties.getProperty("mail.smtp.auth"))) {
>> >             logger.info("Creating session with authentication");
>> >             session = createSessionWithAuthentication(smtpProperties);
>> >         } else {
>> >             logger.info("Creating default session");
>> >             session = createDefaultSession(smtpProperties);
>> >         }
>> >         return session;
>> >     }
>> >
>> >     private Session createDefaultSession(final Properties
>> smtpProperties)
>> >     {
>> >         return Session.getInstance(smtpProperties);
>> >     }
>> >
>> >     private Session createSessionWithAuthentication(final Properties
>> > smtpProperties)
>> >     {
>> >         return Session.getInstance(smtpProperties,
>> >                 new Authenticator()
>> >                 {
>> >                     @Override
>> >                     protected PasswordAuthentication
>> > getPasswordAuthentication()
>> >                     {
>> >                         return new
>> > PasswordAuthentication(smtpProperties.getProperty("smtp.username"),
>> >
>> > smtpProperties.getProperty("smtp.password"));
>> >                     }
>> >                 });
>> >     }
>> >
>> >     public void run()
>> >     {
>> >         if (smtpProperties != null && message != null) {
>> >             try {
>> >                 sendMail();
>> >             } catch (Exception ex) {
>> >                 throw new EmailException("Error", ex);
>> >             }
>> >         }
>> >     }
>> > }
>> > </pre>
>> >
>> > These are the SMTP properties that were set:
>> >
>> > <pre>
>> > mail.smtp.socketFactory.fallback:false
>> > mail.smtp.socketFactory.class:javax.net.ssl.SSLSocketFactory
>> > mail.transport.protocol:smtp
>> > mail.smtp.connectiontimeout:10000
>> > mail.smtp.host:smtp.gmail.com
>> > mail.smtp.timeout:10000
>> > mail.smtp.starttls.enable:true
>> > mail.smtp.port:465
>> > mail.smtp.auth:true
>> > mail.smtp.socketFactory.port:465
>> > mail.smtp.quitwait:false
>> > smtp.username:foo@gmail.com
>> > smtp.password: bar
>> > </pre>
>> >
>> > This is the exception thrown:
>> >
>> > <pre>
>> > Caused by: javax.mail.MessagingException: Could not connect to SMTP
>> host:
>> > smtp.gmail.com, port: 465
>> >     at
>> com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
>> > ~[mail-1.4.4.jar:1.4.4]
>> >     at
>> > com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
>> > ~[mail-1.4.4.jar:1.4.4]
>> >     at javax.mail.Service.connect(Service.java:297) ~[mail-1.4.jar:1.4]
>> >     at javax.mail.Service.connect(Service.java:156) ~[mail-1.4.jar:1.4]
>> >     at javax.mail.Service.connect(Service.java:105) ~[mail-1.4.jar:1.4]
>> >     at javax.mail.Transport.send0(Transport.java:168)
>> ~[mail-1.4.jar:1.4]
>> >     at javax.mail.Transport.send(Transport.java:98) ~[mail-1.4.jar:1.4]
>> >     at
>> >
>> com.mcruncher.core.module.email.util.MailSenderTask.sendMail(MailSenderTask.java:75)
>> > ~[MailSenderTask.class:2.7.0-SNAPSHOT]
>> >     ... 56 common frames omitted
>> > Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException:
>> > Unexpected error: java.security.InvalidAlgorithmParameterException: the
>> > trustAnchors parameter must be non-empty
>> >     at
>> com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1692)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1675)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1204)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1181)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
>> > ~[mail-1.4.4.jar:1.4]
>> >     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
>> > ~[mail-1.4.4.jar:1.4]
>> >     at
>> com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
>> > ~[mail-1.4.4.jar:1.4.4]
>> >     ... 63 common frames omitted
>> > Caused by: java.lang.RuntimeException: Unexpected error:
>> > java.security.InvalidAlgorithmParameterException: the trustAnchors
>> > parameter must be non-empty
>> >     at
>> sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:57)
>> > ~[na:1.6.0_33]
>> >     at sun.security.validator.Validator.getInstance(Validator.java:161)
>> > ~[na:1.6.0_33]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:108)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:204)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
>> > ~[na:1.6]
>> >     at
>> > com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
>> > ~[na:1.6]
>> >     at
>> >
>> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1197)
>> > ~[na:1.6]
>> >     ... 67 common frames omitted
>> > Caused by: java.security.InvalidAlgorithmParameterException: the
>> > trustAnchors parameter must be non-empty
>> >     at
>> >
>> java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
>> > ~[na:1.6.0_33]
>> >     at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
>> > ~[na:1.6.0_33]
>> >     at
>> >
>> java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
>> > ~[na:1.6.0_33]
>> >     at
>> sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:55)
>> > ~[na:1.6.0_33]
>> >     ... 78 common frames omitted
>> > </pre>
>> >
>> > Eagerly awaiting fellow wicket users' help....
>> >
>> > --
>> > Thanks & regards
>> > James Selvakumar
>> > mcruncher.com
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> Thanks & regards
> James Selvakumar
> mcruncher.com
>
>


-- 
Thanks & regards
James Selvakumar
mcruncher.com

Re: Problem sending email using SSL after upgrading to Wicket 1.5

Posted by James Eliyezar <ja...@mcruncher.com>.
Martin,

Yes I use smtp props that are similar to what you have shared. Kindly see
my initial post for the smtp properties used by me.
I may sound stupid but the same piece of code runs fine when using
wicket-1.4.x.
And I use the following wicket related dependencies:

   - wicket
   - wicket-extensions
   - wicket-ioc
   - wicket-spring
   - wicket-datetime
   - wicketstuff-annotation
   - wicketstuff-objectautocomplete
   - wiquery-jquery-ui

All of them use the version 1.5.7. (Yes some of them don't belong to the
wicket project at all but they depend on wicket-1.5.x)

Is there a possibility of a dependency conflict?

NOTE: I found that wicket-ioc depends on "cglib". But even when I excluded
it the problem persists.
On Tue, Aug 14, 2012 at 2:27 PM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> I don't think this is anyhow related to Wicket.
> Here are the GMail SMTP related props I use successfully:
>
> mail.server.host=smtp.gmail.com
> mail.server.port=587
> mail.server.username=my.email@gmail.com
> mail.server.password=my-passwd
> mail.server.starttls.enable=true
>
> You may also check the docs of SMTPAppender in Logback. There are
> examples for configuring it with GMail. I believe the problem is in
> these settings.
>
> On Tue, Aug 14, 2012 at 5:34 AM, James Eliyezar <ja...@mcruncher.com>
> wrote:
> > Greetings to all of you.
> >
> > We recently upgraded our application to Wicket 1.5.
> > However, after upgrading we had problems sending email using SSL from our
> > application.
> > This may not be related to wicket at all but I promise we didn't change
> any
> > dependencies other than wicket's.
> > What amuses me is that it works as expected in our older versions which
> > still use Wicket 1.4.x.
> > Both the older version and the current version were run using the same
> JRE.
> >
> > Here's the code that sends email:
> >
> > <pre>
> > public class MailSenderTask implements Runnable
> > {
> >     private Properties smtpProperties;
> >     private EmailMessage message;
> >     private static final Logger logger =
> > LoggerFactory.getLogger(MailSenderTask.class);
> >
> >     public MailSenderTask(Properties smtpProperties, EmailMessage
> message)
> >     {
> >         this.smtpProperties = smtpProperties;
> >         this.message = message;
> >     }
> >
> >     public synchronized void sendMail() throws Exception
> >     {
> >         try {
> >             if (addSSlProvider()) {
> >                 logger.info("Adding ssl provider");
> >                 Security.addProvider(new
> > com.sun.net.ssl.internal.ssl.Provider());
> >             } else {
> >                 logger.info("Using plain text connection as ssl/tls is
> not
> > enabled");
> >             }
> >             Session session = createSession();
> >             MimeMessage mimeMessage = new MimeMessage(session);
> >             mimeMessage.setSender(new
> InternetAddress(message.getSender()));
> >             mimeMessage.setSubject(message.getSubject());
> >
> >             if (message.getRecipients().indexOf(',') > 0) {
> >                 mimeMessage.setRecipients(Message.RecipientType.TO,
> > InternetAddress.parse(message.getRecipients()));
> >             } else {
> >                 mimeMessage.setRecipient(Message.RecipientType.TO, new
> > InternetAddress(message.getRecipients()));
> >             }
> >
> >             MimeBodyPart bodyPart = new MimeBodyPart();
> >             bodyPart.setContent(message.getBody(), "text/html");
> >
> >             Multipart multipart = new MimeMultipart();
> >             multipart.addBodyPart(bodyPart);
> >
> >             if (message.getAttachments() != null &&
> > message.getAttachments().length > 0) {
> >                 for (File file : message.getAttachments()) {
> >                     logger.debug("Adding {} as an attachment", file);
> >                     MimeBodyPart attachmentPart = new MimeBodyPart();
> >                     attachmentPart.attachFile(file);
> >                     multipart.addBodyPart(attachmentPart);
> >                 }
> >             }
> >
> >             mimeMessage.setContent(multipart);
> >
> >             logger.info("Sending mail...");
> >             Transport.send(mimeMessage);
> >             logger.info("Mail sent to {}", message.getRecipients());
> >         } catch (Exception ex) {
> >             throw new EmailException("Error occurred while sending mail",
> > ex);
> >         }
> >     }
> >
> >     private boolean addSSlProvider()
> >     {
> >         String sslEnabledProperty =
> > smtpProperties.getProperty("mail.smtp.starttls.enable");
> >         if (StringUtils.isNotEmpty(sslEnabledProperty)) {
> >             return Boolean.parseBoolean(sslEnabledProperty);
> >         }
> >         return false;
> >     }
> >
> >     private Session createSession()
> >     {
> >         Session session = null;
> >         if
> > (Boolean.parseBoolean(smtpProperties.getProperty("mail.smtp.auth"))) {
> >             logger.info("Creating session with authentication");
> >             session = createSessionWithAuthentication(smtpProperties);
> >         } else {
> >             logger.info("Creating default session");
> >             session = createDefaultSession(smtpProperties);
> >         }
> >         return session;
> >     }
> >
> >     private Session createDefaultSession(final Properties smtpProperties)
> >     {
> >         return Session.getInstance(smtpProperties);
> >     }
> >
> >     private Session createSessionWithAuthentication(final Properties
> > smtpProperties)
> >     {
> >         return Session.getInstance(smtpProperties,
> >                 new Authenticator()
> >                 {
> >                     @Override
> >                     protected PasswordAuthentication
> > getPasswordAuthentication()
> >                     {
> >                         return new
> > PasswordAuthentication(smtpProperties.getProperty("smtp.username"),
> >
> > smtpProperties.getProperty("smtp.password"));
> >                     }
> >                 });
> >     }
> >
> >     public void run()
> >     {
> >         if (smtpProperties != null && message != null) {
> >             try {
> >                 sendMail();
> >             } catch (Exception ex) {
> >                 throw new EmailException("Error", ex);
> >             }
> >         }
> >     }
> > }
> > </pre>
> >
> > These are the SMTP properties that were set:
> >
> > <pre>
> > mail.smtp.socketFactory.fallback:false
> > mail.smtp.socketFactory.class:javax.net.ssl.SSLSocketFactory
> > mail.transport.protocol:smtp
> > mail.smtp.connectiontimeout:10000
> > mail.smtp.host:smtp.gmail.com
> > mail.smtp.timeout:10000
> > mail.smtp.starttls.enable:true
> > mail.smtp.port:465
> > mail.smtp.auth:true
> > mail.smtp.socketFactory.port:465
> > mail.smtp.quitwait:false
> > smtp.username:foo@gmail.com
> > smtp.password: bar
> > </pre>
> >
> > This is the exception thrown:
> >
> > <pre>
> > Caused by: javax.mail.MessagingException: Could not connect to SMTP host:
> > smtp.gmail.com, port: 465
> >     at
> com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
> > ~[mail-1.4.4.jar:1.4.4]
> >     at
> > com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
> > ~[mail-1.4.4.jar:1.4.4]
> >     at javax.mail.Service.connect(Service.java:297) ~[mail-1.4.jar:1.4]
> >     at javax.mail.Service.connect(Service.java:156) ~[mail-1.4.jar:1.4]
> >     at javax.mail.Service.connect(Service.java:105) ~[mail-1.4.jar:1.4]
> >     at javax.mail.Transport.send0(Transport.java:168) ~[mail-1.4.jar:1.4]
> >     at javax.mail.Transport.send(Transport.java:98) ~[mail-1.4.jar:1.4]
> >     at
> >
> com.mcruncher.core.module.email.util.MailSenderTask.sendMail(MailSenderTask.java:75)
> > ~[MailSenderTask.class:2.7.0-SNAPSHOT]
> >     ... 56 common frames omitted
> > Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException:
> > Unexpected error: java.security.InvalidAlgorithmParameterException: the
> > trustAnchors parameter must be non-empty
> >     at
> com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
> > ~[na:1.6]
> >     at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731)
> > ~[na:1.6]
> >     at
> > com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1692)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1675)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1204)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1181)
> > ~[na:1.6]
> >     at
> >
> com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
> > ~[mail-1.4.4.jar:1.4]
> >     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
> > ~[mail-1.4.4.jar:1.4]
> >     at
> com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
> > ~[mail-1.4.4.jar:1.4.4]
> >     ... 63 common frames omitted
> > Caused by: java.lang.RuntimeException: Unexpected error:
> > java.security.InvalidAlgorithmParameterException: the trustAnchors
> > parameter must be non-empty
> >     at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:57)
> > ~[na:1.6.0_33]
> >     at sun.security.validator.Validator.getInstance(Validator.java:161)
> > ~[na:1.6.0_33]
> >     at
> >
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:108)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:204)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
> > ~[na:1.6]
> >     at
> > com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
> > ~[na:1.6]
> >     at
> >
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1197)
> > ~[na:1.6]
> >     ... 67 common frames omitted
> > Caused by: java.security.InvalidAlgorithmParameterException: the
> > trustAnchors parameter must be non-empty
> >     at
> >
> java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
> > ~[na:1.6.0_33]
> >     at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
> > ~[na:1.6.0_33]
> >     at
> >
> java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
> > ~[na:1.6.0_33]
> >     at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:55)
> > ~[na:1.6.0_33]
> >     ... 78 common frames omitted
> > </pre>
> >
> > Eagerly awaiting fellow wicket users' help....
> >
> > --
> > Thanks & regards
> > James Selvakumar
> > mcruncher.com
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Thanks & regards
James Selvakumar
mcruncher.com

Re: Problem sending email using SSL after upgrading to Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I don't think this is anyhow related to Wicket.
Here are the GMail SMTP related props I use successfully:

mail.server.host=smtp.gmail.com
mail.server.port=587
mail.server.username=my.email@gmail.com
mail.server.password=my-passwd
mail.server.starttls.enable=true

You may also check the docs of SMTPAppender in Logback. There are
examples for configuring it with GMail. I believe the problem is in
these settings.

On Tue, Aug 14, 2012 at 5:34 AM, James Eliyezar <ja...@mcruncher.com> wrote:
> Greetings to all of you.
>
> We recently upgraded our application to Wicket 1.5.
> However, after upgrading we had problems sending email using SSL from our
> application.
> This may not be related to wicket at all but I promise we didn't change any
> dependencies other than wicket's.
> What amuses me is that it works as expected in our older versions which
> still use Wicket 1.4.x.
> Both the older version and the current version were run using the same JRE.
>
> Here's the code that sends email:
>
> <pre>
> public class MailSenderTask implements Runnable
> {
>     private Properties smtpProperties;
>     private EmailMessage message;
>     private static final Logger logger =
> LoggerFactory.getLogger(MailSenderTask.class);
>
>     public MailSenderTask(Properties smtpProperties, EmailMessage message)
>     {
>         this.smtpProperties = smtpProperties;
>         this.message = message;
>     }
>
>     public synchronized void sendMail() throws Exception
>     {
>         try {
>             if (addSSlProvider()) {
>                 logger.info("Adding ssl provider");
>                 Security.addProvider(new
> com.sun.net.ssl.internal.ssl.Provider());
>             } else {
>                 logger.info("Using plain text connection as ssl/tls is not
> enabled");
>             }
>             Session session = createSession();
>             MimeMessage mimeMessage = new MimeMessage(session);
>             mimeMessage.setSender(new InternetAddress(message.getSender()));
>             mimeMessage.setSubject(message.getSubject());
>
>             if (message.getRecipients().indexOf(',') > 0) {
>                 mimeMessage.setRecipients(Message.RecipientType.TO,
> InternetAddress.parse(message.getRecipients()));
>             } else {
>                 mimeMessage.setRecipient(Message.RecipientType.TO, new
> InternetAddress(message.getRecipients()));
>             }
>
>             MimeBodyPart bodyPart = new MimeBodyPart();
>             bodyPart.setContent(message.getBody(), "text/html");
>
>             Multipart multipart = new MimeMultipart();
>             multipart.addBodyPart(bodyPart);
>
>             if (message.getAttachments() != null &&
> message.getAttachments().length > 0) {
>                 for (File file : message.getAttachments()) {
>                     logger.debug("Adding {} as an attachment", file);
>                     MimeBodyPart attachmentPart = new MimeBodyPart();
>                     attachmentPart.attachFile(file);
>                     multipart.addBodyPart(attachmentPart);
>                 }
>             }
>
>             mimeMessage.setContent(multipart);
>
>             logger.info("Sending mail...");
>             Transport.send(mimeMessage);
>             logger.info("Mail sent to {}", message.getRecipients());
>         } catch (Exception ex) {
>             throw new EmailException("Error occurred while sending mail",
> ex);
>         }
>     }
>
>     private boolean addSSlProvider()
>     {
>         String sslEnabledProperty =
> smtpProperties.getProperty("mail.smtp.starttls.enable");
>         if (StringUtils.isNotEmpty(sslEnabledProperty)) {
>             return Boolean.parseBoolean(sslEnabledProperty);
>         }
>         return false;
>     }
>
>     private Session createSession()
>     {
>         Session session = null;
>         if
> (Boolean.parseBoolean(smtpProperties.getProperty("mail.smtp.auth"))) {
>             logger.info("Creating session with authentication");
>             session = createSessionWithAuthentication(smtpProperties);
>         } else {
>             logger.info("Creating default session");
>             session = createDefaultSession(smtpProperties);
>         }
>         return session;
>     }
>
>     private Session createDefaultSession(final Properties smtpProperties)
>     {
>         return Session.getInstance(smtpProperties);
>     }
>
>     private Session createSessionWithAuthentication(final Properties
> smtpProperties)
>     {
>         return Session.getInstance(smtpProperties,
>                 new Authenticator()
>                 {
>                     @Override
>                     protected PasswordAuthentication
> getPasswordAuthentication()
>                     {
>                         return new
> PasswordAuthentication(smtpProperties.getProperty("smtp.username"),
>
> smtpProperties.getProperty("smtp.password"));
>                     }
>                 });
>     }
>
>     public void run()
>     {
>         if (smtpProperties != null && message != null) {
>             try {
>                 sendMail();
>             } catch (Exception ex) {
>                 throw new EmailException("Error", ex);
>             }
>         }
>     }
> }
> </pre>
>
> These are the SMTP properties that were set:
>
> <pre>
> mail.smtp.socketFactory.fallback:false
> mail.smtp.socketFactory.class:javax.net.ssl.SSLSocketFactory
> mail.transport.protocol:smtp
> mail.smtp.connectiontimeout:10000
> mail.smtp.host:smtp.gmail.com
> mail.smtp.timeout:10000
> mail.smtp.starttls.enable:true
> mail.smtp.port:465
> mail.smtp.auth:true
> mail.smtp.socketFactory.port:465
> mail.smtp.quitwait:false
> smtp.username:foo@gmail.com
> smtp.password: bar
> </pre>
>
> This is the exception thrown:
>
> <pre>
> Caused by: javax.mail.MessagingException: Could not connect to SMTP host:
> smtp.gmail.com, port: 465
>     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
> ~[mail-1.4.4.jar:1.4.4]
>     at
> com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
> ~[mail-1.4.4.jar:1.4.4]
>     at javax.mail.Service.connect(Service.java:297) ~[mail-1.4.jar:1.4]
>     at javax.mail.Service.connect(Service.java:156) ~[mail-1.4.jar:1.4]
>     at javax.mail.Service.connect(Service.java:105) ~[mail-1.4.jar:1.4]
>     at javax.mail.Transport.send0(Transport.java:168) ~[mail-1.4.jar:1.4]
>     at javax.mail.Transport.send(Transport.java:98) ~[mail-1.4.jar:1.4]
>     at
> com.mcruncher.core.module.email.util.MailSenderTask.sendMail(MailSenderTask.java:75)
> ~[MailSenderTask.class:2.7.0-SNAPSHOT]
>     ... 56 common frames omitted
> Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException:
> Unexpected error: java.security.InvalidAlgorithmParameterException: the
> trustAnchors parameter must be non-empty
>     at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1692)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1675)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1204)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1181)
> ~[na:1.6]
>     at
> com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
> ~[mail-1.4.4.jar:1.4]
>     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
> ~[mail-1.4.4.jar:1.4]
>     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
> ~[mail-1.4.4.jar:1.4.4]
>     ... 63 common frames omitted
> Caused by: java.lang.RuntimeException: Unexpected error:
> java.security.InvalidAlgorithmParameterException: the trustAnchors
> parameter must be non-empty
>     at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:57)
> ~[na:1.6.0_33]
>     at sun.security.validator.Validator.getInstance(Validator.java:161)
> ~[na:1.6.0_33]
>     at
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:108)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:204)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
> ~[na:1.6]
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1197)
> ~[na:1.6]
>     ... 67 common frames omitted
> Caused by: java.security.InvalidAlgorithmParameterException: the
> trustAnchors parameter must be non-empty
>     at
> java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:183)
> ~[na:1.6.0_33]
>     at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:103)
> ~[na:1.6.0_33]
>     at
> java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:87)
> ~[na:1.6.0_33]
>     at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:55)
> ~[na:1.6.0_33]
>     ... 78 common frames omitted
> </pre>
>
> Eagerly awaiting fellow wicket users' help....
>
> --
> Thanks & regards
> James Selvakumar
> mcruncher.com



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org