Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 11180 invoked by uid 500); 23 Apr 2001 19:23:27 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 11068 invoked from network); 23 Apr 2001 19:23:24 -0000 From: "Vadim Gritsenko" To: Subject: RE: [C2] Failed to build Date: Mon, 23 Apr 2001 15:22:55 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_005B_01C0CC09.451FD560" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: Importance: Normal X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N ------=_NextPart_000_005B_01C0CC09.451FD560 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Donald, Here is the diff. Added smptport parameter, username, password. Username and password is optional, and if not specified then null authenticator will be used (it works for me). Otherwise, authenticator will be created. Please note that username / password can be overriden by action's parameters. In this case, instead of calling getDefaultInstance, getInstance method will be used. Also, I see a potential problem with getDefaultInstance: if someone creates more then one instance of action (or someone uses JavaMail from any other place), it will not work: getDefaultInstance may be used only with the same authenticator, i.e. from one action in our case. May be you want to use getInstance instead - then pls modify line 90 and 97 of the diff file so they read: + Authenticator authenticator = default_authenticator; and + Session session = Session.getInstance(properties, authenticator); PS: Donald, I did not tested functionality (do not have a sample), but it compiles. Thanks, Vadim > -----Original Message----- > From: Donald Ball [mailto:balld@webslingerZ.com] > Sent: Monday, April 23, 2001 12:43 > To: Cocoon Developers > Subject: Re: [C2] Failed to build > > > On Mon, 23 Apr 2001, Vadim Gritsenko wrote: > > > I have got build error; Cocoon 2 just from CVS: > > ------------------------------------------------------------- > > compile: > > [copy] Copying 12 files to > C:\Apache\xml-cocoon\build\cocoon\classes > > [javac] Compiling 224 source files to > > C:\Apache\xml-cocoon\build\cocoon\classes > > [javac] > > > C:\Apache\xml-cocoon\build\cocoon\src\org\apache\cocoon\acting\Sen > dmailActio > > n.java:83: Wrong number of arguments in method. > > [javac] Session session = > Session.getDefaultInstance(properties); > > [javac] ^ > > [javac] Note: 5 files use or override a deprecated API. > Recompile with > > "-deprecation" for details. > > [javac] 1 error, 1 warning > > > > BUILD FAILED > > ------------------------------------------------------------- > > The problem is that javax.mail.Session does have this method only from > > JavaMail version 1.2 (and up), and existing implementations > (weblogic up to > > 6.0sp1, j2sdkee1.2) of JavaMail have another method: > > public static Session getDefaultInstance(java.util.Properties props, > > Authenticator authenticator) > > > > So, the question is: > > What everybody uses this class with? > > if you compile c2 with an empty classpath, it will ignore the > SendmailAction class. if you want to compile it, download the mailapi.jar > from sun and put it in your classpath (or cocoon's lib directory). if you > want to flip me a patch to add the Authenticator object, that'd be swell. > > - donald > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > > ------=_NextPart_000_005B_01C0CC09.451FD560 Content-Type: application/octet-stream; name="SendmailAction.java.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="SendmailAction.java.diff" Index: SendmailAction.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-cocoon/src/org/apache/cocoon/acting/Attic/SendmailAct= ion.java,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 SendmailAction.java --- SendmailAction.java 2001/04/20 20:49:45 1.1.2.5 +++ SendmailAction.java 2001/04/23 19:13:22 @@ -15,6 +15,8 @@ import javax.mail.Message; import javax.mail.Transport; import javax.mail.Session; +import javax.mail.Authenticator; +import javax.mail.PasswordAuthentication; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; @@ -35,6 +37,12 @@ *
*
smtphost
*
the smtp server to send the mail through
+ *
smtpport
+ *
the smtp server's port (default is 25)
+ *
username
+ *
the username used to authenticate with smtp server = (optional)
+ *
password
+ *
the password for authentication with smtp server = (optional)
*
from
*
the email address the mail appears to be from
*
to
@@ -57,17 +65,47 @@ */ public class SendmailAction extends AbstractAction { =20 + private static class PasswordAuthenticator extends Authenticator + { + String username; + String password; + + public PasswordAuthenticator(String username, String password) + { + this.username =3D username; + this.password =3D password; + } + + protected PasswordAuthentication getPasswordAuthentication() + { + return new PasswordAuthentication(username, password); + } + } + Properties default_properties =3D null; + Authenticator default_authenticator =3D null; =20 public void configure(Configuration conf) throws = ConfigurationException { getLogger().debug("SendmailAction: init"); + default_properties =3D new Properties(); if (conf.getAttribute("smtphost") !=3D null) { = default_properties.put("mail.smtp.host",conf.getAttribute("smtphost")); } else { default_properties.put("mail.smtp.host","127.0.0.1"); + } + if (conf.getAttribute("smtpport") !=3D null) { + = default_properties.put("mail.smtp.port",conf.getAttribute("smtpport")); + } else { + default_properties.put("mail.smtp.port","25"); + } + if (conf.getAttribute("username") !=3D null) { + default_authenticator =3D new PasswordAuthenticator( + conf.getAttribute("username"), = conf.getAttribute("password")); } - getLogger().debug("SendmailAction: using = "+default_properties.get("mail.smtp.host")+" as the smtp server"); + + getLogger().debug("SendmailAction: using " + = default_properties.get("mail.smtp.host") + + ":" + default_properties.get("mail.smtp.port") + " as the = smtp server"); } =20 public Map act(EntityResolver resolver, Map objectModel, String = source, Parameters parameters) throws Exception { @@ -79,8 +117,23 @@ if (parameters.isParameter("smtphost")) { = properties.put("mail.smtp.host",parameters.getParameter("smtphost",null))= ; getLogger().debug("SendmailAction: overriding default smtp = server, using "+properties.get("mail.smtp.host")); + } + if (parameters.isParameter("smtpport")) { + = properties.put("mail.smtp.port",parameters.getParameter("smtpport",null))= ; + getLogger().debug("SendmailAction: overriding default smtp = server port, using "+properties.get("mail.smtp.port")); } - Session session =3D Session.getDefaultInstance(properties); + + Authenticator authenticator =3D null; + if (parameters.isParameter("username")) { + final String username =3D parameters.getParameter("username", = null); + authenticator =3D new PasswordAuthenticator(username, = parameters.getParameter("password", null)); + getLogger().debug("SendmailAction: overriding default = credentials, using " + username); + } + + Session session =3D (authenticator =3D=3D null)? + Session.getDefaultInstance(properties, default_authenticator) + :Session.getInstance(properties, authenticator); + Message message =3D new MimeMessage(session); String from =3D null; String to =3D null; ------=_NextPart_000_005B_01C0CC09.451FD560 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org ------=_NextPart_000_005B_01C0CC09.451FD560--