Message Boards

LifeRay 7.3 wont allow calling getUser() method

Mike Bigelow, modified 4 Years ago.

LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
This crashes on the getUser() call when I put it into either .java or .jsp , why? I have this code working in LifeRay 6.1 and LifeRay 7.0, but I cannot get it to work in the latest 7.3:
ThemeDisplay td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); <-- works fine
        User tduser = td.getUser(); <-- any usage of getUser() crashes the module to a STOPPED state
thumbnail
Christoph Rabel, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
What exception do you see in the logfiles? Is the Themedisplay really available (I mean, did you check if td != null?).
That an exception in a jsp should be able to disable a module baffles me.
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
I'm not seeing anything reach the log. Just my Eclipse shows the module STOPPED and doesn't start until I remove the getUser() call.
2020-04-20 18:12:05.721 INFO  [pipe-stop 1150][BundleStartStopLogger:49] STOPPED MIR3
I know td works because all the td methods that aren't getUser() work correctly for example: String item = td.getURLCurrent(); <-- working
I also tried a new Module with just a call to td.getUser() and this breaks it. It's like LifeRay 7.3 won't allow it, I have the same lines of code running on the 7.0 server 6.1 servers fine.
Can you get the td.getUser() to work under 7.3 module?
thumbnail
Christoph Rabel, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Wait a second.
Does it crash or does it stay in STOPPED state when you deploy it?
I guess, you are missing a dependency. What does the gogo shell say? Have you tried "diag <bundleId>"?
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
STOPPED state, diag says:Unresolved requirement: Import-Package: com.liferay.portal.kernel.model; version="[4.1.0,5.0.0)
I've tried changing the version of the dependency, but no change:        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>com.liferay.portal.kernel</artifactId>
            <version>5.4.0</version>
            <scope>provided</scope>
        </dependency>
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
I'm not sure how to get this import-package into the manifest.mf, if I add it manually it just gets removed on redeploy.
If I put an Import-Package: com.liferay.portal.kernel.model on the bnd.bnd it just stops the rebuild.Do I have to go get some .jar file to include the model manually? Not understanding how this can't already be there.
thumbnail
Christoph Rabel, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Ok, from somewhere the OSGI runtime believes that com.liferay.portal.kernel.model; version="[4.1.0,5.0.0) is a necessary dependency. Probably this is an issue in one of the dependencies of the artifacts you have in the pom.xml.
You could try to enforce that the package is not required by adapting the bnd file. Something along:
Import-Package: !com.liferay.portal.kernel.model; version="[4.1.0,5.0.0), *
I am not sure if that works, if it complains later on (e.g. ClassNotFound), you may also need to add the model again in the correct version, e.g.:
Import-Package: !com.liferay.portal.kernel.model; version="[4.1.0,5.0.0), com.liferay.portal.kernel.model; version="[5.0.0,6.0.0), *
Again, I am not sure if this works.

In gradle you could try this in build.gradle:
implementation enforcedPlatform(group: 'com.liferay.portal', name: 'com.liferay.portal.kernel', version: '5.4.0')
instead of compileOnly ...
But I have no idea how that could be done in maven.
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
The first import package throws a new error:java.lang.NoClassDefFoundError: com/liferay/portal/kernel/portlet/bridges/mvc/MVCPortlet
The second import package says:IllegalArgumentException: Invalid filter directive
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
I've further found from the view.jsp I can call:mylog.info(themeDisplay.getUser().getComments());
But if I want to import the "User" class and assign themeDisplay.getUser() to a User variable than it crashes.
Without the import it doesn't know what User class is.Perhaps some issue with double loading going on once it hits the server deployment?
Mike Bigelow, modified 4 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
I found the fix for .jsp, but still not in the .java:In the .jsp there seem to already be global variables defined "themeDisplay" and "user". If I use these then everything is fine.Must be an issue trying to grab them again.However, I can't find these same globals on the .java side
Alberto Fernandez, modified 3 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 16 Join Date: 9/29/10 Recent Posts
Hi Mike, I have the same problem. How did you solve it in java
thumbnail
Olaf Kock, modified 3 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
I only see this thread now.
The only explanation that I'd have for a module to be STOPPED upon a simple call is if that call happens during a module's initialization - e.g. in @Activate. During runtime, it shouldn't make a difference to the state of the bundle.
Can you provide code (preferably a minimal version) that demonstrates what you observe? Where does the code live that causes this behavior?
Alberto Fernandez, modified 3 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 16 Join Date: 9/29/10 Recent Posts
Hi Olaf,My code in doView() method:
        ThemeDisplay td = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
        String userScreenName = td.getUser().getScreenName();

