Using the KMC Platform in Standalone Web Applications

SAP Developer Network

Applies To:

Web Application Server 6.40
Knowledge Management 6.0

Summary

Using the Knowledge Management & Collaboration platform (KMC) in portal related components, e.g. iViews, is possible since SAP Enterprise Portal 5.0. From SAP NetWeaver '04 and forward, more and more custom developments will be done as a standard web application in the SAP Web Application Server Stack. Therefore calling the KMC platform needs to be available for design time in the SAP NetWeaver Developer Studio and at runtime in the NetWeaver Stack.

By Thilo Brandt
NetWeaver RIG Specialist
27 Sep 2004

 

Prerequisites and Relevant Knowledge Management APIs

The following prerequisites must be fulfilled to get started with KMC platform usage in web applications:

  • SAP NetWeaver Developer Studio

  • At least SAP NetWeaver '04 Installation including Web Application Server, Portal and Knowledge Management and Collaboration

  • Customer web application must run on the same Web Application Server

Developers starting to use KMC APIs need an understanding of the concepts described in Repository Framework Concepts (RCO) and advanced knowledge of the J2EE architecture of Web Application Server.

This tutorial describes the implementation of a simple Servlet extending HTTPServlet which uses basic functionality from KM's repository framework. The following Knowledge Management API package is used in the sample implementation:

  • com.sapportals.wcm.repository.*: Contains all basic functionality from KM's repository framework

Project Preparation on SAP NetWeaver Developer Studio

To make the KMC platform called by a standard J2EE implementation, you have to set up a new J2EE component and a new Enterprise application project in the SAP NetWeaver Developer Studio. Adjust the standard configuration settings to your needs.

In addition to the default settings, you have to include the KMC platform libraries for design time. The KMC platform libraries can be found within the IRJ application deployment.

Recommendation: Copy the required Jar files into a separate location on your developer PC and set a variable reference from within the SAP NetWeaver Developer Studio.

After adding the libraries for the design time, you have to set up the references used by the web application during runtime.

Edit the application-j2ee-engine.xml deployment descriptor and add the required reference. The target reference ID for the KMC platform is: com.sap.km.application

The target type must be set to application and the provider name is set to SAP's default: sap.com. Save the project and get started with the implementation.

Coding in Detail

This example shows the implementation of a simple Servlet using a basic function from KM's repository framework.

protected void doGet(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
				

To access KM information objects (resources) you have to create a resource context for which the data is retrieved. A resource context needs to be specified for a certain authenticated user. This user can come from the User Management Engine or can be retrieved from the ServiceUserFactory.

IUser serviceUser = WPUMFactory.getServiceUserFactory().
    getServiceUser("service_user_id");
				
ResourceContext c = new ResourceContext(serviceUser);
				

With a valid resource context object you can retrieve the resource object from KM's repository framework.

IResource r = ResourceFactory.getInstance().
    getResource(RID.getRID("/documents"), c);
				

If you have a valid reference for the resource object, you can access certain information stored on the object and process this information in your web application.

r.getProperties()
				
r.getContext().getUser().getDisplayName()
				

Methods to be implemented:

Method

Purpose

doGet()

At least the doGet() method should be implemented to get a visible response on the UI

Deployment & Running

The deployment of the web application should be done with the SDM or directly out of the SAP NetWeaver Developer Studio.

After deployment you can launch your web application. In this example you can simply call the servlet by executing the following URL:

http://localhost:50000/SimpleEnterpriseApplication/SimpleServlet

Sample Servlet using KMC platform

The following archive contains a valid and deployable SAP NetWeaver Developer Studio project based on KMC API of NW04 SPS 4, which shows the steps described above in a whole example.

Download: SimpleServlet (com.sap.netweaver.kmc_servlet.zip)

Recommended Literature

[RCO] Repository Framework Concepts, SAP AG, 2003, SDN -> Knowledge Management -> KM 6.0 Articles

[NDG] SAP NetWeaver Developer Guide, SAP, 2004, SDN -> Knowledge Management -> QuickLinks -> Knowledge Management and Collaboration Developers' Guide

Table of Contents



Content Options

Copyright © 2005 SAP AG, Inc. All Rights Reserved. SAP, mySAP, mySAP.com, xApps, xApp, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product, service names, trademarks and registered trademarks mentioned are the trademarks of their respective owners.

SAP Developer Network