/**
  * Sets explicit xsd schema repository instance to use for validation.
  *
  * @param schemaRepository
  * @return
  */
 public AssertSoapFaultDefinition xsdSchemaRepository(String schemaRepository) {
   validationContext.setSchemaRepository(schemaRepository);
   return this;
 }
 /**
  * Sets schema validation enabled/disabled for this SOAP fault assertion.
  *
  * @param enabled
  * @return
  */
 public AssertSoapFaultDefinition schemaValidation(boolean enabled) {
   validationContext.setSchemaValidation(enabled);
   return this;
 }
 /**
  * Sets explicit schema instance name to use for schema validation.
  *
  * @param schemaName
  * @return
  */
 public AssertSoapFaultDefinition xsd(String schemaName) {
   validationContext.setSchema(schemaName);
   return this;
 }
Exemplo n.º 4
0
  public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanDefinition;

    beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(AssertSoapFault.class);

    beanDefinition.addPropertyValue("name", element.getLocalName());
    DescriptionElementParser.doParse(element, beanDefinition);

    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, element.getAttribute("fault-code"), "faultCode");
    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, element.getAttribute("fault-string"), "faultString");
    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, element.getAttribute("fault-actor"), "faultActor");

    Element faultDetailElement = DomUtils.getChildElementByTagName(element, "fault-detail");
    if (faultDetailElement != null) {
      if (faultDetailElement.hasAttribute("file")) {
        if (StringUtils.hasText(DomUtils.getTextValue(faultDetailElement).trim())) {
          throw new BeanCreationException(
              "You tried to set fault-detail by file resource attribute and inline text value at the same time! "
                  + "Please choose one of them.");
        }

        String filePath = faultDetailElement.getAttribute("file");
        beanDefinition.addPropertyValue("faultDetailResourcePath", filePath);
      } else {
        String faultDetailData = DomUtils.getTextValue(faultDetailElement).trim();
        if (StringUtils.hasText(faultDetailData)) {
          beanDefinition.addPropertyValue("faultDetail", faultDetailData);
        } else {
          throw new BeanCreationException(
              "Not content for fault-detail is set! Either use file attribute or inline text value for fault-detail element.");
        }
      }

      XmlMessageValidationContext context = new XmlMessageValidationContext();

      String schemaValidation = faultDetailElement.getAttribute("schema-validation");
      if (StringUtils.hasText(schemaValidation)) {
        context.setSchemaValidation(Boolean.valueOf(schemaValidation));
      }

      String schema = faultDetailElement.getAttribute("schema");
      if (StringUtils.hasText(schema)) {
        context.setSchema(schema);
      }

      String schemaRepository = faultDetailElement.getAttribute("schema-repository");
      if (StringUtils.hasText(schemaRepository)) {
        context.setSchemaRepository(schemaRepository);
      }

      beanDefinition.addPropertyValue("validationContext", context);
    }

    Map<String, BeanDefinitionParser> actionRegistry =
        TestActionRegistry.getRegisteredActionParser();
    Element action;
    if (faultDetailElement == null) {
      action = DOMUtil.getFirstChildElement(element);
    } else {
      action = DOMUtil.getNextSiblingElement(faultDetailElement);
    }

    if (action != null && action.getTagName().equals("description")) {
      action = DOMUtil.getNextSiblingElement(action);
    }

    if (action != null) {
      BeanDefinitionParser parser = actionRegistry.get(action.getTagName());

      if (parser == null) {
        beanDefinition.addPropertyValue(
            "action",
            parserContext
                .getReaderContext()
                .getNamespaceHandlerResolver()
                .resolve(action.getNamespaceURI())
                .parse(action, parserContext));
      } else {
        beanDefinition.addPropertyValue("action", parser.parse(action, parserContext));
      }
    }

    BeanDefinitionParserUtils.setPropertyReference(
        beanDefinition, element.getAttribute("fault-validator"), "validator", "soapFaultValidator");
    BeanDefinitionParserUtils.setPropertyReference(
        beanDefinition,
        element.getAttribute("message-factory"),
        "messageFactory",
        "messageFactory");

    return beanDefinition.getBeanDefinition();
  }