Skip to Content

First some background. People attending some of the standard SAP training courses related to portal (EP*) and administration (ADM*) often end up using SAP solutions that allow for email integration. For example, in the EP200 course we setup the UME (user management engine) so that new user creations cause an email to be sent to the new user telling them their logon details.

Currently we use an email server from ArgoSoft. The free version works well, but has a few limitations, such as the web interface comes with ads and it doesn’t easily run as a Windows service.

Looking around I found the Apache Software Foundation’s james Project, which seems to have what I needed. It’s easy to install and can run as a Windows service. Now I just needed to work out how to populate its user base. Because different training courses have different usernames for the students, I didn’t want to hardcode all the users.

While the mail server can hold its users in different locations, such as a database, I chose the default, which is at the file system. This is not the most efficient, but is suitable for a small (<200) number of users. Technically there is one file per user in a specific folder (apps\james\var\users). The name is a hex encoded version of the username plus .Repository.FileObjectStore. So, user FRED would be stored as file 46524544.Repository.FileObjectStore. The contents of the file are a couple of Serializable objects supplied with the server called DefaultJamesUser and JamesUser. Instantiating these objects creates the appropriate structures and handles password setting etc.

While the mail server comes with a telnet utility that allows for user creation, I found that this wasn’t an easy mechanism for accessing through Java code and libraries. So, I decided to write a Java application to allow for the user populating. To do this I had to decide whether to use a portal component or bite the bullet and learn Web Dynpro for Java (WDJ).

As I wanted to be able to run the application even if a portal wasn’t installed on the AS Java, I needed to use WDJ, but here are a few things that you should take into consideration.

Writing a portal component is fairly straight forward. Launch the NetWeaver Developer Studio (NWDS), create a portal project and then create a new portal application. The simplest type is based on AbstractPortalComponent. To write your HTML response to the browser is quite simple – the response.write(String) method writes the nominated text.

For example:


Hello there!


would generate a header with the text “Hello there!”

Web Dynpro for Java is quite different, due to its use of the MVC (Model, View, Component) paradigm. In practical terms you need to know what you want to write out and specify this as a view, keeping this part completely separate from the code to generate the content. So, the simple “Hello there!” becomes a View with a TextView object. The contents of the TextView itself can be set from the Java implementation, removing the need to hardcode the text value. This allows for some changes under program control. For example you could look up the logged on user’s username and return their first name and change the text of the TextView to say “Hello there, Michael!”.

Tables in Web Dynpro for Java are a lot more powerful than the HTMLB equivalent and populating the contents is quite simple. It is based on the concept of a repeating node in the view’s context and I became quite comfortable using them after a little playing round and understanding the general methods for their manipulation.

As an example, I needed to be able to launch operating system commands to start and stop the mail server. To this end I wrote a WDJ Application that took a parameter of a Windows command and returned the output as lines of a table. The context looks like:

   Value node: results
         Value attribute: line

At run time, I execute the nominated command using:

String[] cmd = new String[3];
cmd[0] = “cmd.exe”;
cmd[1] = “/C”;
cmd[2] = command;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream()));
String line=null;
while((line=in.readLine() )!=null) {
   IResultsElement results = wdContext.nodeResults().createResultsElement();

My next issue was how to handle the mail contents. WDJ doesn’t seem to have a simple way to display HTML code and I didn’t want to do my own parsing to make more TextView elements. I ended up with a table display in WDJ that lists the mail inbox with date, sender, subject etc. Selecting a line sets the URL value for an IFRAME element. This URL starts a simple Web app that returns the HTML version of the mail contents.





To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply