Author: emuckenhuber
Date: 2008-03-12 11:38:16 -0400 (Wed, 12 Mar 2008)
New Revision: 10273
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailService.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/impl/IdentityMailServiceImpl.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/UIComponentConfiguration.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/UsernameValidator.java
Log:
better logging and minor cleanup
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailService.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailService.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailService.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -34,6 +34,25 @@
*/
public interface IdentityMailService
{
- void sendMail(String templateLocation, Map mailData, Locale locale) throws
IOException, TemplateException;
+ /**
+ * Generates and sends an email based on a template.
+ *
+ * @param the template location (directory)
+ * @param a map required for the template
+ * @param the requested locale
+ * @throws IOException
+ * @throws TemplateException
+ */
+ void sendMail(String templateLocation, Map<String, String> mailData, Locale
locale) throws IOException, TemplateException;
+
+ /**
+ * Sends an email
+ *
+ * @param email from
+ * @param email to
+ * @param subject
+ * @param email body
+ */
+ public void send(String emailFrom, String emailTo, String subject, String emailText);
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -42,9 +42,6 @@
*/
public class WorkflowSoftDependency extends AbstractJBossService
{
-
- private Logger log = Logger.getLogger(WorkflowSoftDependency.class);
-
private MBeanServer server;
private IdentityUIConfigurationService identityUIConfigurationService;
@@ -55,6 +52,9 @@
private ObjectName workflowServiceObjectName;
+ /** The logger. */
+ private Logger log = Logger.getLogger(WorkflowSoftDependency.class);
+
public WorkflowSoftDependency()
{
server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
@@ -84,7 +84,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error("Error starting workflow", e);
}
}
@@ -95,7 +95,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error(e);
}
}
@@ -107,7 +107,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error(e);
}
}
@@ -148,7 +148,7 @@
}
catch (MBeanProxyCreationException e)
{
- e.printStackTrace();
+ log.error("Error starting workflow", e);
}
}
else
@@ -162,7 +162,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error(e);
}
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/impl/IdentityMailServiceImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/impl/IdentityMailServiceImpl.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/impl/IdentityMailServiceImpl.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -28,12 +28,12 @@
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.URL;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import org.jboss.logging.Logger;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.identity.services.IdentityConstants;
import org.jboss.portal.core.identity.services.IdentityMailService;
import org.jboss.portal.core.identity.services.metadata.IdentityUIConfiguration;
@@ -52,47 +52,42 @@
*/
public class IdentityMailServiceImpl extends AbstractJBossService implements
IdentityMailService
{
-
- /** Template mail data */
- private Map mailData = new HashMap();
-
- /** Requested locale */
- private Locale locale;
-
- /** The e-mail text */
- private String emailText = null;
- /** The e-mail domain */
+ /** The e-mail domain. */
private String emailDomain = null;
- /** E-Mail from */
+ /** E-Mail from. */
private String emailFrom = null;
-
- /** Template location */
- private String templateLocation;
-
- /** The mail module */
+
+ /** The mail module. */
private MailModule mailModule;
- /** The core-identity configuration service */
+ /** The template path. */
+ private static final String TEMPLATE_PATH = "conf/templates/";
+
+ /** The template prefix. */
+ private static final String TEMPLATE_PREFIX = "/emailTemplate_";
+
+ /** The core-identity configuration service. */
private IdentityUIConfigurationService identityUIConfigurationService;
- /** . */
+ /** The logger */
private static final Logger log = Logger.getLogger(IdentityMailServiceImpl.class);
- /** . */
+ /** The JNDI binding */
private JNDI.Binding jndiBinding;
- /** . */
+ /** The JNDI name */
private String jndiName = null;
public void startService() throws Exception
{
super.startService();
- IdentityUIConfiguration cf =this.identityUIConfigurationService.getConfiguration();
- this.emailDomain = cf.getEmailDomain();
- this.emailFrom = cf.getEmailFrom();
+ IdentityUIConfiguration cf
=this.identityUIConfigurationService.getConfiguration();
+ // Set mail attributes
+ this.setEmailDomain(cf.getEmailDomain());
+ this.setEmailFrom(cf.getEmailFrom());
if (this.jndiName != null)
{
@@ -119,6 +114,9 @@
public void setEmailDomain(String emailDomain)
{
+ if(emailDomain == null)
+ throw new IllegalArgumentException("email domain may not be null.");
+
this.emailDomain = emailDomain;
}
@@ -129,6 +127,9 @@
public void setEmailFrom(String emailFrom)
{
+ if(emailFrom == null)
+ throw new IllegalArgumentException("email from may not be null.");
+
this.emailFrom = emailFrom;
}
@@ -162,12 +163,16 @@
this.jndiName = jndiName;
}
- public void sendMail(String templateLocation, Map mailData, Locale locale) throws
IOException, TemplateException
+ public void sendMail(String templateLocation, Map<String, String> mailData,
Locale locale) throws IOException, TemplateException
{
- this.templateLocation = templateLocation;
- this.mailData = mailData;
- this.locale = locale;
- this.mailData.put(IdentityConstants.EMAIL_DOMAIN, emailDomain);
+ if(templateLocation == null)
+ throw new IllegalArgumentException("template location may not be
null.");
+ if(mailData == null)
+ throw new IllegalArgumentException("mail data may not be null.");
+ if(locale == null)
+ throw new IllegalArgumentException("locale may not be null.");
+
+ mailData.put(IdentityConstants.EMAIL_DOMAIN, emailDomain);
ResourceBundle bundle = ResourceBundle.getBundle("conf.bundles.Identity",
locale);
@@ -188,41 +193,49 @@
}
else
{
- throw new IllegalArgumentException("unknown template.");
+ subject = bundle.getString(templateLocation);
+ if(subject == null)
+ throw new IllegalArgumentException("unknown template.");
}
// Generating message
- this.generateEmailText();
+ String emailText = generateEmailText(templateLocation, mailData, locale);
// log.debug(this.emailText);
// Sending mail
- this.getMailModule().send(emailFrom, to , subject, emailText);
+ send(emailFrom, to , subject, emailText);
}
- private void generateEmailText() throws IOException, TemplateException
+ public void send(String emailFrom, String emailTo, String subject, String emailText)
{
+ this.getMailModule().send(emailFrom, emailTo, subject, emailText);
+ }
+
+ private String generateEmailText(String templateLocation, Map<String, String>
mailData, Locale locale) throws IOException, TemplateException
+ {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- URL config = tcl.getResource("conf/templates/" + this.templateLocation +
"/emailTemplate_" + locale.getLanguage() + "_" + locale.getCountry() +
".tpl");
+ URL config = tcl.getResource(TEMPLATE_PATH + templateLocation + TEMPLATE_PREFIX +
locale.getLanguage() + "_" + locale.getCountry() + ".tpl");
if (config == null)
{
- config = tcl.getResource("conf/templates/" + this.templateLocation +
"/emailTemplate_" + locale.getLanguage() + ".tpl");
+ config = tcl.getResource(TEMPLATE_PATH + templateLocation + TEMPLATE_PREFIX +
locale.getLanguage() + ".tpl");
}
if (config == null)
{
- config = tcl.getResource("conf/templates/" + this.templateLocation +
"/emailTemplate.tpl");
+ config = tcl.getResource(TEMPLATE_PATH + templateLocation + TEMPLATE_PREFIX +
".tpl");
}
if (config == null)
{
- throw new FileNotFoundException("Cannot load a suitable emailTemplate.tpl
in conf/templates/"
- + this.templateLocation);
+ throw new FileNotFoundException("Cannot load a suitable email templte in:
" + TEMPLATE_PATH);
}
+
InputStream in = config.openStream();
Template tpl = new Template("emailTemplate", new InputStreamReader(in),
new Configuration());
StringWriter out = new StringWriter();
- tpl.process(this.mailData, out);
- out.close();
+ tpl.process(mailData, out);
- this.emailText = out.toString();
+ IOTools.safeClose(out);
+
+ return out.toString();
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -87,7 +87,7 @@
// Loading workflow if subscriptionmodes != automatic
if (this.configuration.enableWorkflow())
{
-
+ // Throws an CoreIdentityConfigurationException if the workflow service is
null
this.isValidConfiguration();
String subscriptionMode = this.configuration.getSubscriptionMode();
@@ -221,7 +221,7 @@
JbpmContext jbpmContext = null;
try
- {
+ {
jbpmContext =
this.getWorkflowService().getJbpmConfiguration().createJbpmContext();
ProcessDefinition processDefinition =
jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
@@ -243,7 +243,7 @@
}
catch(Exception e)
{
- throw new CoreIdentityConfigurationException("I don't like your
subscription mode! Please make sure that the file and the process name match - also check
the syntax.");
+ throw new CoreIdentityConfigurationException("I don't like your
subscription mode! Please make sure that the file and the process name match - also check
the syntax.", e);
}
finally
{
@@ -279,8 +279,7 @@
}
catch (IdentityException e)
{
- uiComponent = null;
- throw new IllegalArgumentException("cannot resolve property:
" + uiComponent.getPropertyRef());
+ throw new IllegalArgumentException("cannot resolve property:
" + uiComponent.getPropertyRef(), e);
}
}
return uiComponent;
@@ -332,11 +331,11 @@
}
catch (IOException e)
{
- throw new CoreIdentityConfigurationException("Could not find configuration
file or schema.");
+ throw new CoreIdentityConfigurationException("Could not find configuration
file or schema.", e);
}
catch (JBossXBException e)
{
- throw new CoreIdentityConfigurationException("Could not parse configuration
file.");
+ throw new CoreIdentityConfigurationException("Could not parse configuration
file.", e);
}
catch (Throwable e)
{
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/UIComponentConfiguration.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/UIComponentConfiguration.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/UIComponentConfiguration.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -166,6 +166,6 @@
public Class getPropertyClass() throws ClassNotFoundException
{
// Returns the Class of the Property
- return ClassLoader.getSystemClassLoader().loadClass(this.propertyInfo.getType());
+ return
Thread.currentThread().getContextClassLoader().loadClass(this.propertyInfo.getType());
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -78,11 +78,10 @@
emailMap.put("username", uc.getUsername());
emailMap.put("password", uc.getPassword());
}
- // Change email
+ // Change email request (send an email to the NEW email address)
else if (IdentityConstants.ACTION_CHANGE_EMAIL.equals(action))
{
- String emailTo =
this.getIdentityManagementService().getCurrentEmail(uc.getUsername());
- emailMap.put(IdentityConstants.EMAIL_TO, emailTo);
+ emailMap.put(IdentityConstants.EMAIL_TO, email);
}
else
{
@@ -90,7 +89,8 @@
}
ectx.getContextInstance().setVariable(IdentityConstants.VALIDATION_HASH, hash);
- // Building the validation URL
+
+ // Generating the validation URL
String portalURL = (String)
ectx.getContextInstance().getVariable(IdentityConstants.PORTAL_URL);
String activationLink = portalURL + "/" +
IdentityConstants.VALIDATE_EMAIL + "/"
+ ectx.getProcessInstance().getId() + "/" + hash;
@@ -149,21 +149,4 @@
return identityMailService;
}
- private IdentityUserManagementService getIdentityManagementService()
- {
- if (identityManagementService == null)
- {
- try
- {
- this.identityManagementService = (IdentityUserManagementService) new
InitialContext()
- .lookup("java:/portal/IdentityUserManagementService");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return identityManagementService;
- }
-
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/UsernameValidator.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/UsernameValidator.java 2008-03-12
12:21:16 UTC (rev 10272)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/UsernameValidator.java 2008-03-12
15:38:16 UTC (rev 10273)
@@ -52,6 +52,9 @@
/** The registration service */
private RegistrationService registrationService;
+ /** The logger */
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(UsernameValidator.class);
+
public void validate(FacesContext context, UIComponent component, Object value) throws
ValidatorException
{
String username = (String) value;
@@ -66,12 +69,14 @@
// checking jBPM context
if (registrationService.checkUsername(username))
{
- throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_TAKEN") +
username));
+ throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_TAKEN")
+ + username));
}
User u = userModule.findUserByUserName(username);
// User found so this nickname is already taken
- throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_TAKEN") +
u.getUserName()));
+ throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_TAKEN")
+ + u.getUserName()));
}
catch (NoSuchUserException e)
{
@@ -83,11 +88,13 @@
}
catch (IdentityException e)
{
+ log.error("Error validation username", e);
throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_ERROR")));
}
catch (CoreIdentityConfigurationException e)
{
- throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_ERROR")));
+ log.error("Error validation username", e);
+ throw new ValidatorException(new
FacesMessage(bundle.getString("IDENTITY_VALIDATION_ERROR_USERNAME_ERROR")));
}
}
}