掲示板

MessageListener issue

thumbnail
7年前 に Sachin J によって更新されました。

MessageListener issue

New Member 投稿: 21 参加年月日: 15/10/09 最新の投稿
Hi ,

I want to access the serviceContext to save my pdf document into document media.
i have scheduling some jobs and then create PDF file and save in document media.
How can I achieve this?


ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();



pdfFile= pdfGenerationUtil.createPdf(addressModel, subscriberFormAcceptanceModel, agentsDetailModel,userSubScriptionModel,paymentMap,productMap,smartCardMap);
File file=new File(pdfFile);
String fileName=file.getName();

InputStream fis =new FileInputStream(file);
OutputBlob dataOutputBlob = new OutputBlob(fis, file.length());

try {
DLAppLocalServiceUtil.addFileEntry(20199, 20182, 97104, file.getName(), "application/pdf", userSubScriptionModel.getSurname()+userSubScriptionModel.getSubscriptionId(), "dlapp save", "1.0", file, serviceContext);

Error :

er.messaging.ReceiverKey@dcc05254, MESSAGE_LISTENER_UUID=e30bca0a-7f92-4658-8324-28c95518c767}}
com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.NullPointerException
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:86)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:72)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:71)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at com.liferay.portal.repository.liferayrepository.LiferayRepositoryBase.getDefaultFileEntryTypeId(LiferayRepositoryBase.java:159)
at com.liferay.portal.repository.liferayrepository.LiferayLocalRepository.addFileEntry(LiferayLocalRepository.java:117)
at com.liferay.portlet.documentlibrary.service.impl.DLAppLocalServiceImpl.addFileEntry(DLAppLocalServiceImpl.java:200)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
at $Proxy196.addFileEntry(Unknown Source)
at com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil.addFileEntry(DLAppLocalServiceUtil.java:152)
at com.multichoice.schedular.SubScriberSchedular.receive(SubScriberSchedular.java:153)
at sun.reflect.GeneratedMethodAccessor1208.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at $Proxy594.receive(Unknown Source)
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:77)
... 5 more




Kind Regards,
Sudhakar
7年前 に Dávid Matejkov によって更新されました。

RE: MessageListener issue

New Member 投稿: 18 参加年月日: 15/12/15 最新の投稿
Did you try
ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
7年前 に Dávid Matejkov によって更新されました。

RE: MessageListener issue

New Member 投稿: 18 参加年月日: 15/12/15 最新の投稿
Well I tried my old example with
ServiceContextThreadLocal.getServiceContext();

And it is working the same as
ServiceContextFactory.getInstance(actionRequest);

So the problem is not in serviceContext
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: MessageListener issue

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hey David,

I'm going to make an assumption that you are using 6.2. I've had similar issues before and it all traced back (for me) to the service context ultimately not being what I expected it to be. When you use the factory to create a service context, you get a lot of the fields on the object. For example, the company id and the scope group id are set for you because Liferay knows how to find them based on things like the url (attaching the host to a company id, and the group friendly url to the scope group id). When the scheduled job runs, there is no such context because it doesn't come from an inbound request object that contains that kind of information. The null pointer, according to your stack trace originates with this method --

protected long getDefaultFileEntryTypeId(
			ServiceContext serviceContext, long folderId)
		throws PortalException, SystemException {

		folderId = dlFolderLocalService.getFolderId(
			serviceContext.getCompanyId(), folderId);

		return dlFileEntryTypeLocalService.getDefaultFileEntryTypeId(folderId);
	}


The thread locals are awesome, but they are set based on one of the filters in the request chain being executed -- so I don't think that it is complete when you use it in a scheduled job. I faced something along these lines recently with a startup action that I wrote where all you have is the companyId. In the end I wrote a utility class that, based on some configs I added to the portal-ext uses Liferay's API to look up the data points I need to have in the service context and then I created a utility to generate the service context for me.

I'm not sure if you have the same issue or not, but I would set a breakpoint in my listener and check to see if the ServiceContextThreadLocal is actually returning an object, or if you are getting a null.