This article covers a Bloomreach Experience Manager version 12. There's an updated version available that covers our most recent release.

Example with SalesForce REST API

Introduction

The following ResourceResolver bean definition is an example configuration for SalesForce REST API backend. This will give hints on how to configure conneciton information, RestTemplate object configuration, authentication such as OAuth2, ResourceLinkResolver object configuration, cache control configuration, etc.

The following ResourceResolver Spring Framework Beans configuration can be set at /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoSalesForce/@crisp:beandefinition property in the repository for "demoSalesForce" resource space, for instance.

ResourceResolver Configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
 
  <bean parent="abstractCrispSimpleJacksonRestTemplateResourceResolver"
        class="org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver">
    <property name="cacheEnabled" value="${cache.enabled}" />
    <property name="baseUri" value="${salesforce.baseUrl}/services/data/v20.0" />
    <property name="restTemplate">
      <bean class="org.springframework.security.oauth2.client.OAuth2RestTemplate">
        <constructor-arg>
          <bean class="org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails">
            <property name="clientAuthenticationScheme" value="form" />
            <property name="accessTokenUri" value="${salesforce.baseUrl}/services/oauth2/token" />
            <property name="clientId" value="${salesforce.clientId}" />
            <property name="clientSecret" value="${salesforce.clientSecret}" />
            <property name="grantType" value="password" />
            <property name="username" value="${salesforce.username}" />
            <property name="password" value="${salesforce.password}${salesforce.securityToken}" />
          </bean>
        </constructor-arg>
        <constructor-arg>
          <bean class="org.springframework.security.oauth2.client.DefaultOAuth2ClientContext">
            <constructor-arg>
              <bean class="org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest">
              </bean>
            </constructor-arg>
          </bean>
        </constructor-arg>
        <property name="requestFactory" ref="org.springframework.http.client.ClientHttpRequestFactory" />
      </bean>
    </property>
    <property name="resourceDataCache">
      <bean class="org.onehippo.cms7.crisp.core.resource.SpringResourceDataCache">
        <constructor-arg>
          <bean class="org.springframework.cache.ehcache.EhCacheCache">
            <constructor-arg>
              <bean parent="abstractCrispResourceEhCache">
                <property name="cacheName" value="demoSalesForceCache" />
                <property name="maxEntriesLocalHeap" value="1000" />
                <property name="maxEntriesLocalDisk" value="0" />
                <property name="timeToLiveSeconds" value="60" />
                <property name="timeToIdleSeconds" value="60" />
              </bean>
            </constructor-arg>
          </bean>
        </constructor-arg>
      </bean>
    </property>
  </bean>
 
</beans>

The following properties are used in the bean configuration through pairs of crisp:propnames and crisp:propvalues properties at /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoSalesForce node for "demoSalesForce" resource space, for instance.

Property Name Example Value
cache.enabled true
salesforce.clientId someClientId
salesforce.clientSecret someClientSecret
salesforce.username [email protected]
salesforce.password somePassword
salesforce.securityToken someSecurityToken
salesforce.baseUrl https://na1.salesforce.com
  • cacheEnabled property is to enable or disable ResourceResolver level caching.
  • baseUri property is to set the base URI of the backend SalesForce REST API. So, invocations on ResourceServiceBroker for this resource space will take a relative resource path to combine it with the base URI to invoke the backend SalesForce REST API in the end.
  • restTemplate property is to set an org.springframework.security.oauth2.client.OAuth2RestTemplate object. In this example, because the SalesForce REST API backend requires OAuth2 authentication, it set an instance of org.springframework.security.oauth2.client.OAuth2RestTemplate with necessary OAuth2 authentication information. For details on , please see the JavaDocs: OAuth2RestTemplate. org.springframework.http.client.ClientHttpRequestFactory is the default requestFactory bean definition in CRISP module library.
  • Finally, resourceDataCache property specifies a ResourceResolver specific ResourceDataCache object. If this property is set and the specific resource is cacheable, the ResourceServiceBroker may cache resource specific data in the specified ResourceDataCache. If not set but the specific resource is still cacheable, ResourceServiceBroker may cache resource specific data in a globally-shared ResourceDataCache by default.

 

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?