When the td.getUser () method is executed, these traces are obtained in the application log:

020-10-21 14:54:01.263 INFO  [http-nio-8080-exec-2][SeguimientoAmaPortlet:50] doview
2020-10-21 14:54:10.529 ERROR [http-nio-8080-exec-2][FragmentRendererControllerImpl:120] Unable to render content of fragment entry 0:com.liferay.fragment.exception.FragmentEntryContentException: com.liferay.portal.kernel.portlet.PortletContainerException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/liferay/portal/kernel/model/User
2020-10-21 14:54:10.757 ERROR [liferay/monitoring-3][ParallelDestination:59] Unable to process message {destinationName=liferay/monitoring, response=null, responseDestinationName=null, responseId=null, payload=[{displayName=SeguimientoAma, portletId=seguimiento_ama_SeguimientoAmaPortlet_INSTANCE_ewhp, requestType=RENDER, {attributes=null, companyId=37401, groupId=38402, description=null, duration=0, name=seguimiento_ama_SeguimientoAmaPortlet, namespace=com.liferay.monitoring.Portlet, requestStatus=null, stopWatch=0:00:09.484, timeout=0, user=37435}}, {displayName=Product Menu, portletId=com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet, requestType=RENDER, {attributes=null, companyId=37401, groupId=38402, description=null, duration=67, name=com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet, namespace=com.liferay.monitoring.Portlet, requestStatus=SUCCESS, stopWatch=0:00:00.067, timeout=0, user=37435}}, {displayName=Search Bar, portletId=com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet_INSTANCE_templateSearch, requestType=RENDER, {attributes=null, companyId=37401, groupId=38402, description=null, duration=2, name=com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet, namespace=com.liferay.monitoring.Portlet, requestStatus=SUCCESS, stopWatch=0:00:00.002, timeout=0, user=37435}}, {displayName=User Personal Bar, portletId=com_liferay_product_navigation_user_personal_bar_web_portlet_ProductNavigationUserPersonalBarPortlet, requestType=RENDER, {attributes=null, companyId=37401, groupId=38402, description=null, duration=3, name=com_liferay_product_navigation_user_personal_bar_web_portlet_ProductNavigationUserPersonalBarPortlet, namespace=com.liferay.monitoring.Portlet, requestStatus=SUCCESS, stopWatch=0:00:00.003, timeout=0, user=37435}}, {displayName=Navigation, portletId=com_liferay_site_navigation_menu_web_portlet_SiteNavigationMenuPortlet, requestType=RENDER, {attributes=null, companyId=37401, groupId=38402, description=null, duration=4, name=com_liferay_site_navigation_menu_web_portlet_SiteNavigationMenuPortlet, namespace=com.liferay.monitoring.Portlet, requestStatus=SUCCESS, stopWatch=0:00:00.004, timeout=0, user=37435}}, {referer=null, remoteAddr=127.0.0.1, requestURL=http://localhost:8080/c/portal/layout.jsp_display, statusCode=200, userAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36, {attributes=null, companyId=37401, groupId=38402, description=Portal Request, duration=200, name=/c/portal/layout, namespace=com.liferay.monitoring.Portal, requestStatus=SUCCESS, stopWatch=0:00:00.200, timeout=-1, user=37435}}, {referer=null, remoteAddr=127.0.0.1, requestURL=, statusCode=200, userAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36, {attributes=null, companyId=37401, groupId=38402, description=null, duration=9500, name=/c/portal/layout, namespace=com.liferay.monitoring.Portal, requestStatus=SUCCESS, stopWatch=0:00:09.500, timeout=-1, user=37435}}, {referer=null, remoteAddr=127.0.0.1, requestURL=, statusCode=200, userAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36, {attributes=null, companyId=37401, groupId=38402, description=null, duration=9504, name=/group/seguimiento/home, namespace=com.liferay.monitoring.Portal, requestStatus=SUCCESS, stopWatch=0:00:09.504, timeout=-1, user=null}}], values={defaultLocale=es_ES, companyId=37401, groupId=0, principalName=37435, permissionChecker=com.liferay.portal.kernel.util.TransientValue@3b4fe16d, siteDefaultLocale=es_ES, themeDisplayLocale=es_ES}}
com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.NullPointerException
    at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:41)
    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:74)
    at com.liferay.portal.messaging.internal.ParallelDestination$1.run(ParallelDestination.java:56)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.liferay.portal.monitoring.internal.statistics.portlet.PortletStatistics.processDataSample(PortletStatistics.java:112)
    at com.liferay.portal.monitoring.internal.statistics.portlet.CompanyStatistics.processDataSample(CompanyStatistics.java:209)
    at com.liferay.portal.monitoring.internal.statistics.portlet.ServerStatistics.processDataSample(ServerStatistics.java:118)
    at com.liferay.portal.monitoring.internal.statistics.portlet.ServerStatistics.processDataSample(ServerStatistics.java:35)
    at com.liferay.portal.monitoring.internal.messaging.MonitoringMessageListener.processDataSample(MonitoringMessageListener.java:93)
    at com.liferay.portal.monitoring.internal.messaging.MonitoringMessageListener.doReceive(MonitoringMessageListener.java:121)
    at com.liferay.portal.kernel.messaging.BaseMessageListener.doReceive(BaseMessageListener.java:48)
    at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:34)
    ... 5 more
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Liferay 7.3 wont allow calling getUser() method

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Alberto Fernandez:

