Example with Marketo REST API

Overview

This page provides an example configuration for a ResourceResolver bean that connects to a Marketo REST API backend using the CRISP API integration in Bloomreach Content. The configuration demonstrates how to define connection details, set up the RestTemplate, configure OAuth2 authentication, manage cache settings, and register the necessary Spring beans.

You can apply this configuration to the /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoMarketo/@crisp:beandefinition property in the repository for a resource space named demoMarketo.

ResourceResolver Configuration

brXM 16

The following example shows how to configure a ResourceResolver for Marketo using Caffeine cache and OAuth2 authentication.

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd 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="${marketo.baseUrl}/rest/v1" /> <property name="resourceDataCache"> <bean class="org.onehippo.cms7.crisp.core.resource.SpringResourceDataCache"> <constructor-arg> <bean class="org.springframework.cache.caffeine.CaffeineCache" factory-bean="caffeineCacheInstanceFactory" factory-method="createSpringCacheInstance"> <constructor-arg value="demomarketoCache" /> <constructor-arg value="initialCapacity=10,maximumSize=1000,expireAfterWrite=100s,expireAfterAccess=100s" /> </bean> </constructor-arg> </bean> </property> <property name="clientHttpRequestInterceptor"> <list value-type="org.springframework.http.client.ClientHttpRequestInterceptor"> <bean class="org.onehippo.cms7.crisp.core.interceptor.SimpleOAuth2AuthorizedClientInterceptor" autowire="constructor"> <property name="authorizedClientService" ref="authorizedClientService" /> <property name="clientRegistrationId" value="marketo-login" /> </bean> </list> </property> </bean> <s:client-registrations> <s:client-registration registration-id="marketo-login" client-id="${marketo.clientId}" client-secret="${marketo.clientSecret}" client-authentication-method="client_secret_basic" authorization-grant-type="client_credentials" provider-id="marketo"/> <s:provider provider-id="marketo" authorization-uri="${marketo.baseUrl}/identity/oauth/token" token-uri="${marketo.baseUrl}/identity/oauth/token"/> </s:client-registrations> <bean id="authorizedClientService" class="org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService" autowire="constructor"/> <bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository"> <constructor-arg ref="authorizedClientService"/> </bean> </beans>

brXM 14 & 15

For Bloomreach Content versions 14 and 15, use EhCache for caching as shown below.

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd 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="${marketo.baseUrl}/rest/v1" /> <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="demomarketoCache" /> <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> <property name="clientHttpRequestInterceptor"> <list value-type="org.springframework.http.client.ClientHttpRequestInterceptor"> <bean class="org.onehippo.cms7.crisp.core.interceptor.SimpleOAuth2AuthorizedClientInterceptor" autowire="constructor"> <property name="authorizedClientService" ref="authorizedClientService" /> <property name="clientRegistrationId" value="marketo-login" /> </bean> </list> </property> </bean> <s:client-registrations> <s:client-registration registration-id="marketo-login" client-id="${marketo.clientId}" client-secret="${marketo.clientSecret}" client-authentication-method="client_secret_basic" authorization-grant-type="client_credentials" provider-id="marketo"/> <s:provider provider-id="marketo" authorization-uri="${marketo.baseUrl}/identity/oauth/token" token-uri="${marketo.baseUrl}/identity/oauth/token"/> </s:client-registrations> <bean id="authorizedClientService" class="org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService" autowire="constructor"/> <bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository"> <constructor-arg ref="authorizedClientService"/> </bean> </beans>

Property Reference

Define the following properties in the repository node /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/demoMarketo using the crisp:propnames and crisp:propvalues properties for the demoMarketo resource space.

Property NameExample Value
cache.enabledtrue
marketo.clientIdsomeClientId
marketo.clientSecretsomeClientSecret
marketo.baseUrlhttps://123-something-456.mktorest.com

Configuration Details

  • The cacheEnabled property enables or disables caching at the ResourceResolver level.
  • The baseUri property sets the base URI for the Marketo REST API. All requests from the ResourceServiceBroker in this resource space use this base URI, appending the relative resource path to form the complete endpoint.
  • The resourceDataCache property assigns a specific ResourceDataCache instance to the ResourceResolver. If set and the resource is cacheable, the ResourceServiceBroker stores resource-specific data in this cache. If not set, cacheable resources are stored in a globally shared cache by default.
  • The clientHttpRequestInterceptor property configures a SimpleOAuth2AuthorizedClientInterceptor to handle OAuth2 authentication. Marketo REST API requires OAuth2, so you must register an OAuth2 client in the OAuth2AuthorizedClientRepository with the required credentials.

Note:
The spring-security-oauth2 project is deprecated, and related libraries will be removed in future releases. Review the Salesforce example for guidance on implementing the SimpleOAuth2AuthorizedClientInterceptor using supported libraries.

Share Feedback
Page: /build/crisp-api/configuration/example-with-marketo-rest-api
Section: Build
Category *