Package net.shibboleth.idp.attribute.resolver.dc.http.impl

# Class TemplatedBodyBuilder

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.attribute.resolver.dc.http.impl.AbstractHTTPSearchBuilder
net.shibboleth.idp.attribute.resolver.dc.http.impl.TemplatedBodyBuilder

All Implemented Interfaces:
  `ExecutableSearchBuilder<HTTPSearch>`, `Component`, `DestructableComponent`, `InitializableComponent`

public class TemplatedBodyBuilder extends AbstractHTTPSearchBuilder
An `ExecutableSearchBuilder` that generates a request by evaluating `Template`s against the currently resolved attributes within an `AttributeResolutionContext` to produce a URL and body, via GET or POST, and a configurable cache key.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Template`
`bodyTemplate`
Body template to be evaluated.
`private String`
`bodyTemplateText`
Text of body template to be evaluated.
`private Template`
`cacheKeyTemplate`
Cache key template to be evaluated.
`private String`
`cacheKeyTemplateText`
Text of cache key template to be evaluated.
`private String`
`charset`
Character set.
`private org.apache.hc.core5.http.ContentType`
`contentType`
Content type.
`private Object`
`customObject`
A custom object to inject into the template.
`private org.apache.velocity.app.VelocityEngine`
`engine`
VelocityEngine.
`private final Escaper`
`fragmentEscaper`
Escaper for fragments.
`private final org.slf4j.Logger`
`log`
Class logger.
`private String`
`method`
HTTP method.
`private String`
`mimeType`
MIME type.
`private final Escaper`
`paramEscaper`
Escaper for form parameters.
`private final Escaper`
`pathEscaper`
Escaper for path segments.
`private Template`
`urlTemplate`
URL template to be evaluated.
`private String`
`urlTemplateText`
Text of URL template to be evaluated.
`private final Escaper`
`xmlAttributeEscaper`
Escaper for XML Attributes.
`private final Escaper`
`xmlContentEscaper`
Escaper for XML content.

## Constructor Summary

Constructors
Constructor
Description
`TemplatedBodyBuilder()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doInitialize()`
`Template`
`getBodyTemplate()`
Get the body template to be evaluated.
`String`
`getBodyTemplateText()`
Get the body template text to be evaluated.
`Template`
`getCacheKeyTemplate()`
Get the cache key template to be evaluated.
`String`
`getCacheKeyTemplateText()`
Get the cache key template text to be evaluated.
`protected org.apache.hc.core5.http.ClassicHttpRequest`
`getHttpRequest(AttributeResolutionContext resolutionContext, Map<String,List<IdPAttributeValue>> dependencyAttributes)`
Default implementation just supports GET and builds a request around a URL.
`protected String`
`getResultCacheKey(org.apache.hc.core5.http.ClassicHttpRequest request, AttributeResolutionContext resolutionContext, Map<String,List<IdPAttributeValue>> dependencyAttributes)`
Default implementation just allows caching of GET requests and returns the URI itself.
`Template`
`getURLTemplate()`
Get the URL template to be evaluated.
`String`
`getURLTemplateText()`
Get the URL template text to be evaluated.
`org.apache.velocity.app.VelocityEngine`
`getVelocityEngine()`
Get the `VelocityEngine` to be used.
`protected String`
`merge(Template template, org.apache.velocity.VelocityContext context)`
Invokes `Template.merge(org.apache.velocity.context.Context)` on the supplied template and context.
`void`
`setBodyTemplateText(String text)`
Set the body template to be evaluated.
`void`
`setCacheKeyTemplateText(String text)`
Set the cache key template to be evaluated.
`void`
`setCharacterSet(String c)`
Set the character set.
`void`
`setCustomObject(Object object)`
Set the custom (externally provided) object.
`void`
`setMethod(String m)`
Set the HTTP method.
`void`
`setMIMEType(String type)`
Set the MIME type.
`void`
`setURLTemplateText(String text)`
Set the URL template to be evaluated.
`void`
`setVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)`
Set the `VelocityEngine` to be used.

### Methods inherited from class net.shibboleth.idp.attribute.resolver.dc.http.impl.AbstractHTTPSearchBuilder

`build, getHeaders, getHttpClientSecurityParameters, getURL, setHeaders, setHttpClientSecurityParameters`

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### urlTemplate

@NonnullAfterInit private Template urlTemplate
URL template to be evaluated.

### bodyTemplate

@NonnullAfterInit private Template bodyTemplate
Body template to be evaluated.

### cacheKeyTemplate

private Template cacheKeyTemplate
Cache key template to be evaluated.

### urlTemplateText

@NonnullAfterInit private String urlTemplateText
Text of URL template to be evaluated.

### bodyTemplateText

@NonnullAfterInit private String bodyTemplateText
Text of body template to be evaluated.

### cacheKeyTemplateText

private String cacheKeyTemplateText
Text of cache key template to be evaluated.

### engine

@NonnullAfterInit private org.apache.velocity.app.VelocityEngine engine
VelocityEngine.

### method

@Nonnull @NotEmpty private String method
HTTP method.

### mimeType

@Nonnull @NotEmpty private String mimeType
MIME type.

### charset

@Nullable private String charset
Character set.

### contentType

@NonnullAfterInit private org.apache.hc.core5.http.ContentType contentType
Content type.

### paramEscaper

@Nonnull private final Escaper paramEscaper
Escaper for form parameters.

### fragmentEscaper

@Nonnull private final Escaper fragmentEscaper
Escaper for fragments.

### pathEscaper

@Nonnull private final Escaper pathEscaper
Escaper for path segments.

### xmlAttributeEscaper

@Nonnull private final Escaper xmlAttributeEscaper
Escaper for XML Attributes.

### xmlContentEscaper

@Nonnull private final Escaper xmlContentEscaper
Escaper for XML content.

### customObject

@Nullable private Object customObject
A custom object to inject into the template.

## Constructor Details

### TemplatedBodyBuilder

public TemplatedBodyBuilder()
Constructor.

## Method Details

### getURLTemplate

@NonnullAfterInit public Template getURLTemplate()
Get the URL template to be evaluated.

Returns:
  template

### getBodyTemplate

@NonnullAfterInit public Template getBodyTemplate()
Get the body template to be evaluated.

Returns:
  template

### getCacheKeyTemplate

@Nullable public Template getCacheKeyTemplate()
Get the cache key template to be evaluated.

Returns:
  template

### getURLTemplateText

@NonnullAfterInit public String getURLTemplateText()
Get the URL template text to be evaluated.

Returns:
  template text

### setURLTemplateText

public void setURLTemplateText(@Nullable String text)
Set the URL template to be evaluated.

Parameters:
  `text` - template to be evaluated

### getBodyTemplateText

@NonnullAfterInit public String getBodyTemplateText()
Get the body template text to be evaluated.

Returns:
  template text

### setBodyTemplateText

public void setBodyTemplateText(@Nullable String text)
Set the body template to be evaluated.

Parameters:
  `text` - template to be evaluated

### getCacheKeyTemplateText

@Nullable public String getCacheKeyTemplateText()
Get the cache key template text to be evaluated.

Returns:
  template text

### setCacheKeyTemplateText

public void setCacheKeyTemplateText(@Nullable String text)
Set the cache key template to be evaluated.

Parameters:
  `text` - template to be evaluated

### getVelocityEngine

@NonnullAfterInit public org.apache.velocity.app.VelocityEngine getVelocityEngine()
Get the `VelocityEngine` to be used.

Returns:
  template engine

### setVelocityEngine

public void setVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine velocityEngine)
Set the `VelocityEngine` to be used.

Parameters:
  `velocityEngine` - engine to be used

### setMethod

public void setMethod(@Nonnull @NotEmpty String m)
Set the HTTP method.

Defaults to "POST".

Parameters:
  `m` - method

### setMIMEType

public void setMIMEType(@Nonnull @NotEmpty String type)
Set the MIME type.

Defaults to "text/plain".

Parameters:
  `type` - MIME type

### setCharacterSet

public void setCharacterSet(@Nullable String c)
Set the character set.

Parameters:
  `c` - character set

### setCustomObject

public void setCustomObject(@Nullable Object object)
Set the custom (externally provided) object.

Parameters:
  `object` - the custom object

### doInitialize

protected void doInitialize() throws ComponentInitializationException

Overrides:
  `doInitialize` in class `AbstractInitializableComponent`
Throws:
  `ComponentInitializationException`

### merge

@Nonnull @NotEmpty protected String merge(@Nonnull Template template, @Nonnull org.apache.velocity.VelocityContext context)
Invokes `Template.merge(org.apache.velocity.context.Context)` on the supplied template and context.

Parameters:
  `template` - template to merge
  `context` - to merge
Returns:
  result of the merge operation

### getHttpRequest

@Nonnull protected org.apache.hc.core5.http.ClassicHttpRequest getHttpRequest(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull Map<String,List<IdPAttributeValue>> dependencyAttributes) throws ResolutionException
Default implementation just supports GET and builds a request around a URL.

Overrides:
  `getHttpRequest` in class `AbstractHTTPSearchBuilder`
Parameters:
  `resolutionContext` - the context of the resolution
  `dependencyAttributes` - made available to the request
Returns:
  the `ClassicHttpRequest` to use
Throws:
  `ResolutionException` - if an error occurs

### getResultCacheKey

@Nullable @NotEmpty protected String getResultCacheKey(@Nonnull org.apache.hc.core5.http.ClassicHttpRequest request, @Nonnull AttributeResolutionContext resolutionContext, @Nonnull Map<String,List<IdPAttributeValue>> dependencyAttributes)
Default implementation just allows caching of GET requests and returns the URI itself.

Overrides:
  `getResultCacheKey` in class `AbstractHTTPSearchBuilder`
Parameters:
  `request` - the HTTP request about to be executed
  `resolutionContext` - the attribute resolution context
  `dependencyAttributes` - dependencies
Returns:
  the cache key