Skip to Content

Creating a Portal navigation viewer with SAP NetWeaver and Google Web Toolkit (GWT) – Part IV


Part I – Introduction and motivation, presentation of the application
Part II – Creation of the J2EE project in SAP NetWeaver, adding GWT to the project
Part III – Creation of an EAR, deployment, creating a Portal IView
Part IV – Adding backend functionality, getting the current portal user
Part V – Adding AJAX user search


The first three parts of this series described only the fundament of a GWT Portal application, basically a summary of different blog, forum and article posts I found in SDN.

Now onto something more interesting:

How can a GWT application access the j2ee backend in the context of the user (IUser) currently logged in?

First, I want to show how to establish a communication channel between the GWT frontend and the j2ee backend.

GWT communicating with a J2EE servlet 

First we need to create the j2ee servlet our GWT application will be communicating with:

  1. Create two new packages:
    • de.bds.portal.pcdbrowser.server
    • de.bds.portal.pcdbrowser.server.pcd

    create server package

  2. Create the servlet named “PcdBrowserServlet” using SAP NetWeavers default settings:
    create a new servlet
    give the servlet the name PcdBrowserServlet
  3. Now we need to make this servlet visible to GWT. To achieve this, we need to define a servlet mapping for our new servlet in web.xml.
    add a servlet mapping

Actually getting the current user 

Next we include our own code. I’ve prepared the necessary files – you know this already from part II.

Add the following files:

Replace the following files:

In order to access portals user management, we need the files and in our servlets classpath. These files are part of the portal and/or Netweaver Developer Studio installation. If you can’t find them, you may try out class locator – an open source tool I consider invaluable for portal development.add usermanagementapi.jar to classpath

Now perform the deployment cycle described in chapter III (PcdBrowser-compile.cmd -> Build WEB Archive -> Build Application Archive -> Deploy to J2EE engine). Afterwards, you can call the IView you created in chapter III and should see a screen similar to this one:
call pcd browser in portal

As you can see, the GWT application periodically requests data from the backend. Therefore, it can take up to ten seconds until you receive the first status line.

The most interesting part in the backend application is the part, where the portal user is determined:

public String getReport(HttpServletRequest req, HttpServletResponse resp) {
    IUser user = UMFactory.getAuthenticator().getLoggedInUser(req, resp);

So we need the HttpServletRequest and HttpServletResponse of a request in order to get the current portal user from UMFactory. Thankfully, GWT offers a possibility to retrieve these from the current thread by calling RemoteServiceServlet.getThreadLocalRequest() and RemoteServiceServlet.getThreadLocalResponse().

Tobias Braun, Burda Digital Systems GmbH, Offenburg, Germany
BDS Logo

You must be Logged on to comment or reply to a post.