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
public class TemplatedBodyBuilder extends AbstractHTTPSearchBuilder
AnExecutableSearchBuilderthat generates a request by evaluatingTemplates against the currently resolved attributes within anAttributeResolutionContextto produce a URL and body, via GET or POST, and a configurable cache key.
-
-
Field Summary
Fields Modifier and Type Field Description private TemplatebodyTemplateBody template to be evaluated.private StringbodyTemplateTextText of body template to be evaluated.private TemplatecacheKeyTemplateCache key template to be evaluated.private StringcacheKeyTemplateTextText of cache key template to be evaluated.private StringcharsetCharacter set.private org.apache.http.entity.ContentTypecontentTypeContent type.private ObjectcustomObjectA custom object to inject into the template.private org.apache.velocity.app.VelocityEngineengineVelocityEngine.private EscaperfragmentEscaperEscaper for fragments.private org.slf4j.LoggerlogClass logger.private StringmethodHTTP method.private StringmimeTypeMIME type.private EscaperparamEscaperEscaper for form parameters.private EscaperpathEscaperEscaper for path segments.private TemplateurlTemplateURL template to be evaluated.private StringurlTemplateTextText of URL template to be evaluated.private EscaperxmlAttributeEscaperEscaper for XML Attributes.private EscaperxmlContentEscaperEscaper for XML content.
-
Constructor Summary
Constructors Constructor Description TemplatedBodyBuilder()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoInitialize()TemplategetBodyTemplate()Get the body template to be evaluated.StringgetBodyTemplateText()Get the body template text to be evaluated.TemplategetCacheKeyTemplate()Get the cache key template to be evaluated.StringgetCacheKeyTemplateText()Get the cache key template text to be evaluated.protected org.apache.http.client.methods.HttpUriRequestgetHttpRequest(AttributeResolutionContext resolutionContext, Map<String,List<IdPAttributeValue>> dependencyAttributes)Default implementation just supports GET and builds a request around a URL.protected StringgetResultCacheKey(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.TemplategetURLTemplate()Get the URL template to be evaluated.StringgetURLTemplateText()Get the URL template text to be evaluated.org.apache.velocity.app.VelocityEnginegetVelocityEngine()Get theVelocityEngineto be used.protected Stringmerge(Template template, org.apache.velocity.VelocityContext context)InvokesTemplate.merge(org.apache.velocity.context.Context)on the supplied template and context.voidsetBodyTemplateText(String text)Set the body template to be evaluated.voidsetCacheKeyTemplateText(String text)Set the cache key template to be evaluated.voidsetCharacterSet(String c)Set the character set.voidsetCustomObject(Object object)Set the custom (externally provided) object.voidsetMethod(String m)Set the HTTP method.voidsetMIMEType(String type)Set the MIME type.voidsetURLTemplateText(String text)Set the URL template to be evaluated.voidsetVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)Set theVelocityEngineto 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 Detail
-
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
@NonnullAfterInit 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
@NonnullAfterInit private String cacheKeyTemplateText
Text of cache key template to be evaluated.
-
engine
@NonnullAfterInit private org.apache.velocity.app.VelocityEngine engine
VelocityEngine.
-
charset
@Nullable private String charset
Character set.
-
contentType
@NonnullAfterInit private org.apache.http.entity.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.
-
-
Method Detail
-
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 theVelocityEngineto be used.- Returns:
- template engine
-
setVelocityEngine
public void setVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine velocityEngine)Set theVelocityEngineto 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:
doInitializein 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:
getHttpRequestin classAbstractHTTPSearchBuilder- Parameters:
resolutionContext- the context of the resolutiondependencyAttributes- made available to the request- Returns:
- the
HttpRequestto 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:
getResultCacheKeyin classAbstractHTTPSearchBuilder- Parameters:
request- the HTTP request about to be executedresolutionContext- the attribute resolution contextdependencyAttributes- dependencies- Returns:
- the cache key
-
-