Mavenized Liferay Portlet 2.0 using Spring

Hello all,

I have no idea if anyone else has ever encountered an issue such as this one, but it has me baffled.

In short: a ‘getContext’ within my init() method in my portlet-application class returns an object of type ‘WebApplicationContext’ instead of the expected PortletApplicationContext2

A relevant code snippet from my application class:


import com.vaadin.terminal.gwt.server.PortletApplicationContext2;
import com.vaadin.terminal.gwt.server.PortletApplicationContext2.PortletListener;

public class Dante extends Application implements PortletListener {
public void init() {
		log.debug("init() called");
		... // non relevant code

		log.debug("getContext().getClass().getSimpleName() = " + getContext().getClass().getSimpleName());

		if (getContext() instanceof PortletApplicationContext2) {
			PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();

			// Add a custom listener to handle action and
			// render requests.
			ctx.addPortletListener(this, this);
		} else {
			getMainWindow().showNotification(
					"Not initialized via Portal! - context not of type PortletApplicationContext2",
					Notification.TYPE_ERROR_MESSAGE);
		}
	}
}

Console output when starting my server & loading my app:


9-nov-2011 12:20:00 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\liferay-portal-6.0.6\tomcat-6.0.29\jre1.6.0_20\win\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Java\apache-maven-3.0.1\bin;C:\Java\apache-ant-1.8.2\bin;C:\Java\jdk1.6.0_23\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin
9-nov-2011 12:20:00 org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080
9-nov-2011 12:20:00 org.apache.catalina.startup.Catalina load INFO: Initialization processed in 329 ms
9-nov-2011 12:20:00 org.apache.catalina.core.StandardService start INFO: Starting service Catalina
9-nov-2011 12:20:00 org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
9-nov-2011 12:20:00 org.apache.catalina.startup.HostConfig deployDescriptor INFO: Deploying configuration descriptor ROOT.xml Loading jar:file:/C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
12:20:02,020 INFO  [ConfigurationLoader:56]
 Properties for jar:file:/C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal loaded from [jar:file:/C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties]
 Loading jar:file:/C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
12:20:06,814 INFO  [DialectDetector:69]
 Determining dialect for HSQL Database Engine 1
12:20:06,816 WARN  [DialectDetector:84]
 Liferay is configured to use Hypersonic as its database. Do NOT use Hypersonic in production. Hypersonic is an embedded database useful for development and demo'ing purposes. The database settings can be changed in portal.properties.
12:20:06,883 INFO  [DialectDetector:49]
 Using dialect org.hibernate.dialect.HSQLDialect
12:20:09,716 INFO  [PortalImpl:278]
 Global lib directory /C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/lib/ext/
12:20:09,719 INFO  [PortalImpl:298]
 Portal lib directory /C:/Java/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/ Starting Liferay Portal Community Edition 6.0.6 CE (Bunyan / Build 6006 / February 17, 2011)
12:20:23,061 INFO  [BaseDB:400]
 Database supports case sensitive queries
12:20:27,394 INFO  [PluginPackageUtil:1109]
 Reloading repositories
12:20:31,108 INFO  [HotDeployUtil:69]
 Initializing hot deploy manager 24853345
12:20:31,358 INFO  [AutoDeployDir:105]
 Auto deploy scanner started for C:\Java\liferay-portal-6.0.6\deploy
9-nov-2011 12:20:31 org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory Dante-web
12:20:33,158 INFO  [PortletHotDeployListener:220]
 Registering portlets for Dante-web
12:20:33,231 INFO  [PortletHotDeployListener:369]
 1 portlet for Dante-web is available for use
9-nov-2011 12:20:33 org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8080
9-nov-2011 12:20:33 org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009
9-nov-2011 12:20:33 org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/16  config=null
9-nov-2011 12:20:33 org.apache.catalina.startup.Catalina start INFO: Server startup in 32614 ms
2011-11-09 12:21:10,825 [http-8080-2]
 DEBUG nl.ou.dante.ui.Dante - init() called
2011-11-09 12:21:10,955 [http-8080-2]
 DEBUG nl.ou.dante.ui.Dante - getContext().getClass().getSimple
Name() = [b]
[color=#ff0808]
WebApplicationContext
[/color]
[/b]

As you can see at the bottom: WebApplicationContext.
And loading the portlet shows me the ErrorNotification-window.

There is one other thing that might be worth mentioning: I’m using Maven to handle my dependencies & my building.

Other information regarding the project build up can be provided on request or you could click and check
this

So anyone care to give me any insights? Thoughts? Comments?

thanks in advance for any and all feedback!

Pieter

I have found a workaround for this problem.

Stop the server
clean the following folders of your app-specific entries:
…\liferay-portal-6.0.6\tomcat-6.0.29\webapps
…\liferay-portal-6.0.6\tomcat-6.0.29\temp
…\liferay-portal-6.0.6\tomcat-6.0.29\work\Catalina\localhost\

Place your war in the deploy folder

restart server.

Though I must admit this is a really ugly way of testing & redeploying…

Hi, I am also trying to develop a Vaadin portlet in liferay and using Spring for dependency injection.
I am facing issues with it. Can you please help me by sending your sample source code like web.xml , spring-application.xml etc and few Vaadin
application classes.
I am getting below error. I have configured RequestContextFilter in my web.xml but I am not sure why I am getting this error still.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘memberGeneric’ defined in file [C:\liferay-portal-tomcat-6.1.0-ce-_05_09\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps\VaadinProject-portlet\WEB-INF\classes\com\magellanhealth\memberinfo\MemberGeneric.class]
: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.magellanhealth.memberinfo.MemberGeneric]
: Constructor threw exception; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.