Start of Content Area

Component documentation User Agent Service  Locate the document in its SAP Library structure

Purpose

A user agent is an application which is used to browse through the World Wide Web. Web user agents can be web browsers and search engine spiders as well as accessibility products like screen readers and braille browsers.

The user agent provides information about itself, when a web site is accessed. The information contains the brand and version of the browser and the operating system the browser is running on.

Example

User agent

Internet Explorer 5.5 running on MS Windows 2000

Provided information

Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0).

 

How to get the User Agent

Necessary SharingReference Entry in Deployment Descriptor

To use the user agent service you have to add a sharing reference entry to the deployment descriptor (file portalapp.xml) in the section <application-config>.

The entry has following format:

<application-config>

  <property name="SharingReference" value="com.sap.portal.useragent"/>

.

</application-config>

 

Note

When you use another service or services in the portal application, you separate the services by a comma.

Example

value="htmlb,com.sap.portal.useragent"

 

Get the Useragent Service

The entry point of the user agent service is the interface IUserAgentService. You get this interface from the Portal Runtime (PRT) with following command:

    IUserAgentService userAgentService =
        (IUserAgentService) PortalRuntime
            .getRuntimeResources()
            .getService(
            
"com.sap.portal.useragent.useragent");

 

Get the User Agent

To get the user agent, you have to get the user agent name first. With the user agent name and the user agent service you get the user agent from the HttpServletRequest object. You can use the following commands:

    HttpServletRequest sRequest = request.getServletRequest();
    String userAgentName = sRequest.getHeader(
"User-Agent");
    
//   Using this information you can use the method getUserAgent() of 
    //   IUserAgentService to get the user agent object of type IUserAgent:
    
IUserAgent userAgent =
        userAgentService.getUserAgent(sRequest.getHeader(userAgentName));

For more details about the usage of the userAgent methods refer to the PDK.

 

Get the User Agent Family

The user agent service also provides information about the user agent family with interface IUserAgentService. This interface provides the method getUserAgentFamily() that delivers the information. You get this interface with the following commands:

    IUserAgentFamily userAgentFamily =
                     userAgentService.getUserAgentFamily();
/*  From this object you get an enumeration of all user agent sets of
    type IUserAgentSet that matches the IUserAgent: object:   */
    
Enumeration enum = userAgentFamily.findUserAgentSets(userAgent);

 

End of Content Area