Package org.mapfish.print.processor.http
Class CompositeClientHttpRequestFactoryProcessor
- java.lang.Object
-
- org.mapfish.print.processor.AbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
-
- org.mapfish.print.processor.http.CompositeClientHttpRequestFactoryProcessor
-
- All Implemented Interfaces:
ConfigurationObject
,HttpProcessor<CompositeClientHttpRequestFactoryProcessor.Input>
,Processor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
public final class CompositeClientHttpRequestFactoryProcessor extends AbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void> implements HttpProcessor<CompositeClientHttpRequestFactoryProcessor.Input>
A processor that wraps severalAbstractClientHttpRequestFactoryProcessor
s.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:
[[examples=http_processors]]- !configureHttpRequests httpProcessors: - !mapUri mapping: (http)://localhost(.*): "$1://127.0.0.1$2" - !forwardHeaders all: true - !restrictUris matchers: [!localMatch {}]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompositeClientHttpRequestFactoryProcessor.Input
The input.-
Nested classes/interfaces inherited from class org.mapfish.print.processor.AbstractProcessor
AbstractProcessor.Context
-
Nested 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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CompositeClientHttpRequestFactoryProcessor()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MfClientHttpRequestFactory
createFactoryWrapper(CompositeClientHttpRequestFactoryProcessor.Input input, MfClientHttpRequestFactory requestFactory)
Create theMfClientHttpRequestFactory
to use.CompositeClientHttpRequestFactoryProcessor.Input
createInputParameter()
Returns a new/clean instance of a parameter object.java.lang.Void
execute(CompositeClientHttpRequestFactoryProcessor.Input values, Processor.ExecutionContext context)
Perform the process on the input attributes.protected void
extraValidation(java.util.List<java.lang.Throwable> validationErrors, Configuration configuration)
Perform any extra validation a subclass may need to perform.void
setHttpProcessors(java.util.List<HttpProcessor> httpProcessors)
Sets all the http processors that will executed by this processor.void
toString(java.lang.StringBuilder builder, int indent, java.lang.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, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.mapfish.print.config.ConfigurationObject
validate
-
Methods inherited from interface org.mapfish.print.processor.Processor
getInputMapperBiMap, getInputPrefix, getOutputMapperBiMap, getOutputPrefix, getOutputType
-
-
-
-
Method Detail
-
setHttpProcessors
public void setHttpProcessors(java.util.List<HttpProcessor> httpProcessors)
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:HttpProcessor
Create theMfClientHttpRequestFactory
to use.- Specified by:
createFactoryWrapper
in 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
protected void extraValidation(java.util.List<java.lang.Throwable> validationErrors, Configuration configuration)
Description copied from class:AbstractProcessor
Perform any extra validation a subclass may need to perform.- Specified by:
extraValidation
in classAbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
- Parameters:
validationErrors
- a list to add errors to so that all validation errors are reported as one.configuration
- the containing configuration
-
createInputParameter
@Nullable public CompositeClientHttpRequestFactoryProcessor.Input createInputParameter()
Description copied from interface:Processor
Returns 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 theValues
object.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
Values
object 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
HasDefaultValue
annotation 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:
createInputParameter
in interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
-
execute
@Nullable public java.lang.Void execute(CompositeClientHttpRequestFactoryProcessor.Input values, Processor.ExecutionContext context)
Description copied from interface:Processor
Perform the process on the input attributes.- Specified by:
execute
in interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
- Parameters:
values
- A Java object whose public fields are populated from theValues
object (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
Values
object. The key in theValues
object 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
public void toString(java.lang.StringBuilder builder, int indent, java.lang.String parent)
Description copied from interface:Processor
Create a string representing this processor.- Specified by:
toString
in interfaceProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.Void>
- Overrides:
toString
in classAbstractProcessor<CompositeClientHttpRequestFactoryProcessor.Input,java.lang.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
-
-