Class Json2XmlValidator

All Implemented Interfaces:
HasSpecialDefaultValues, HasPhysicalDestination, HasTransactionAttribute, IConfigurable, IConfigurationAware, IDualModeValidator, IForwardTarget, INamedObject, IPipe, IScopeProvider, IValidator, IWithParameters, IXmlValidator, EventThrowing, HasStatistics, 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
  • Field Details

  • Constructor Details

    • Json2XmlValidator

      public Json2XmlValidator()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      Description copied from class: XmlValidator
      Configure the XmlValidator
      Specified by:
      configure in interface IConfigurable
      Specified by:
      configure in interface IPipe
      Overrides:
      configure in class XmlValidator
      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 class XmlValidator
      Throws:
      PipeRunException - when isThrowException 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
      Throws:
      XmlValidatorException
      PipeRunException
      ConfigurationException
    • alignJson

      protected PipeRunResult alignJson(String messageToValidate, PipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException
      Throws:
      PipeRunException
      XmlValidatorException
    • addNamespace

      public String addNamespace(String xml)
    • 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 interface HasPhysicalDestination
    • 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 interface HasPhysicalDestination
    • 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()