Package org.mapfish.print.processor.http
Class CompositeClientHttpRequestFactoryProcessor
java.lang.Object
org.mapfish.print.processor.AbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void>
org.mapfish.print.processor.http.CompositeClientHttpRequestFactoryProcessor
- All Implemented Interfaces:
ConfigurationObject,HttpProcessor<CompositeClientHttpRequestFactoryProcessor.Input>,Processor<CompositeClientHttpRequestFactoryProcessor.Input,Void>
public final class CompositeClientHttpRequestFactoryProcessor
extends AbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void>
implements HttpProcessor<CompositeClientHttpRequestFactoryProcessor.Input>
A processor that wraps several
AbstractClientHttpRequestFactoryProcessors.
This makes it more convenient to configure multiple processors that modify MfClientHttpRequestFactory objects.
Consider the case where you need to:
- Restrict allowed URIS using the !restrictUris processor
- Forward all headers from print request to all requests using !forwardHeaders
- Change the url using the !mapUri processor
In this case the !mapUri processor must execute before the !restrictUris processor but it is difficult to enforce this, the inputMapping and outputMapping must be carefully designed in order to do it. The following should work but compare it with the example below:
- !mapUri
mapping:
(http)://localhost(.*): "$1://127.0.0.1$2"
outputMapper: {clientHttpRequestFactoryProvider: clientHttpRequestFactoryMapped}
- !forwardHeaders
all: true
inputMapper: {clientHttpRequestFactoryMapped :clientHttpRequestFactoryProvider}
outputMapper: {clientHttpRequestFactoryProvider: clientHttpRequestFactoryWithHeaders}
- !restrictUris
matchers: [!localMatch {}]
inputMapper: {clientHttpRequestFactoryWithHeaders:clientHttpRequestFactoryProvider}
The recommended way to write the above configuration is as follows:
- !configureHttpRequests
httpProcessors:
- !mapUri
mapping:
(http)://localhost(.*): "$1://127.0.0.1$2"
- !forwardHeaders
all: true
- !restrictUris
matchers: [!localMatch {}]
[[examples=http_processors]]-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe input.Nested classes/interfaces inherited from class org.mapfish.print.processor.AbstractProcessor
AbstractProcessor.ContextNested classes/interfaces inherited from interface org.mapfish.print.processor.Processor
Processor.ExecutionContext -
Field Summary
Fields inherited from interface org.mapfish.print.processor.Processor
MDC_APPLICATION_ID_KEY, MDC_JOB_ID_KEY -
Method Summary
Modifier and TypeMethodDescriptioncreateFactoryWrapper(CompositeClientHttpRequestFactoryProcessor.Input input, MfClientHttpRequestFactory requestFactory) Create theMfClientHttpRequestFactoryto use.Returns a new/clean instance of a parameter object.execute(CompositeClientHttpRequestFactoryProcessor.Input values, Processor.ExecutionContext context) Perform the process on the input attributes.protected voidextraValidation(List<Throwable> validationErrors, Configuration configuration) Perform any extra validation a subclass may need to perform.voidsetHttpProcessors(List<HttpProcessor> httpProcessors) Sets all the http processors that will executed by this processor.voidtoString(StringBuilder builder, int indent, String parent) Create a string representing this processor.Methods inherited from class org.mapfish.print.processor.AbstractProcessor
getInputMapperBiMap, getInputPrefix, getOutputMapperBiMap, getOutputPrefix, getOutputType, setInputMapper, setInputPrefix, setOutputMapper, setOutputPrefix, setPrefix, toString, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.mapfish.print.config.ConfigurationObject
validateMethods inherited from interface org.mapfish.print.processor.Processor
getInputMapperBiMap, getInputPrefix, getOutputMapperBiMap, getOutputPrefix, getOutputType
-
Method Details
-
setHttpProcessors
Sets all the http processors that will executed by this processor.- Parameters:
httpProcessors- the sub processors
-
createFactoryWrapper
public MfClientHttpRequestFactory createFactoryWrapper(CompositeClientHttpRequestFactoryProcessor.Input input, MfClientHttpRequestFactory requestFactory) Description copied from interface:HttpProcessorCreate theMfClientHttpRequestFactoryto use.- Specified by:
createFactoryWrapperin interfaceHttpProcessor<CompositeClientHttpRequestFactoryProcessor.Input>- Parameters:
input- extra parameters required to create the updated request factoryrequestFactory- the basic request factory. It should be unmodified and just wrapped with a proxy class.
-
extraValidation
Description copied from class:AbstractProcessorPerform any extra validation a subclass may need to perform.- Specified by:
extraValidationin classAbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void> - Parameters:
validationErrors- a list to add errors to so that all validation errors are reported as one.configuration- the containing configuration
-
createInputParameter
Description copied from interface:ProcessorReturns a new/clean instance of a parameter object. This instance's will be inspected using reflection to find its public fields and the properties will be set from theValuesobject.The way the properties will be looked up is to
- take the bean property name
- map it using the input mapper, (if the input mapper does not have a mapping for the property then the unmapped property name is used)
- Look up the property value in the
Valuesobject using the mapped property name - set the value on the instance created by this method. If the value is null an exception
will be thrown UNLESS the
HasDefaultValueannotation is on the field for the property.
It is important to realize that super classes will also be analyzed, so care must be had with inheritance.
- Specified by:
createInputParameterin interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void>
-
execute
@Nullable public Void execute(CompositeClientHttpRequestFactoryProcessor.Input values, Processor.ExecutionContext context) Description copied from interface:ProcessorPerform the process on the input attributes.- Specified by:
executein interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void> - Parameters:
values- A Java object whose public fields are populated from theValuesobject (which is used for transferring properties between processors).context- The execution context for a print task.- Returns:
- A Java object whose public fields will be put into the
Valuesobject. The key in theValuesobject is the name of the field or if there is a mapping in theProcessor.getOutputMapperBiMap()map, the mapped name. The key is determined in a similar way as for the input object.
-
toString
Description copied from interface:ProcessorCreate a string representing this processor.- Specified by:
toStringin interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void> - Overrides:
toStringin classAbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,Void> - Parameters:
builder- the builder to add the string to.indent- the number of steps of indent for this nodeparent- the parent node's name
-