Foros de discusión

Send a mail in a Service Hook

François LE QUEMENER, modificado hace 12 años.

Send a mail in a Service Hook

Junior Member Mensajes: 48 Fecha de incorporación: 18/09/09 Mensajes recientes
Hi,

I'm trying to hook JournalArticleLocalService, to send a mail when an article has been marked has expired. I overrode the method "checkArticles()", and wrote a simple method to send a mail (since I could not re-use the parent method) :

/**
	 * See JournalArticleLocalServiceImpl.sendEmail
	 * 
	 * @param article
	 * @param articleURL
	 * @param preferences
	 * @throws IOException
	 * @throws PortalException
	 * @throws SystemException
	 */
	protected void sendEmail(JournalArticle article, String articleURL, PortletPreferences preferences)
		throws IOException, PortalException, SystemException {

		if (preferences == null) {
			return;
		}

		Company company = CompanyLocalServiceUtil.getCompany(article.getCompanyId());

		User user = UserLocalServiceUtil.getUser(article.getUserId());

		articleURL +=
			"&groupId=" + article.getGroupId() + "&articleId=" +
				article.getArticleId() + "&version=" + article.getVersion();

		String portletName = PortalUtil.getPortletTitle(
			PortletKeys.JOURNAL, user);

		String fromName = preferences.getValue("email-from-name", StringPool.BLANK);
		String fromAddress = preferences.getValue("email-from-address", StringPool.BLANK);

		String toName = user.getFullName();
		String toAddress = user.getEmailAddress();

		String subject = null;
		String body = null;

		subject = LanguageUtil.get(user.getLocale(), ARTICLE_EXPIRED_SUBJECT_KEY);
		body = LanguageUtil.get(user.getLocale(), ARTICLE_EXPIRED_BODY_KEY);

		subject = StringUtil.replace(
			subject,
			new String[] {
				"[$ARTICLE_ID$]",
				"[$ARTICLE_TITLE$]",
				"[$ARTICLE_URL$]",
				"[$ARTICLE_USER_NAME$]",
				"[$ARTICLE_VERSION$]",
				"[$FROM_ADDRESS$]",
				"[$FROM_NAME$]",
				"[$PORTAL_URL$]",
				"[$PORTLET_NAME$]",
				"[$TO_ADDRESS$]",
				"[$TO_NAME$]"
			},
			new String[] {
				article.getArticleId(),
				article.getTitle(),
				articleURL,
				article.getUserName(),
				String.valueOf(article.getVersion()),
				fromAddress,
				fromName,
				company.getVirtualHost(),
				portletName,
				toAddress,
				toName,
			});

		body = StringUtil.replace(
			body,
			new String[] {
				"[$ARTICLE_ID$]",
				"[$ARTICLE_TITLE$]",
				"[$ARTICLE_URL$]",
				"[$ARTICLE_USER_NAME$]",
				"[$ARTICLE_VERSION$]",
				"[$FROM_ADDRESS$]",
				"[$FROM_NAME$]",
				"[$PORTAL_URL$]",
				"[$PORTLET_NAME$]",
				"[$TO_ADDRESS$]",
				"[$TO_NAME$]"
			},
			new String[] {
				article.getArticleId(),
				article.getTitle(),
				articleURL,
				article.getUserName(),
				String.valueOf(article.getVersion()),
				fromAddress,
				fromName,
				company.getVirtualHost(),
				portletName,
				toAddress,
				toName,
			});

		InternetAddress from = new InternetAddress(fromAddress, fromName);

		InternetAddress to = new InternetAddress(toAddress, toName);

		MailMessage message = new MailMessage(from, to, subject, body, true);
		
		MailServiceUtil.sendEmail(message);
	}


The problem is where I create the MailMessage object. I get this Exception:

Exception in thread "liferay/scheduler_dispatch" java.lang.LinkageError: loader constraint violation: when resolving method "com.liferay.portal.kernel.mail.MailMessage.<init>(Ljavax/mail/internet/InternetAddress;Ljavax/mail/internet/InternetAddress;Ljava/lang/String;Ljava/lang/String;Z)V" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, fr/villedeniort/hook/expando/JournalArticleLocalServiceWrapperImpl, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, com/liferay/portal/kernel/mail/MailMessage, have different Class objects for the type javax/mail/internet/InternetAddress used in the signature
	at fr.villedeniort.hook.expando.JournalArticleLocalServiceWrapperImpl.sendEmail(JournalArticleLocalServiceWrapperImpl.java:189)
	at fr.villedeniort.hook.expando.JournalArticleLocalServiceWrapperImpl.checkArticles(JournalArticleLocalServiceWrapperImpl.java:69)
	at sun.reflect.GeneratedMethodAccessor471.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
	at $Proxy305.checkArticles(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor471.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:86)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy169.checkArticles(Unknown Source)
	at com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil.checkArticles(JournalArticleLocalServiceUtil.java:329)
	at com.liferay.portlet.journal.messaging.CheckArticleMessageListener.doReceive(CheckArticleMessageListener.java:29)
	at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:25)
	at sun.reflect.GeneratedMethodAccessor469.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
	at $Proxy238.receive(Unknown Source)
	at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:73)
	at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:63)
	at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:63)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)</init>


Do you see what it means?

Thanks!
biswajit sarkar, modificado hace 11 años.

RE: Send a mail in a Service Hook

Regular Member Mensajes: 166 Fecha de incorporación: 17/10/11 Mensajes recientes
I am getting same problem.

anyone aware about this problem??
thumbnail
Paul Gloessl, modificado hace 10 años.

RE: Send a mail in a Service Hook

New Member Mensajes: 12 Fecha de incorporación: 15/07/13 Mensajes recientes
My answer in this thread should help you.