Class TemplatedBodyBuilder
java.lang.Object
net.shibboleth.utilities.java.support.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
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
FieldsModifier and TypeFieldDescriptionprivate Template
Body template to be evaluated.private String
Text of body template to be evaluated.private Template
Cache key template to be evaluated.private String
Text of cache key template to be evaluated.private String
Character set.private org.apache.http.entity.ContentType
Content type.private Object
A custom object to inject into the template.private org.apache.velocity.app.VelocityEngine
VelocityEngine.private final Escaper
Escaper for fragments.private final org.slf4j.Logger
Class logger.private String
HTTP method.private String
MIME type.private final Escaper
Escaper for form parameters.private final Escaper
Escaper for path segments.private Template
URL template to be evaluated.private String
Text of URL template to be evaluated.private final Escaper
Escaper for XML Attributes.private final Escaper
Escaper for XML content. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Get the body template to be evaluated.Get the body template text to be evaluated.Get the cache key template to be evaluated.Get the cache key template text to be evaluated.protected org.apache.http.client.methods.HttpUriRequest
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.http.client.methods.HttpUriRequest request, AttributeResolutionContext resolutionContext, Map<String, List<IdPAttributeValue>> dependencyAttributes) Default implementation just allows caching of GET requests and returns the URI itself.Get the URL template to be evaluated.Get the URL template text to be evaluated.org.apache.velocity.app.VelocityEngine
Get theVelocityEngine
to be used.protected String
InvokesTemplate.merge(org.apache.velocity.context.Context)
on the supplied template and context.void
setBodyTemplateText
(String text) Set the body template to be evaluated.void
Set the cache key template to be evaluated.void
Set the character set.void
setCustomObject
(Object object) Set the custom (externally provided) object.void
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 theVelocityEngine
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.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
urlTemplate
URL template to be evaluated. -
bodyTemplate
Body template to be evaluated. -
cacheKeyTemplate
Cache key template to be evaluated. -
urlTemplateText
Text of URL template to be evaluated. -
bodyTemplateText
Text of body template to be evaluated. -
cacheKeyTemplateText
Text of cache key template to be evaluated. -
engine
VelocityEngine. -
method
HTTP method. -
mimeType
MIME type. -
charset
Character set. -
contentType
Content type. -
paramEscaper
Escaper for form parameters. -
fragmentEscaper
Escaper for fragments. -
pathEscaper
Escaper for path segments. -
xmlAttributeEscaper
Escaper for XML Attributes. -
xmlContentEscaper
Escaper for XML content. -
customObject
A custom object to inject into the template.
-
-
Constructor Details
-
TemplatedBodyBuilder
public TemplatedBodyBuilder()Constructor.
-
-
Method Details
-
getURLTemplate
Get the URL template to be evaluated.- Returns:
- template
-
getBodyTemplate
Get the body template to be evaluated.- Returns:
- template
-
getCacheKeyTemplate
Get the cache key template to be evaluated.- Returns:
- template
-
getURLTemplateText
Get the URL template text to be evaluated.- Returns:
- template text
-
setURLTemplateText
Set the URL template to be evaluated.- Parameters:
text
- template to be evaluated
-
getBodyTemplateText
Get the body template text to be evaluated.- Returns:
- template text
-
setBodyTemplateText
Set the body template to be evaluated.- Parameters:
text
- template to be evaluated
-
getCacheKeyTemplateText
Get the cache key template text to be evaluated.- Returns:
- template text
-
setCacheKeyTemplateText
Set the cache key template to be evaluated.- Parameters:
text
- template to be evaluated
-
getVelocityEngine
Get theVelocityEngine
to be used.- Returns:
- template engine
-
setVelocityEngine
public void setVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine velocityEngine) Set theVelocityEngine
to be used.- Parameters:
velocityEngine
- engine to be used
-
setMethod
Set the HTTP method.Defaults to "POST".
- Parameters:
m
- method
-
setMIMEType
Set the MIME type.Defaults to "text/plain".
- Parameters:
type
- MIME type
-
setCharacterSet
Set the character set.- Parameters:
c
- character set
-
setCustomObject
Set the custom (externally provided) object.- Parameters:
object
- the custom object
-
doInitialize
- Overrides:
doInitialize
in classAbstractInitializableComponent
- Throws:
ComponentInitializationException
-
merge
@Nonnull @NotEmpty protected String merge(@Nonnull Template template, @Nonnull org.apache.velocity.VelocityContext context) InvokesTemplate.merge(org.apache.velocity.context.Context)
on the supplied template and context.- Parameters:
template
- template to mergecontext
- to merge- Returns:
- result of the merge operation
-
getHttpRequest
@Nonnull protected org.apache.http.client.methods.HttpUriRequest getHttpRequest(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull Map<String, List<IdPAttributeValue>> dependencyAttributes) throws ResolutionExceptionDefault implementation just supports GET and builds a request around a URL.- Overrides:
getHttpRequest
in classAbstractHTTPSearchBuilder
- Parameters:
resolutionContext
- the context of the resolutiondependencyAttributes
- made available to the request- Returns:
- the
HttpRequest
to use - Throws:
ResolutionException
- if an error occurs
-
getResultCacheKey
@Nonnull @NotEmpty protected String getResultCacheKey(@Nonnull org.apache.http.client.methods.HttpUriRequest 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 classAbstractHTTPSearchBuilder
- Parameters:
request
- the HTTP request about to be executedresolutionContext
- the attribute resolution contextdependencyAttributes
- dependencies- Returns:
- the cache key
-