Show TOC

Component documentationUser Agent Service Locate this document in the navigation structure

 

User agents are applications, which are used to browse the Web, such as Web browsers, search engine spiders, as well as accessibility tools, such as screen readers and Braille browsers.

When a browser connects to a server, it passes the information regarding the brand and version of the browser, and the operating system in which the browser is running, in the User-Agent field contained in the HTTP Request header. For example, Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; ).

You can use the User Agent service of the Portal Runtime to access the user agent information, as described below.

Dependencies

To use the User Agent Service, add a sharing reference entry to the deployment descriptor (file portalapp.xml) in the <application-config> section.

Syntax Syntax

  1. <application-config>
    <property name="SharingReference" value="com.sap.portal.useragent"/>
    </application-config>
    
End of the code.
Obtaining a User Agent Service

Obtain a reference to the IUserAgentService interface, as follows:

Syntax Syntax

  1. IUserAgentService userAgentService =(IUserAgentService) PortalRuntime.getRuntimeResources().getService("com.sap.portal.useragent.useragent");
End of the code.
Obtaining a User Agent Object

Obtain a user agent object from the HttpServletRequest object, as follows:

Syntax Syntax

  1. HttpServletRequest sRequest = request.getServletRequest();
    String userAgentName = sRequest.getHeader("User-Agent");
    //With this information call getUserAgent( to get the user agent object of type IUserAgent:
    IUserAgent userAgent =userAgentService.getUserAgent(sRequest.getHeader(userAgentName));
End of the code.
Obtaining the User Agent Family

Obtain the user agent family information by calling the getUserAgentFamily() method, as follows:

Syntax Syntax

  1. 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 the code.

More Information

For more information about the IUserAgentService methods, refer to the Enterprise Portal Javadocs at http://help.sap.com/javadocs.