Fórum

Errors using Document Library API on liferay 5.1.1

thumbnail
cax queiroz, modificado 15 Anos atrás.

Errors using Document Library API on liferay 5.1.1

New Member Postagens: 19 Data de Entrada: 13/02/07 Postagens Recentes
Hi there,
I am trying to use the DL API to upload files on liferay 5.1.1. However, I am getting this error:

java.lang.NullPointerException
at com.liferay.portal.kernel.search.SearchEngineUtil._addDocument(SearchEngineUtil.java:96)
at com.liferay.portal.kernel.search.SearchEngineUtil.addDocument(SearchEngineUtil.java:46)
at com.liferay.documentlibrary.util.Indexer.addFile(Indexer.java:85)
at com.liferay.documentlibrary.util.JCRHook.addFile(JCRHook.java:153)
at com.liferay.documentlibrary.service.impl.DLLocalServiceImpl.addFile(DLLocalServiceImpl.java:69)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.addFileEntry(DLFileEntryLocalServiceImpl.java:256)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.addFileEntry(DLFileEntryLocalServiceImpl.java:201)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.addFileEntry(DLFileEntryLocalServiceImpl.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy214.addFileEntry(Unknown Source)
at com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.addFileEntry(DLFileEntryLocalServiceUtil.java:122)
at au.net.orm.service.OrmAttachmentsLocalServiceTest.testAddFile(OrmAttachmentsLocalServiceTest.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


I've tried to use:

DLLocalServiceUtil
DLServiceUTil
DLFileEntryLocalServiceUtil

In all of them I've got the same error. And if I try to add the same file I get a duplicatefileexception, it means it added the file but I cannot get a reference to it.

Code snippet:
File file = new File("/tmp/t1.pdf");
byte[] data = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(data);
DLFolder folder = DLFolderLocalServiceUtil.getDLFolder(10301);
DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(user.getUserId(), folder.getFolderId(),
"HelloW3.pdf", "Hello World23", "Test2", new String[0], "", data, false, false);

the DLFolderLocalServiceUtil returns successfully (I've created a folder previously). From the folder object I get its folderId and use on DLFileEntryLocalServiceUtil.addFileEntry.

Any ideas?

thanks,

caxqueiroz
thumbnail
Bruno Farache, modificado 15 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
Seems like you are calling it from a test case. If that's the case, you need to setup a lot of stuff before the actual service method call, in this specific case, the SearchEngineUtil is not being configured by spring.

Look for how the test cases are done in the source code, how things are warmed up.
thumbnail
cax queiroz, modificado 15 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

New Member Postagens: 19 Data de Entrada: 13/02/07 Postagens Recentes
Test case is not the problem. As I am (was) using the basetestcase used on lportal. And I have many other test cases working with no problem.

I also have tested using a portlet to do the upload. With NO success, though.

First I tried to use the DLService/DLLocalService as used on wiki portlet with NO success as well.

Guess I have to create/use my own file container emoticon
thumbnail
Bruno Farache, modificado 15 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
The exception is happening at:

at com.liferay.portal.kernel.search.SearchEngineUtil._addDocument(SearchEngineUtil.java:96), this line is something like:
_messageBusIndexWriter.addDocument(companyId, doc);

Null pointer exception is thrown because messageBusIndexWriter is null, that is, SearchEngineUtil wasn't initialized during startup. The current ServiceTestSuite initializes it before adding the test suites:
SearchEngineUtil.init(new IndexSearcherImpl(), new IndexWriterImpl());

Check if this is being called...

Are you calling the service from a deployable portlet or a portlet built with ext environment?
thumbnail
Bruno Farache, modificado 15 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

Liferay Master Postagens: 603 Data de Entrada: 14/05/07 Postagens Recentes
When you call from your portlet you get the same null pointer exception?
thumbnail
cax queiroz, modificado 15 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

New Member Postagens: 19 Data de Entrada: 13/02/07 Postagens Recentes
HI there,

Yeah, checked the ServiceTestSuite class, and the initialisations are there. I've copy to my junit tests. They are working now.

thanks for that.
Todd Story, modificado 14 Anos atrás.

RE: Errors using Document Library API on liferay 5.1.1

New Member Postagens: 2 Data de Entrada: 19/10/09 Postagens Recentes
Bruno Farache:
When you call from your portlet you get the same null pointer exception?


Is this possible in 5.2.3 in a portlet (outside of EXT)? I ask since JCRFactoryUtil is in portal-impl.jar. I figured that there may be a workaround...web services?