Package nl.nn.adapterframework.pipes
Class Json2XmlValidator
-
- All Implemented Interfaces:
HasSpecialDefaultValues
,HasPhysicalDestination
,HasTransactionAttribute
,IConfigurable
,IConfigurationAware
,IDualModeValidator
,IExtendedPipe
,IForwardTarget
,INamedObject
,IPipe
,IScopeProvider
,IValidator
,IXmlValidator
,EventThrowing
,SchemasProvider
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
SoapValidator
public class Json2XmlValidator extends XmlValidator implements HasPhysicalDestination
Pipe
that validates the XML or JSON input message against a XML Schema and returns either XML or JSON.- Author:
- Gerrit van Brakel
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class nl.nn.adapterframework.pipes.XmlValidator
XmlValidator.ResponseValidatorWrapper
-
-
Field Summary
Fields Modifier and Type Field Description static String
INPUT_FORMAT_SESSION_KEY_PREFIX
-
Fields inherited from class nl.nn.adapterframework.pipes.XmlValidator
configurationException, validator
-
Fields inherited from class nl.nn.adapterframework.pipes.AbstractPipe
parameterNamesMustBeUnique
-
Fields inherited from class nl.nn.adapterframework.core.TransactionAttributes
log
-
Fields inherited from interface nl.nn.adapterframework.core.IExtendedPipe
LONG_DURATION_MONITORING_EVENT, MESSAGE_SIZE_MONITORING_EVENT, PIPE_EXCEPTION_MONITORING_EVENT
-
-
Constructor Summary
Constructors Constructor Description Json2XmlValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
addNamespace(String xml)
protected PipeRunResult
alignJson(String messageToValidate, PipeLineSession session, boolean responseMode)
protected PipeRunResult
alignXml2Json(String messageToValidate, PipeLineSession session, boolean responseMode)
void
configure()
Configure the XmlValidatorjakarta.json.JsonStructure
createJsonSchema(String elementName)
jakarta.json.JsonStructure
createJsonSchema(String elementName, String namespace)
PipeRunResult
doPipe(Message input, PipeLineSession session, boolean responseMode, String messageRoot)
Validate the XML or JSON input, and align/convert it into JSON or XML according to a XML Schema.String
getDomain()
String
getInputFormatSessionKey()
protected RootValidations
getJsonRootValidations(boolean responseMode)
DocumentFormat
getOutputFormat()
DocumentFormat
getOutputFormat(PipeLineSession session, boolean responseMode)
String
getOutputFormatSessionKey()
String
getPhysicalDestinationName()
String
getTargetNamespace()
boolean
isAcceptNamespacelessXml()
boolean
isAllowJson()
boolean
isAutoFormat()
boolean
isCompactJsonArrays()
boolean
isDeepSearch()
boolean
isFailOnWildcards()
boolean
isIgnoreUndeclaredElements()
boolean
isJsonWithRootElements()
boolean
isProduceNamespacelessXml()
boolean
isStrictJsonArraySyntax()
boolean
isValidateJsonToRootElementOnly()
void
setAcceptNamespacelessXml(boolean acceptNamespacelessXml)
If true, all XML is allowed to be without namespaces.void
setAcceptNamespaceLessXml(boolean acceptNamespacelessXml)
Deprecated.void
setAllowJson(boolean allowJson)
Allow JSON inputvoid
setAutoFormat(boolean autoFormat)
If true, the format on 'output' is set to the same as the format of the input message on 'input'.void
setCompactJsonArrays(boolean compactJsonArrays)
If true assume arrays in JSON do not have the element containers like in XMLvoid
setDeepSearch(boolean deepSearch)
If true, and converting from JSON to XML, parameter substitutions are searched for optional sub elements too.void
setFailOnWildcards(boolean failOnWildcards)
If true, an exception is thrown when a wildcard is found in the XML Schema when parsing an object.void
setIgnoreUndeclaredElements(boolean ignoreUndeclaredElements)
If true, and converting from JSON to XML, elements in JSON that are not found in the XML Schema are ignoredvoid
setInputFormatSessionKey(String inputFormatSessionKey)
Session key to store the inputFormat in, to be able to set the outputformat when autoFormat=true.void
setJsonWithRootElements(boolean jsonWithRootElements)
If true, assume that JSON contains/must contain a root elementvoid
setOutputFormat(DocumentFormat outputFormat)
Default format of the result, that is used if the format cannot be found from outputFormatSessionKey or from inputFormatSessionKey (when validating responses and autoFormat=true)void
setOutputFormatSessionKey(String outputFormatSessionKey)
Session key to retrieve outputFormat fromvoid
setProduceNamespacelessXml(boolean produceNamespacelessXml)
If true, all XML that is generated is without a namespace setvoid
setProduceNamespaceLessXml(boolean produceNamespacelessXml)
Deprecated.void
setStrictJsonArraySyntax(boolean strictJsonArraySyntax)
If true check that incoming JSON adheres to the specified syntax (compact or full), otherwise both types are accepted for conversion from JSON to XMLvoid
setTargetNamespace(String targetNamespace)
Only for JSON input: namespace of the resulting XML.void
setValidateJsonToRootElementOnly(boolean validateJsonToRootElementOnly)
If true, and converting to or from JSON, then the message root is the only rootValidation, ignoring root validations like for SOAP envelope and header set by descender classes like SoapValidatorprotected void
storeInputFormat(DocumentFormat format, Message input, PipeLineSession session, boolean responseMode)
-
Methods inherited from class nl.nn.adapterframework.pipes.XmlValidator
addInvalidRootNamespaces, addRequestRootValidation, addResponseRootValidation, afterPropertiesSet, checkSchemaSpecified, createRootValidation, determineForward, getCharset, getConfigurationException, getDocumentation, getErrorResult, getIgnoreUnknownNamespaces, getImportedNamespacesToIgnore, getImportedSchemaLocationsToIgnore, getInvalidRootNamespaces, getMessageRoot, getMessageRoot, getNoNamespaceSchemaLocation, getReasonSessionKey, getRequestRootValidations, getResponseRootValidations, getResponseValidator, getRootElementSessionKey, getRootNamespaceSessionKey, getRootValidations, getSchema, getSchemaLocation, getSchemas, getSchemas, getSchemas, getSchemasId, getSchemasId, getSoapNamespace, getSpecialDefaultValue, getXmlReasonSessionKey, getXsds, getXSModels, isAddNamespaceToSchema, isConfiguredForMixedValidation, isFullSchemaChecking, isThrowException, isUseBaseImportedSchemaLocationsToIgnore, isValidateFile, setAddNamespaceToSchema, setCharset, setFullSchemaChecking, setIgnoreCaching, setIgnoreUnknownNamespaces, setImplementation, setImportedNamespacesToIgnore, setImportedSchemaLocationsToIgnore, setNoNamespaceSchemaLocation, setReasonSessionKey, setResponseRoot, setRoot, setRootElementSessionKey, setRootNamespaceSessionKey, setSchema, setSchemaLocation, setSoapNamespace, setThrowException, setUseBaseImportedSchemaLocationsToIgnore, setValidateFile, setWarn, setXmlReasonSessionKey, setXmlSchemaVersion, start, stop, validate
-
Methods inherited from class nl.nn.adapterframework.pipes.ValidatorBase
determineForward, doPipe, getResponseRoot, getRoot, getSchemaSessionKey, isForwardFailureToSuccess, setForwardFailureToSuccess, setSchemaSessionKey, validate, validate
-
Methods inherited from class nl.nn.adapterframework.pipes.FixedForwardPipe
getIfParam, getIfValue, getOnlyIfSessionKey, getOnlyIfValue, getParameterValue, getSuccessForward, getUnlessSessionKey, getUnlessValue, isSkipOnEmptyInput, setIfParam, setIfValue, setOnlyIfSessionKey, setOnlyIfValue, setSkipOnEmptyInput, setUnlessSessionKey, setUnlessValue, skipPipe
-
Methods inherited from class nl.nn.adapterframework.pipes.AbstractPipe
addParameter, consumesSessionVariable, createBean, findForward, getAdapter, getApplicationContext, getChompCharSize, getConfigurationClassLoader, getDurationThreshold, getElementToMove, getElementToMoveChain, getElementToMoveSessionKey, getEmptyInputReplacement, getEventSourceName, getForwards, getGetInputFromFixedValue, getGetInputFromSessionKey, getHideRegex, getInSizeStatDummyObject, getLocker, getLogIntermediaryResults, getMaxThreads, getName, getOutSizeStatDummyObject, getParameterList, getPipeLine, getSecLogSessionKeys, getStoreResultInSessionKey, hasSizeStatistics, isPreserveInput, isRemoveCompactMsgNamespaces, isRestoreMovedElements, isWriteToSecLog, registerEvent, registerForward, setApplicationContext, setChompCharSize, setDurationThreshold, setElementToMove, setElementToMoveChain, setElementToMoveSessionKey, setEmptyInputReplacement, setEventPublisher, setGetInputFromFixedValue, setGetInputFromSessionKey, setHideRegex, setLocker, setLogIntermediaryResults, setMaxThreads, setName, setPipeLine, setPreserveInput, setRemoveCompactMsgNamespaces, setRestoreMovedElements, setSecLogSessionKeys, setSizeStatistics, setStoreResultInSessionKey, setWriteToSecLog, throwEvent
-
Methods inherited from class nl.nn.adapterframework.core.TransactionAttributes
configureTransactionAttributes, getTransactionAttribute, getTransactionTimeout, getTxDef, isTransacted, isTransacted, setTransacted, setTransactionAttribute, setTransactionTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
-
Methods inherited from interface nl.nn.adapterframework.core.IConfigurationAware
getApplicationContext, getName
-
Methods inherited from interface nl.nn.adapterframework.core.IExtendedPipe
throwEvent
-
Methods inherited from interface nl.nn.adapterframework.core.IForwardTarget
getName
-
Methods inherited from interface nl.nn.adapterframework.core.INamedObject
getName
-
Methods inherited from interface nl.nn.adapterframework.core.IPipe
consumesSessionVariable, doPipe, getForwards, getMaxThreads, registerForward
-
Methods inherited from interface nl.nn.adapterframework.core.IScopeProvider
getConfigurationClassLoader
-
Methods inherited from interface nl.nn.adapterframework.core.IValidator
setName, validate
-
-
-
-
Field Detail
-
INPUT_FORMAT_SESSION_KEY_PREFIX
public static final String INPUT_FORMAT_SESSION_KEY_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
public void configure() throws ConfigurationException
Description copied from class:XmlValidator
Configure the XmlValidator- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceIPipe
- Overrides:
configure
in classXmlValidator
- Throws:
ConfigurationException
- when:- the schema cannot be found
- <
XmlValidator.isThrowException()
is false and there is no forward defined for "failure" - when the parser does not accept setting the properties for validating
-
getOutputFormat
public DocumentFormat getOutputFormat(PipeLineSession session, boolean responseMode)
-
storeInputFormat
protected void storeInputFormat(DocumentFormat format, Message input, PipeLineSession session, boolean responseMode)
-
doPipe
public PipeRunResult doPipe(Message input, PipeLineSession session, boolean responseMode, String messageRoot) throws PipeRunException
Validate the XML or JSON input, and align/convert it into JSON or XML according to a XML Schema. The format of the input message (XML or JSON) is automatically detected.- Overrides:
doPipe
in classXmlValidator
- Throws:
PipeRunException
- whenisThrowException
is true and a validationerror occurred.
-
getJsonRootValidations
protected RootValidations getJsonRootValidations(boolean responseMode)
-
alignXml2Json
protected PipeRunResult alignXml2Json(String messageToValidate, PipeLineSession session, boolean responseMode) throws XmlValidatorException, PipeRunException, ConfigurationException
-
alignJson
protected PipeRunResult alignJson(String messageToValidate, PipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException
-
createJsonSchema
public jakarta.json.JsonStructure createJsonSchema(String elementName)
-
createJsonSchema
public jakarta.json.JsonStructure createJsonSchema(String elementName, String namespace)
-
getPhysicalDestinationName
public String getPhysicalDestinationName()
- Specified by:
getPhysicalDestinationName
in interfaceHasPhysicalDestination
-
setTargetNamespace
public void setTargetNamespace(String targetNamespace)
Only for JSON input: namespace of the resulting XML. Need only be specified when the namespace of root name is ambiguous in the schema
-
setOutputFormat
public void setOutputFormat(DocumentFormat outputFormat)
Default format of the result, that is used if the format cannot be found from outputFormatSessionKey or from inputFormatSessionKey (when validating responses and autoFormat=true)- Default value
- XML
-
setOutputFormatSessionKey
public void setOutputFormatSessionKey(String outputFormatSessionKey)
Session key to retrieve outputFormat from- Default value
- outputFormat
-
setInputFormatSessionKey
public void setInputFormatSessionKey(String inputFormatSessionKey)
Session key to store the inputFormat in, to be able to set the outputformat when autoFormat=true. Can also be used to pass the value of an HTTP Accept header, to obtain a properly formatted response- Default value
- "Json2XmlValidator.inputFormat "<name of the pipe>
-
setAutoFormat
public void setAutoFormat(boolean autoFormat)
If true, the format on 'output' is set to the same as the format of the input message on 'input'. The format of the input message is stored in and retrieved from the session variable specified by outputFormatSessionKey- Default value
- true
-
setCompactJsonArrays
public void setCompactJsonArrays(boolean compactJsonArrays)
If true assume arrays in JSON do not have the element containers like in XML- Default value
- true
-
setStrictJsonArraySyntax
public void setStrictJsonArraySyntax(boolean strictJsonArraySyntax)
If true check that incoming JSON adheres to the specified syntax (compact or full), otherwise both types are accepted for conversion from JSON to XML- Default value
- false
-
setJsonWithRootElements
public void setJsonWithRootElements(boolean jsonWithRootElements)
If true, assume that JSON contains/must contain a root element- Default value
- false
-
setDeepSearch
public void setDeepSearch(boolean deepSearch)
If true, and converting from JSON to XML, parameter substitutions are searched for optional sub elements too. By default, only mandatory elements are searched for parameter substitutions. N.B. Currently this option might cause problems. Please try using more qualified parameters names (using '/') first- Default value
- false
-
setIgnoreUndeclaredElements
public void setIgnoreUndeclaredElements(boolean ignoreUndeclaredElements)
If true, and converting from JSON to XML, elements in JSON that are not found in the XML Schema are ignored- Default value
- false
-
setFailOnWildcards
public void setFailOnWildcards(boolean failOnWildcards)
If true, an exception is thrown when a wildcard is found in the XML Schema when parsing an object. This often indicates that an element is not properly typed in the XML Schema, and could lead to ambuigities.- Default value
- true
-
setAcceptNamespacelessXml
public void setAcceptNamespacelessXml(boolean acceptNamespacelessXml)
If true, all XML is allowed to be without namespaces. If no namespaces are detected (by the presence of the string 'xmlns') in the XML, the root namespace is added to the XML- Default value
- false
-
setAcceptNamespaceLessXml
@Deprecated @ConfigurationWarning("The attribute \'acceptNamespaceLessXml\' has been renamed \'acceptNamespacelessXml\'") public void setAcceptNamespaceLessXml(boolean acceptNamespacelessXml)
Deprecated.
-
setProduceNamespacelessXml
public void setProduceNamespacelessXml(boolean produceNamespacelessXml)
If true, all XML that is generated is without a namespace set- Default value
- false
-
setProduceNamespaceLessXml
@Deprecated @ConfigurationWarning("The attribute \'produceNamespaceLessXml\' has been renamed \'produceNamespacelessXml\'") public void setProduceNamespaceLessXml(boolean produceNamespacelessXml)
Deprecated.
-
setValidateJsonToRootElementOnly
public void setValidateJsonToRootElementOnly(boolean validateJsonToRootElementOnly)
If true, and converting to or from JSON, then the message root is the only rootValidation, ignoring root validations like for SOAP envelope and header set by descender classes like SoapValidator- Default value
- true
-
setAllowJson
public void setAllowJson(boolean allowJson)
Allow JSON input- Default value
- true
-
getDomain
public String getDomain()
- Specified by:
getDomain
in interfaceHasPhysicalDestination
-
isCompactJsonArrays
public boolean isCompactJsonArrays()
-
isStrictJsonArraySyntax
public boolean isStrictJsonArraySyntax()
-
isJsonWithRootElements
public boolean isJsonWithRootElements()
-
isDeepSearch
public boolean isDeepSearch()
-
isIgnoreUndeclaredElements
public boolean isIgnoreUndeclaredElements()
-
getTargetNamespace
public String getTargetNamespace()
-
getOutputFormat
public DocumentFormat getOutputFormat()
-
isAutoFormat
public boolean isAutoFormat()
-
getInputFormatSessionKey
public String getInputFormatSessionKey()
-
getOutputFormatSessionKey
public String getOutputFormatSessionKey()
-
isFailOnWildcards
public boolean isFailOnWildcards()
-
isAcceptNamespacelessXml
public boolean isAcceptNamespacelessXml()
-
isProduceNamespacelessXml
public boolean isProduceNamespacelessXml()
-
isValidateJsonToRootElementOnly
public boolean isValidateJsonToRootElementOnly()
-
isAllowJson
public boolean isAllowJson()
-
-