Ejemplo n.º 1
0
  private SoapVersion11() {
    try {
      XmlOptions options = new XmlOptions();
      options.setCompileNoValidation();
      options.setCompileNoPvrRule();
      options.setCompileDownloadUrls();
      options.setCompileNoUpaRule();
      options.setValidateTreatLaxAsSkip();

      URL soapSchemaXmlResource =
          ResourceUtils.getResourceWithAbsolutePackagePath(
              getClass(), "/xsds/", "soapEnvelope.xsd");
      soapSchemaXml = XmlUtils.createXmlObject(soapSchemaXmlResource, options);
      soapSchema = XmlBeans.loadXsd(new XmlObject[] {soapSchemaXml});

      soapEnvelopeType = soapSchema.findDocumentType(envelopeQName);
      soapFaultType = soapSchema.findDocumentType(faultQName);

      URL soapEncodingXmlResource =
          ResourceUtils.getResourceWithAbsolutePackagePath(
              getClass(), "/xsds/", "soapEncoding.xsd");
      soapEncodingXml = XmlUtils.createXmlObject(soapEncodingXmlResource, options);

    } catch (XmlException ex) {
      throw new SoapBuilderException(ex);
    }
  }
Ejemplo n.º 2
0
  /**
   * Finds nested XML schema definition and compiles it to a schema type system instance.
   *
   * @param wsdl
   * @return
   * @throws MojoExecutionException
   */
  private SchemaTypeSystem compileXsd(XmlObject wsdl) throws MojoExecutionException {
    // extract namespaces defined on wsdl-level:
    String[] namespacesWsdl = extractNamespacesOnWsdlLevel(wsdl);

    // calc the namespace-prefix of the schema-tag, default ""
    String schemaNsPrefix = extractSchemaNamespacePrefix(wsdl);

    // extract each schema-element and add missing namespaces defined on wsdl-level
    String[] schemas = getNestedSchemas(wsdl, namespacesWsdl, schemaNsPrefix);

    XmlObject[] xsd = new XmlObject[schemas.length];
    try {
      for (int i = 0; i < schemas.length; i++) {
        xsd[i] =
            XmlObject.Factory.parse(
                schemas[i],
                (new XmlOptions())
                    .setLoadLineNumbers()
                    .setLoadMessageDigest()
                    .setCompileDownloadUrls());
      }
    } catch (Exception e) {
      throw new MojoExecutionException("Failed to parse XSD schema", e);
    }

    SchemaTypeSystem schemaTypeSystem = null;
    try {
      schemaTypeSystem =
          XmlBeans.compileXsd(xsd, XmlBeans.getContextTypeLoader(), new XmlOptions());
    } catch (XmlException e) {
      for (Object error : e.getErrors()) {
        getLog().error("Line " + ((XmlError) error).getLine() + ": " + error.toString());
      }
      throw new MojoExecutionException("Failed to compile XSD schema", e);
    } catch (Exception e) {
      throw new MojoExecutionException("Failed to compile XSD schema", e);
    }
    return schemaTypeSystem;
  }