[jboss-cvs] jboss-seam/src/mail/org/jboss/seam/mail/ui ...
Peter Muir
peter at bleepbleep.org.uk
Wed Jan 24 17:21:51 EST 2007
User: pmuir
Date: 07/01/24 17:21:51
Modified: src/mail/org/jboss/seam/mail/ui UIReplyTo.java
UIMessage.java AddressComponent.java UIFrom.java
UIBody.java MailComponent.java
RecipientAddressComponent.java UISubject.java
Log:
Improve exception handling
Revision Changes Path
1.4 +9 -3 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIReplyTo.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIReplyTo.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIReplyTo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIReplyTo.java 24 Jan 2007 17:11:30 -0000 1.3
+++ UIReplyTo.java 24 Jan 2007 22:21:50 -0000 1.4
@@ -5,6 +5,8 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;
/**
@@ -20,14 +22,18 @@
{
MimeMessage mimeMessage = findMimeMessage();
if (mimeMessage.getReplyTo() != null && mimeMessage.getReplyTo().length > 1) {
- throw new UnsupportedOperationException("Email cannot have more than one Reply-to address");
+ throw new AddressException("Email cannot have more than one Reply-to address", getAddress());
}
Address[] replyTo = {getInternetAddress(facesContext)};
mimeMessage.setReplyTo(replyTo);
}
- catch (Exception e)
+ catch (AddressException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage() + " " + "(" + e.getRef() + ")", e);
+ }
+ catch (MessagingException e)
+ {
+ throw new FacesException(e.getMessage(), e);
}
}
}
1.3 +3 -3 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIMessage.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIMessage.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIMessage.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIMessage.java 23 Jan 2007 19:25:31 -0000 1.2
+++ UIMessage.java 24 Jan 2007 22:21:51 -0000 1.3
@@ -4,6 +4,7 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
@@ -54,12 +55,11 @@
super.encodeEnd(arg0);
try
{
- // TODO Can we improve upon this?
Transport.send(getMimeMessage());
}
- catch (Exception e)
+ catch (MessagingException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage(), e);
}
}
1.2 +4 -2 jboss-seam/src/mail/org/jboss/seam/mail/ui/AddressComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AddressComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/AddressComponent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AddressComponent.java 21 Jan 2007 14:13:34 -0000 1.1
+++ AddressComponent.java 24 Jan 2007 22:21:51 -0000 1.2
@@ -3,7 +3,7 @@
import java.io.IOException;
import javax.faces.context.FacesContext;
-import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public abstract class AddressComponent extends MailComponent
@@ -19,8 +19,10 @@
/**
* get an InternetAddress object based upon name, address
+ * @throws IOException
+ * @throws AddressException
*/
- protected InternetAddress getInternetAddress(FacesContext facesContext) throws MessagingException, IOException
+ protected InternetAddress getInternetAddress(FacesContext facesContext) throws IOException, AddressException
{
InternetAddress address = new InternetAddress();
address.setAddress(getAddress() != null ? getAddress() : encode(facesContext));
1.3 +9 -3 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIFrom.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIFrom.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIFrom.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UIFrom.java 23 Jan 2007 19:25:31 -0000 1.2
+++ UIFrom.java 24 Jan 2007 22:21:51 -0000 1.3
@@ -4,6 +4,8 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;
/**
@@ -20,13 +22,17 @@
MimeMessage mimeMessage = findMimeMessage();
if (mimeMessage.getFrom() != null && mimeMessage.getFrom().length > 0) {
- throw new UnsupportedOperationException("Email cannot have more than one from address");
+ throw new AddressException("Email cannot have more than one from address", getAddress());
}
mimeMessage.setFrom(getInternetAddress(facesContext));
}
- catch (Exception e)
+ catch (AddressException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage() +"(" + e.getRef() + ")", e);
+ }
+ catch (MessagingException e)
+ {
+ throw new FacesException(e.getMessage(), e);
}
}
}
1.2 +3 -2 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIBody.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIBody.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIBody.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIBody.java 21 Jan 2007 14:13:34 -0000 1.1
+++ UIBody.java 24 Jan 2007 22:21:51 -0000 1.2
@@ -6,6 +6,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.mail.BodyPart;
+import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
@@ -56,9 +57,9 @@
}
}
}
- catch (Exception e)
+ catch (MessagingException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage(), e);
}
}
1.3 +2 -2 jboss-seam/src/mail/org/jboss/seam/mail/ui/MailComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MailComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/MailComponent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- MailComponent.java 23 Jan 2007 19:25:31 -0000 1.2
+++ MailComponent.java 24 Jan 2007 22:21:51 -0000 1.3
@@ -56,7 +56,7 @@
/**
* look up the tree for mail message
*/
- public MimeMessage findMimeMessage() throws MessagingException {
+ public MimeMessage findMimeMessage() {
UIMessage parent = (UIMessage) findParent(this, UIMessage.class);
if (parent != null)
{
1.2 +8 -2 jboss-seam/src/mail/org/jboss/seam/mail/ui/RecipientAddressComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RecipientAddressComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/RecipientAddressComponent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- RecipientAddressComponent.java 21 Jan 2007 14:13:34 -0000 1.1
+++ RecipientAddressComponent.java 24 Jan 2007 22:21:51 -0000 1.2
@@ -4,7 +4,9 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.mail.MessagingException;
import javax.mail.Message.RecipientType;
+import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;
/**
@@ -22,9 +24,13 @@
MimeMessage mimeMessage = findMimeMessage();
mimeMessage.addRecipient(getRecipientType(), getInternetAddress(facesContext));
}
- catch (Exception e)
+ catch (AddressException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage() + " (" + e.getRef() +")", e);
+ }
+ catch (MessagingException e)
+ {
+ throw new FacesException(e.getMessage(), e);
}
}
1.2 +3 -2 jboss-seam/src/mail/org/jboss/seam/mail/ui/UISubject.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UISubject.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UISubject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UISubject.java 21 Jan 2007 14:13:34 -0000 1.1
+++ UISubject.java 24 Jan 2007 22:21:51 -0000 1.2
@@ -4,6 +4,7 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.mail.MessagingException;
/**
* JSF component for rendering subject line
@@ -18,9 +19,9 @@
String subject = encode(facesContext);
findMimeMessage().setSubject(subject);
}
- catch (Exception e)
+ catch (MessagingException e)
{
- throw new FacesException(e);
+ throw new FacesException(e.getMessage(), e);
}
}
}
More information about the jboss-cvs-commits
mailing list