Hi Olaf,My code in doView() method:
        ThemeDisplay td = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
        String userScreenName = td.getUser().getScreenName();


That's a bit too minimal (i.e. not enough to reproduce, that'd require a full project), but with a bit of digging, at least the log gives some hints:

Alberto Fernandez:

When the td.getUser () method is executed, these traces are obtained in the application log:

020-10-21 14:54:01.263 INFO  [http-nio-8080-exec-2][SeguimientoAmaPortlet:50] doview
2020-10-21 14:54:10.529 ERROR [http-nio-8080-exec-2][FragmentRendererControllerImpl:120] Unable to render content of fragment entry 0:com.liferay.fragment.exception.FragmentEntryContentException: com.liferay.portal.kernel.portlet.PortletContainerException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/liferay/portal/kernel/model/User
2020-10-21 14:54:10.757 ERROR [liferay/monitoring-3][ParallelDestination:59] Unable to process message....


I'm not sure if the next message (about monitoring/message processing) belongs to the investigated issue, i.e. if it is a follow-up problem or unrelated.
If the User class can't be found, there's something wrong with the OSGi wiring of your portlet - and I'm wondering why it deploys at all: Technically the Manifest should contain the dependencies, and if they're not met, your portlet won't be deployed. But if this runtime problem pops up, it obviously is deployed and started.
How do you deploy your portlet? What are the buildfiles and dependencies like? Can you provide a (minimal) fully building plugin that exhibits this behavior?
Mike Bigelow, modified 3 Years ago.

RE: Liferay 7.3 wont allow calling getUser() method

New Member Posts: 8 Join Date: 4/7/20 Recent Posts
<p>Hi Alberto,</p>

<p>Like I stated above: In the .jsp there seem to already be global variables defined &quot;<strong>themeDisplay</strong>&quot; and &quot;<strong>user</strong>&quot;</p>

<p>So, switch your code out of the .java and move it into the .jsp</p>

<p>That&#39;s how I solved it, by eliminating it from the .java, as no solution ever was presented.</p>

<p>If needed, you can pass it from the .jsp to the .java by a variable. But, I found once I moved it to .jsp side I no longer required the .java area code.</p>
Diego valencia, modified 3 Years ago.

RE: LifeRay 7.3 wont allow calling getUser() method

New Member Posts: 2 Join Date: 12/29/19 Recent Posts

I have the same problem

only when I make use of display variable to use getuser.get screenname does the error appear.
Problem with deploying bundle: gogo: BundleException: Could not resolve module: co.dnube.portlet.company [1365]
  Unresolved requirement: Import-Package: com.liferay.portal.kernel.model; version = "[4.1.0,5.0.0)"