Show TOC

Procedure documentationStep 1: Creating a Content Provider Service Locate this document in the navigation structure

 

The content provider service represents the third-party content provider. This service is responsible for initializing the connection to the provider, defining authentication parameters, and creating provider entities.

All content provider services implement IContentProviderService. The content provider framework includes an AbstractContentProviderService class, which implements all required methods except for getProviderEntity(), which you must implement.

In the following procedure, the variable context is the generic IServiceContext object for the current service.

Procedure

  1. Create a new class that extends AbstractContentProviderService.

  2. If necessary, override the provider service's init() method in order to handle such tasks as initializing authentication, checking the connection or loading a license.

    For example, the following creates a new HTTP authentication manager and stores it in a local variable in the service class. The authentication manager is then available to be assigned to the entity created in the getProviderEntity() method.

    Syntax Syntax

    1. super.init(context);
      mm_authManger = new myCPAuthenticationManager(context);   
      
    End of the code.

    For more information on authentication managers, see Creating an Authentication Manager.

  3. Implement the getProviderEntity() method, which serves as a factory for all entity objects for this content provider.

    In this method, do the following:

    • Create an IDataHandler object with the help of the content provider utility service, which you can obtain from the getUtilsService() method of the AbstractContentProviderService class.

      Syntax Syntax

      1. IDataHandler dataHandler = getUtilsService().createDataHandler(
            request, context);
        
      End of the code.
    • Obtain (or, if necessary, create) the appropriate entity based on the ProviderEntityType parameter passed into the method.

      In the following implementation, an instance of myCPSearchEntity is created if the entity type is SEARCH. Otherwise, an instance of myCPEntity is created. (myCPEntity can be the implementation for different entities because, with the same getSourceURL() method, it can return different URL strings based on the entity type).

      Syntax Syntax

      1. myCPEntity res = null;
        if(providerEntityType.equals(ProviderEntityType.SEARCH))
        {
           res = new myCPSearchEntity(m_context,dataHandler);
        }
        else if(providerEntityType.equals(ProviderEntityType.STORY)
           || providerEntityType.equals(ProviderEntityType.COMPANY)
           || providerEntityType.equals(ProviderEntityType.HEADLINE)
           || providerEntityType.getValue().equals(IConstants.STOCK_ENTITY_KEY)
           || providerEntityType.getValue().equals(IConstants.CHARTS_ENTITY_KEY)
           || providerEntityType.getValue().equals(IConstants.FINANCE_ENTITY_KEY)
           || providerEntityType.getValue().equals(IConstants.WEATHER_ENTITY_KEY)
           || providerEntityType.getValue().equals(IConstants.FORECAST_ENTITY_KEY))
        {
           res = new myCPEntity(providerEntityType,m_context,dataHandler);            
        }       
        
        if(res == null)
        {
           throw new ContentProviderException("Cannot 
              create provider entity: "+providerEntityType);
        }
        
      End of the code.
    • Create a default properties handler and make this object the properties handler for the entity.

      Syntax Syntax

      1. IContextWrapper myCPContextHandler =   getUtilsService().createContextWrapper(context);
        
        ISourcePropertiesHandler propsHndlr =                       getUtilsService().createSourcePropertiesHandler(
                    request,dataHandler,myCPContextHandler);
        
        res.setSourcePropertiesHandler(propsHndlr);
        
      End of the code.
    • For HTTP connectivity, set the authentication manager for the entity to the service's authentication manager. You should initialize the authentication manager in the provider service's init() method.

      Syntax Syntax

      1. res.setHTTPAuthenticatorManager(mm_authManger);
      End of the code.
    • For SOAP connectivity, set the message processor for the entity. For more information on creating a SOAP message processor, see Creating a SOAP Message Processor.

      Syntax Syntax

      1. res.setMessageProcessor( new MyMessageProcessor());
      End of the code.
    • Call the entity's doInit() method, and then return the entity.

      Syntax Syntax

      1. res.doInit(request);    
        return res;
        
      End of the code.
  4. Create a service entry in portalapp.xml for the provider service, similar to the one shown below:

    Syntax Syntax

    1. <service name="ContentProvider">
        <service-config>
          <property name="className" value="com.sap.portal.myCP.myCPService"/>
          <property name="startup" value="false"/>
          <property name="SafetyLevel" value="high_safety"/>
        </service-config>
        <service-profile>
          <property name="com.sap.portal.cp.PROVIDER_SITE"
                          value="http://www.myCP.com"/>
          <property name="com.sap.portal.cp.PROVIDER_ICON"
                          value="http://www.myCP.com/logobar.gif"/>
          <property name="com.sap.portal.cp.PROVIDER_VERSION" value="1.0"/>
          <property name="com.sap.portal.cp.PROVIDER_NAME" value="myCP"/>
          <property name="com.sap.portal.cp.BASE_URL" value="http://myCP.com/api"/>
        </service-profile>
      </service>
      
    End of the code.

    The <service> element for the content provider service is similar to the <service> element for any service. It defines the name of the service in the element's name attribute.

    In the <service> element, add a <service-config> element, as you would for any service. In this element, add the following property elements:

    • className: The name of your class that implements the provider service.

    • startup: Set to false, indicating not to start this service at portal startup.

    • SafetyLevel: Set to high_safety. This is the service's security zone safety level.

    In the <service> element, also add a <service-profile> element, as you would for any service. In this section, add the following property elements:

    • Information about the content provider service, as defined in the IProviderDetails interface:

      • com.sap.portal.cp.PROVIDER_SITE: The main web site of the content provider

      • com.sap.portal.cp.PROVIDER_ICON: The URL of the content provider's logo

      • com.sap.portal.cp.PROVIDER_VERSION: The version of the content provider

      • com.sap.portal.cp.PROVIDER_NAME: The name of the content provider

      The default implementation of the content provider framework currently does not make use of these properties, and you are not required to supply them in portalapp.xml.

    • com.sap.portal.cp.BASE_URL: The base address for all XML sources for this content provider. You do not need to use this address; however, the default implementation loads this value into the entity's m_baseUrl field during initialization.

    • Any other properties that the content provider needs, for example, a default user name and password in order to connect.