Skip Navigation

Access to OSGi Services from Web Apps with JavaScript

Web apps can use a JavaScript function named SrwOsgiApi.callOSGIService to call OSGi services, however, the Java-to-JavaScript bridge (JS bridge) exposes only a subset of OSGi services. These exposed services are referred to as whitelisted services.

The SrwOsgiApi.callOSGIService function is available to use in DefaultWebkitEditor and WebkitView implementations.

OSGi Whitelisted Services

The list of OSGi whitelisted services follows:

        com.sabre.edge.platform.core.sso.base.IAgentProfileService . This access Agent Profile Services.

        com.sabre.edge.platform.core.config.base.IBaseConfigService . This access ConfigService.

        com.sabre.edge.platform.core.logging.ILoggerService . This access Logger Services.

        com.sabre.edge.platform.optional.notifications.INotificationService . This access Notifications Services.

        com.sabre.edge.cf.core.registry.service.ISRWRuntime. This SRWRuntime service grants access to the SRWRuntime communications services.

        com.sabre.edge.cf.core.token.IAuthenticationTokenService. This SRWRuntime service authenticates with the SRWRuntime communications bus.

The process that you use depends upon whether you are accessing OSGi services without communications or accessing communications services through SRWRuntime.

Overview of Accessing SRWRuntime with JavaScript

The JS bridge enables you to register for SRWRuntime communications functionality by using a JavaScript function instead of Java methods. In order to access this communications functionality, you are required to do the following:

  • Include the correct registrations and authorizations in redapp.xml for any channels that you want to access through the JS bridge. In this context, channel refers to SRWRuntime communications, for example, com.sabre.edge.cf.host.service.Communication .

  • Include the communications functionality in your main Red App plug-in. (If you are using other OSGi whitelisted services without communications, you can add this functionality to any plug-in within your Red App bundle, however, it is recommended that you access these services from your main plug-in.)

  • Pass a valid authentication token each time you access any of SRWRuntime communication channels.

Overview of Calling OSGi Non-communications Services

If you are calling OSGi services other than ISRWRuntime, authentication and authorization are not used. Consequently, the implementation of access to these services is more straightforward.

When to Write Java Code to Handle Communications

If none of the above scenarios meet your needs, you must write your own Java code.

With the JS bridge, you can call any whitelisted OSGi service, including SRWRuntime communication channels. However, you cannot register your own service to intercept a communication on the communications bus.

For example, you can send a command through the bus to the host and receive a response, but you cannot listen to what other Red Apps or an agent is sending through the emulator. If you want to add listening, you must provide your own implementation of an editor or a view and write Java code to handle the communications. Your Red App must register a specific Java class as a service to handle the communications.