Configuring JBoss Weld to Run with JavaServer Faces on Google App Engine

By: Derek Berube, Wildstar Technologies, LLC.

This tutorial will provide a step-by-step process one can follow to incorporate the capabilities of the Context and Dependency Injection (JSR-299) framework into a JavaServer Faces application running on the Google App Engine platform. 

The reference application I constructed in the course of writing this tutorial is available from http://weldgae.wildstartech.com/.  The source code is available from the (to be published when tutorial is written) Google Code project.

*** THIS ARTICLE IS CURRENTLY IN A DRAFT STATUS ***

Software Requirements

Required Software

In order to build the sample application and have it run on the Google App Engine platform, you will need to have the following software downloaded and installed locally.

Pre-Configuration Steps

This tutorial is intended to focus on incorporating the CDI frameworks into an existing JavaServer Faces (JSF) application running on the Google App Engine platform.  As such, be sure that you have completed the process outlined in one of the following articles based on which iteration of the JSF specification you are using.
After completing one of the above tutorials, please continue with the process outlined below.

Importing the JBoss Weld Files
The following steps will guide you through the process of importing the files which provide support for the "Contexts and Dependency Injection" API using version 1.0.1 of the reference implementation - JBoss Weld.
  1. In the "Project Explorer" tab, located on the left side of your IDE, expand your project and navigate to and left-click on the WEB-INF/lib directory.



  2. Left-click on the 'File' menu and select the 'Import...' menu item.
  3. When presented with the "Import" dialog, left-click on the 'File System' item under the "General" option.
  4. Left-click on the 'Next' button.
  5. Left-click on the 'Browse...' button and select the folder on your local hard disk drive into which you uncompressed the files found in the weld-1.0.1-Final.zip archive you downloaded from the "Weld Distribution Downloads" page.  When you have selected the directory, left-click on the 'Open' button.
  6. Left-click on the arrow appearing to the left of the weld-1.0.1-Final folder.
  7. Left-click on the arrow appearing to the left of the artifacts folder.
  8. Left-click on the cdi folder.
  9. Place a check mark beside the cdi-api.jar file as shown in the figure below.



  10. Left-click on the weld folder.
  11. Place check marks beside the weld-api.jarweld-core.jar, and weld-servlet.jar files as shown in the figure below.



  12. Left-click on the 'Finish' button to complete the process of importing the files.
  13. You will see that you now have an artifacts folder in your WEB-INF/lib folder.



  14. Expand the artifacts folder.
  15. Expand the cdi folder.
  16. Left-click on the cdi-api.jar file and drag it up and drop it onto the lib folder.
  17. Expand the weld folder.
  18. Select the weld-api.jarweld-core.jar, and weld-servlet.jar files and drag them up an drop them onto the lib folder.
  19. Steps 14 through 18 will move the JBoss Weld libraries out of their sub-folders and into the WEB-INF/lib directory.
  20. Right-click on the artifacts folder to display the pop-up menu for the folder.


  21. Left-click on the 'Delete' menu option.
  22. When presented with the "Confirm Delete" dialog, simply left-click on the 'OK' button.


  23. After completing the process outlined above, the WEB-INF/lib folder in your web application should look similar to what is shown in the figure below.

Configuration File Changes

web.xml

Edit the web.xml file found in the WEB-INF directory of the project and add org.jboss.weld.environment.servlet.Listener class implements the ServletContextListenerServletRequestListener, and HttpSessionListener interfaces as a listener.

<!-- JBoss Weld 1.0.1 Compatibility -->

<listener>

   <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>

</listener>


Known Issues

WELD-001303 No active contexts for scope type @ConversationScoped

When sendRedirect() is used inside of a JSP page, it results in the exception "WELD-001303: No active contexts for scope type @ConversationScoped" and the following stack trace.


org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type @ConversationScoped
at org.jboss.weld.conversation.ConversationImpl.checkConversationActive(ConversationImpl.java:79)
at org.jboss.weld.conversation.ConversationImpl.isTransient(ConversationImpl.java:234)
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:597)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
at org.jboss.weld.conversation.ConversationImpl_$$_javassist_2.isTransient(ConversationImpl_$$_javassist_2.java)
at org.jboss.weld.conversation.AbstractConversationManager.cleanupConversation(AbstractConversationManager.java:148)
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:597)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
at org.jboss.weld.conversation.ServletConversationManager_$$_javassist_0.cleanupConversation(ServletConversationManager_$$_javassist_0.java)
at org.jboss.weld.jsf.WeldPhaseListener.afterRenderResponse(WeldPhaseListener.java:131)
at org.jboss.weld.jsf.WeldPhaseListener.afterPhase(WeldPhaseListener.java:103)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:51)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)



Copyright © 2010, Wildstar Technologies, LLC.
Comments