Using with Google Appengine

From DaamWiki

Jump to: navigation, search

Althought the most important feature of Daam as compared to other Direct Ajax framework is that it is integrated into the EJB container, you might also use it in a simple web container. Version 1.0.3 contains important changes that makes it able to run in the Google Appengine environment.

When running in a standard web container, you can have only one "component" which will serve as the main application class. It is instantiated for a http session and managed by the DaamServlet. Other lightweight IoC container integrations will be implemented in a future release. Now, you have to define the main application class in the web.xml, and you have to define "daam.DaamServletGae" as the servlet class:

    <servlet>
        <servlet-name>daamservlet</servlet-name>
        <servlet-class>daam.DaamServletGae</servlet-class>
        <init-param>
            <param-name>applicationClass</param-name>
            <param-value>demo.Application</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>daamservlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

The other important difference from the normal Seam integrated use is that your application class won't be an EJB, so the initialization code has to go to the constructor, not the PostConstruct method.

You can put the daam.jar to the WEB-INF/lib directory of your Appengine project, it will be uploaded to the server when you deploy your applicaiton.

If you wish to force users to login using their Google account, you might extend the servlet class:

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        try {
            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();

            if (user != null) {
                super.service(req, resp);
            } else {
                resp.sendRedirect(userService.createLoginURL(req
                        .getRequestURI()));
            }
        } catch (Exception e) {
                   [...]
        }
    }

That's all.