javax.wsdl.extensions.schema.Schema Java Examples

The following examples show how to use javax.wsdl.extensions.schema.Schema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsdlTypes.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Find a named <complexType> or <simpleType> in the types section of the WSDL.
 *
 * @param typeName Name of the type to find.
 * @return null if type not found.
 */
protected Element findNamedType( QName typeName ) {

  Schema s = getSchema( typeName.getNamespaceURI() );
  if ( s == null ) {
    return null;
  }

  Element schemaRoot = s.getElement();

  // get all simple and complex types defined at the top-level.
  //
  List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
  types.addAll( DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.SIMPLE_TYPE_NAME ) );

  Element namedType = null;
  for ( Element t : types ) {
    String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
    if ( typeName.getLocalPart().equals( schemaTypeName ) ) {
      namedType = t;
      break;
    }
  }
  return namedType;
}
 
Example #2
Source File: WsdlTypes.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Build a list of schema target name spaces which are element form qualified.
 *
 * @return All target name spaces for schemas defined in the WSDL which are element form qualified.
 */
private List<String> getElementFormQualifiedNamespaces() {

  List<String> namespaces = new ArrayList<>();
  List<ExtensibilityElement> schemas = getSchemas();

  for ( ExtensibilityElement schema : schemas ) {
    Element schemaElement = ( (Schema) schema ).getElement();

    if ( schemaElement.hasAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR ) ) {
      String v = schemaElement.getAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR );
      if ( WsdlUtils.ELEMENT_FORM_QUALIFIED.equalsIgnoreCase( v ) ) {
        namespaces.add( schemaElement.getAttribute( WsdlUtils.TARGET_NAMESPACE_ATTR ) );
      }
    }
  }
  return namespaces;
}
 
Example #3
Source File: WsdlTypes.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Get the schema with the specified target namespace.
 *
 * @param targetNamespace target namespace of the schema to get.
 * @return null if not found.
 */
private Schema getSchema( String targetNamespace ) {

  if ( _types == null ) {
    return null;
  }

  List<ExtensibilityElement> schemas = WsdlUtils.findExtensibilityElements( (ElementExtensible) _types, "schema" );

  for ( ExtensibilityElement e : schemas ) {
    Element schemaRoot = ( (Schema) e ).getElement();
    String tns = schemaRoot.getAttribute( "targetNamespace" );
    if ( targetNamespace.equals( tns ) ) {
      return (Schema) e;
    }
  }
  return null;
}
 
Example #4
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Get the schema with the specified target namespace.
 *
 * @param targetNamespace
 *          target namespace of the schema to get.
 * @return null if not found.
 */
private Schema getSchema( String targetNamespace ) {

  if ( _types == null ) {
    return null;
  }

  List<ExtensibilityElement> schemas = WsdlUtils.findExtensibilityElements( _types, "schema" );

  for ( ExtensibilityElement e : schemas ) {
    Element schemaRoot = ( (Schema) e ).getElement();
    String tns = schemaRoot.getAttribute( "targetNamespace" );
    if ( targetNamespace.equals( tns ) ) {
      return (Schema) e;
    }
  }
  return null;
}
 
Example #5
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Build a list of schema target name spaces which are element form qualified.
 *
 * @return All target name spaces for schemas defined in the WSDL which are element form qualified.
 */
private List<String> getElementFormQualifiedNamespaces() {

  List<String> namespaces = new ArrayList<String>();
  List<ExtensibilityElement> schemas = getSchemas();

  for ( ExtensibilityElement schema : schemas ) {
    Element schemaElement = ( (Schema) schema ).getElement();

    if ( schemaElement.hasAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR ) ) {
      String v = schemaElement.getAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR );
      if ( WsdlUtils.ELEMENT_FORM_QUALIFIED.equalsIgnoreCase( v ) ) {
        namespaces.add( schemaElement.getAttribute( WsdlUtils.TARGET_NAMESPACE_ATTR ) );
      }
    }
  }
  return namespaces;
}
 
Example #6
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Find a named &lt;complexType&gt; or &lt;simpleType&gt; in the types section of the WSDL.
 *
 * @param typeName
 *          Name of the type to find.
 * @return null if type not found.
 */
protected Element findNamedType( QName typeName ) {

  Schema s = getSchema( typeName.getNamespaceURI() );
  if ( s == null ) {
    return null;
  }

  Element schemaRoot = s.getElement();

  // get all simple and complex types defined at the top-level.
  //
  List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
  types.addAll( DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.SIMPLE_TYPE_NAME ) );

  Element namedType = null;
  for ( Element t : types ) {
    String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
    if ( typeName.getLocalPart().equals( schemaTypeName ) ) {
      namedType = t;
      break;
    }
  }
  return namedType;
}
 
Example #7
Source File: SchemaWriterImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Element getElement(Definition wsdlDef) throws WSDLException {
    Types types = wsdlDef.getTypes();
    if (types != null) {
        List<ExtensibilityElement> l = CastUtils.cast(types.getExtensibilityElements());
        if (l == null) {
            return null;
        }

        for (ExtensibilityElement e : l) {
            if (e instanceof Schema) {
                Schema sc = (Schema)e;
                return sc.getElement();
            }
        }
    }
    return null;
}
 
Example #8
Source File: WSDLCorbaWriterImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void fixTypes(Definition wsdlDef) throws ParserConfigurationException {
    Types t = wsdlDef.getTypes();
    if (t == null) {
        return;
    }
    List<ExtensibilityElement> l = CastUtils.cast(t.getExtensibilityElements());
    if (l == null) {
        return;
    }

    for (ExtensibilityElement e : l) {
        if (e instanceof Schema) {
            Schema sc = (Schema)e;
            String pfx = wsdlDef.getPrefix(sc.getElementType().getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                pfx = "xsd";
                String ns = wsdlDef.getNamespace(pfx);
                int count = 1;
                while (!StringUtils.isEmpty(ns)) {
                    pfx = "xsd" + count++;
                    ns = wsdlDef.getNamespace(pfx);
                }
                wsdlDef.addNamespace(pfx, sc.getElementType().getNamespaceURI());
            }
            if (sc.getElement() == null) {
                fixSchema(sc, pfx);
            }
        }
    }
}
 
Example #9
Source File: WsdlComplexTypes.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance, parse the WSDL file for named complex types.
 *
 * @param wsdlTypes
 *          Name space resolver.
 */
protected WsdlComplexTypes( WsdlTypes wsdlTypes ) {

  List<ExtensibilityElement> schemas = wsdlTypes.getSchemas();
  for ( ExtensibilityElement schema : schemas ) {
    Element schemaRoot = ( (Schema) schema ).getElement();

    List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
    for ( Element t : types ) {
      String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
      _complexTypes.put( schemaTypeName, new ComplexType( t, wsdlTypes ) );
    }
  }
}
 
Example #10
Source File: WSDLCorbaWriterImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void fixSchema(Schema sc, String pfx) throws ParserConfigurationException {
    Document doc = DOMUtils.getEmptyDocument();
    Element el = doc.createElementNS(sc.getElementType().getNamespaceURI(),
                        pfx + ":" + sc.getElementType().getLocalPart());
    sc.setElement(el);
    Map<String, List<String>> mp = CastUtils.cast(sc.getImports());
    for (Map.Entry<String, List<String>> ent : mp.entrySet()) {
        Element imp = doc.createElementNS(sc.getElementType().getNamespaceURI(),
                                          pfx + ":import");
        el.appendChild(imp);
        imp.setAttribute("namespace", ent.getKey());
    }
}
 
Example #11
Source File: WSDLGetUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * When the imported schema location has been resolved through catalog, we need to:
 * 1) get a valid relative location to use for recursion into the imported schema
 * 2) add an entry to the doneSchemas map using such a valid relative location, as that's
 *    what will be used later for import links
 *
 * The valid relative location for the imported schema is computed by first obtaining the
 * relative uri that maps the importing schema resolved location into the imported schema
 * resolved location, then such value is resolved on top of the valid relative location
 * that's saved in the doneSchemas map for the importing schema.
 *
 * @param doneSchemas
 * @param resolvedSchemaLocation
 * @param currentSchema
 * @param schemaReference
 * @return
 */
private String getAndSaveRelativeSchemaLocationIfCatalogResolved(Map<String, SchemaReference> doneSchemas,
                                                                 String resolvedSchemaLocation,
                                                                 Schema currentSchema,
                                                                 SchemaReference schemaReference) {
    String path = null;
    for (Map.Entry<String, SchemaReference> entry : doneSchemas.entrySet()) {
        Schema rs = entry.getValue().getReferencedSchema();
        String k = entry.getKey();
        String rsURI = rs.getDocumentBaseURI();
        if (currentSchema.equals(rs) && !rsURI.equals(k)) {
            try {
                String p = URIParserUtil.relativize(rsURI, resolvedSchemaLocation);
                if (p != null) {
                    path = new URI(k).resolve(p).toString();
                    break;
                }
            } catch (URISyntaxException e) {
                // ignore
            }
        }
    }
    if (path != null) {
        doneSchemas.put(path, schemaReference);
    }
    return path;
}
 
Example #12
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addSchemaImport(Schema schema, SchemaInfo schemaInfo, Schema referencedSchema) {
    SchemaImport imp = schema.createImport();
    imp.setId(schemaInfo.getSystemId());
    imp.setNamespaceURI(schemaInfo.getNamespaceURI());
    imp.setSchemaLocationURI(referencedSchema.getDocumentBaseURI());
    imp.setReferencedSchema(referencedSchema);
    schema.addImport(imp);
}
 
Example #13
Source File: SchemaUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void getSchemaList(Definition def) {
    Types typesElement = def.getTypes();
    if (typesElement != null) {
        Iterator<?> ite = typesElement.getExtensibilityElements().iterator();
        while (ite.hasNext()) {
            Object obj = ite.next();
            if (obj instanceof Schema) {
                Schema schema = (Schema)obj;
                addSchema(schema.getDocumentBaseURI(), schema);
            }
        }
    }
}
 
Example #14
Source File: SchemaSerializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void marshall(@SuppressWarnings("rawtypes") Class parentType,
                     QName elementType, ExtensibilityElement extension, PrintWriter pw,
                     Definition def, ExtensionRegistry extReg) throws WSDLException {
    try {
        writeXml(((Schema)extension).getElement(), pw);
    } catch (XMLStreamException e) {
        throw new WSDLException("", "Could not write schema.", e);
    }
}
 
Example #15
Source File: ServiceWSDLBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchemas() throws Exception {
    setupWSDL(WSDL_PATH);
    Types types = newDef.getTypes();
    assertNotNull(types);
    Collection<ExtensibilityElement> schemas =
        CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class);
    assertEquals(1, schemas.size());
    XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
    Element schemaElem = ((Schema)schemas.iterator().next()).getElement();
    XmlSchema newSchema = schemaCollection.read(schemaElem);
    assertEquals("http://apache.org/hello_world_soap_http/types",
                 newSchema.getTargetNamespace()
                 );
}
 
Example #16
Source File: WsdlXmlValidator.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected static void addNamespaces(Schema schema, Map<String, String> namespaces) {
	for (Map.Entry<String,String> e : namespaces.entrySet()) {
		String key = e.getKey().length() == 0 ? "xmlns" : ("xmlns:" + e.getKey());
		if (schema.getElement().getAttribute(key).length() == 0) {
			schema.getElement().setAttribute(key, e.getValue());
		}
	}
}
 
Example #17
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Find a named &lt;element&gt; in the types section of the WSDL.
 *
 * @param elementName
 *          Name of element to find.
 * @return The element node.
 * @throws KettleStepException
 *           If schema or element in schema can't be found for the given element name
 */
protected Element findNamedElement( QName elementName ) throws KettleStepException {

  Element namedElement = null;
  Schema s = getSchema( elementName.getNamespaceURI() );
  if ( s == null ) {
    throw new KettleStepException( BaseMessages
      .getString( PKG, "Wsdl.Error.MissingSchemaException", elementName ) );
  }

  Element schemaRoot = s.getElement();
  List<Element> elements = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.ELEMENT_NAME );

  for ( Element e : elements ) {
    String schemaElementName = e.getAttribute( WsdlUtils.NAME_ATTR );
    if ( elementName.getLocalPart().equals( schemaElementName ) ) {
      namedElement = e;
      break;
    }
  }

  if ( namedElement == null ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "Wsdl.Error.ElementMissingException", elementName ) );
  }
  return namedElement;
}
 
Example #18
Source File: WsdlTypes.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Find a named &lt;element&gt; in the types section of the WSDL.
 *
 * @param elementName Name of element to find.
 * @return The element node.
 * @throws HopTransformException If schema or element in schema can't be found for the given element name
 */
protected Element findNamedElement( QName elementName ) throws HopTransformException {

  Element namedElement = null;
  Schema s = getSchema( elementName.getNamespaceURI() );
  if ( s == null ) {
    throw new HopTransformException( BaseMessages
      .getString( PKG, "Wsdl.Error.MissingSchemaException", elementName ) );
  }

  Element schemaRoot = s.getElement();
  List<Element> elements = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.ELEMENT_NAME );

  for ( Element e : elements ) {
    String schemaElementName = e.getAttribute( WsdlUtils.NAME_ATTR );
    if ( elementName.getLocalPart().equals( schemaElementName ) ) {
      namedElement = e;
      break;
    }
  }

  if ( namedElement == null ) {
    throw new HopTransformException( BaseMessages.getString(
      PKG, "Wsdl.Error.ElementMissingException", elementName ) );
  }
  return namedElement;
}
 
Example #19
Source File: WSDLSchemaManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addWSDLSchemaImport(Schema wsdlSchema, String tns, File file) {
    if (!wsdlSchema.getImports().containsKey(tns)) {
        SchemaImport schemaimport = wsdlSchema.createImport();
        schemaimport.setNamespaceURI(tns);
        if (file != null && !ignoreImports) {
            schemaimport.setSchemaLocationURI(file.toURI().toString());
        }
        wsdlSchema.addImport(schemaimport);
    }
}
 
Example #20
Source File: WsdlComplexTypes.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance, parse the WSDL file for named complex types.
 *
 * @param wsdlTypes Name space resolver.
 */
protected WsdlComplexTypes( WsdlTypes wsdlTypes ) {

  List<ExtensibilityElement> schemas = wsdlTypes.getSchemas();
  for ( ExtensibilityElement schema : schemas ) {
    Element schemaRoot = ( (Schema) schema ).getElement();

    List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
    for ( Element t : types ) {
      String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
      _complexTypes.put( schemaTypeName, new ComplexType( t, wsdlTypes ) );
    }
  }
}
 
Example #21
Source File: WSDLDocCreator.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setSchemaDocIntoWSDLTypes( Document doc ) {
	try {

		Types wsdl_types = localDef.createTypes();
		Schema typesExt = (Schema) extensionRegistry.createExtension( Types.class,
			new QName( NameSpacesEnum.XML_SCH.getNameSpaceURI(), "schema" ) );
		typesExt.setElement( (Element) doc.getFirstChild() );
		wsdl_types.addExtensibilityElement( typesExt );
		localDef.setTypes( wsdl_types );

	} catch( Exception ex ) {
		System.err.println( ex.getMessage() );
	}
}
 
Example #22
Source File: XTeeWsdlDefinition.java    From j-road with Apache License 2.0 5 votes vote down vote up
private void addXRoadExtensions(Definition definition) throws WSDLException {
  definition.addNamespace(XROAD_PREFIX, XROAD_NAMESPACE);

  Message message = definition.createMessage();
  message.setQName(new QName(definition.getTargetNamespace(), XROAD_HEADER));

  addXroadHeaderPart(definition, message, XTeeHeader.CLIENT);
  addXroadHeaderPart(definition, message, XTeeHeader.SERVICE);
  addXroadHeaderPart(definition, message, XTeeHeader.ID);
  addXroadHeaderPart(definition, message, XTeeHeader.USER_ID);
  addXroadHeaderPart(definition, message, XTeeHeader.PROTOCOL_VERSION);

  message.setUndefined(false);
  definition.addMessage(message);

  // Add XRoad schema import to the first schema
  for (Object ex : definition.getTypes().getExtensibilityElements()) {
    if (ex instanceof Schema) {
      Schema schema = (Schema) ex;
      Element xRoadImport =
          schema.getElement().getOwnerDocument().createElement(schema.getElement().getPrefix() == null
                                                                                                       ? "import"
                                                                                                       : schema.getElement().getPrefix()
                                                                                                           + ":import");
      xRoadImport.setAttribute("namespace", XROAD_NAMESPACE);
      xRoadImport.setAttribute("schemaLocation", XROAD_NAMESPACE);
      schema.getElement().insertBefore(xRoadImport, schema.getElement().getFirstChild());
      break;
    }
  }
}
 
Example #23
Source File: WSDLSchemaManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void addWSDLSchemaImport(Definition def, String tns, File file) throws Exception {
    // REVISIT, check if the wsdl schema already exists.
    Types types = def.getTypes();
    if (types == null) {
        types = def.createTypes();
        def.setTypes(types);
    }
    Schema wsdlSchema = (Schema)def.getExtensionRegistry()
        .createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));

    addWSDLSchemaImport(wsdlSchema, tns, file);
    types.addExtensibilityElement(wsdlSchema);
}
 
Example #24
Source File: WSDL11SOAPOperationExtractor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Initiallize SOAP to REST Operations
 *
 * @return true if extracting operations was successful
 */
private boolean initModels() {
    wsdlDefinition = getWSDLDefinition();
    boolean canProcess = true;
    targetNamespace = wsdlDefinition.getTargetNamespace();
    Types types = wsdlDefinition.getTypes();
    if (types != null) {
        typeList = types.getExtensibilityElements();
    }
    if (typeList != null) {
        for (Object ext : typeList) {
            if (ext instanceof Schema) {
                Schema schema = (Schema) ext;
                Map importedSchemas = schema.getImports();
                Element schemaElement = schema.getElement();
                NodeList schemaNodes = schemaElement.getChildNodes();
                schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
                //gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
                if (importedSchemas != null) {
                    for (Object importedSchemaObj : importedSchemas.keySet()) {
                        String schemaUrl = (String) importedSchemaObj;
                        if (importedSchemas.get(schemaUrl) != null) {
                            Vector vector = (Vector) importedSchemas.get(schemaUrl);
                            for (Object schemaVector : vector) {
                                if (schemaVector instanceof SchemaImport) {
                                    Schema referencedSchema = ((SchemaImport) schemaVector)
                                            .getReferencedSchema();
                                    if (referencedSchema != null && referencedSchema.getElement() != null) {
                                        if (referencedSchema.getElement().hasChildNodes()) {
                                            schemaNodeList.addAll(SOAPOperationBindingUtils
                                                    .list(referencedSchema.getElement().getChildNodes()));
                                        } else {
                                            log.warn("The referenced schema : " + schemaUrl
                                                    + " doesn't have any defined types");
                                        }
                                    } else {
                                        boolean isInlineSchema = false;
                                        for (Object aSchema : typeList) {
                                            if (schemaUrl.equalsIgnoreCase(
                                                    ((Schema) aSchema).getElement()
                                                            .getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
                                                isInlineSchema = true;
                                                break;
                                            }
                                        }
                                        if (isInlineSchema) {
                                            log.debug(schemaUrl + " is already defined inline. Hence continue.");
                                        } else {
                                            log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    log.info("No any imported schemas found in the given wsdl.");
                }

                if (log.isDebugEnabled()) {
                    Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy())
                            .create();
                    log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
                }
                if (schemaNodeList == null) {
                    log.warn("No schemas found in the type element for target namespace:" + schema
                            .getDocumentBaseURI());
                }
            }
        }
        if (schemaNodeList != null) {
            for (Node node : schemaNodeList) {
                WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
                ModelImpl model = new ModelImpl();
                Property currentProperty = null;
                traverseTypeElement(node, null, model, currentProperty);
                if (StringUtils.isNotBlank(model.getName())) {
                    parameterModelMap.put(model.getName(), model);
                }
                if (wsdlParamDefinition.getDefinitionName() != null) {
                    wsdlParamDefinitions.add(wsdlParamDefinition);
                }
            }
        } else {
            log.info("No schema is defined in the wsdl document");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName()
                + " with a single WSDL.");
    }
    return canProcess;
}
 
Example #25
Source File: STSClientTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testWCFWsdl() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();

    // Load WSDL
    InputStream inStream = getClass().getResourceAsStream("wcf.wsdl");
    Document doc = StaxUtils.read(inStream);


    NodeList metadataSections =
        doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2004/09/mex", "MetadataSection");
    Element wsdlDefinition = null;
    List<Element> schemas = new ArrayList<>();
    for (int i = 0; i < metadataSections.getLength(); i++) {
        Node node = metadataSections.item(i);
        if (node instanceof Element) {
            Element element = (Element)node;
            String dialect = element.getAttributeNS(null, "Dialect");
            if ("http://schemas.xmlsoap.org/wsdl/".equals(dialect)) {
                wsdlDefinition = DOMUtils.getFirstElement(element);
            } else if ("http://www.w3.org/2001/XMLSchema".equals(dialect)) {
                schemas.add(DOMUtils.getFirstElement(element));
            }
        }
    }

    assertNotNull(wsdlDefinition);
    assertFalse(schemas.isEmpty());

    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
    Definition definition = wsdlManager.getDefinition(wsdlDefinition);

    for (Element schemaElement : schemas) {
        QName schemaName =
            new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
        ExtensibilityElement
            exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
        ((Schema)exElement).setElement(schemaElement);
        definition.getTypes().addExtensibilityElement(exElement);
    }

    WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
    SourceDataBinding dataBinding = new SourceDataBinding();
    factory.setDataBinding(dataBinding);
    Service service = factory.create();
    service.setDataBinding(dataBinding);

}
 
Example #26
Source File: XMLUtil.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static void writeSchema(Schema schema, File file) throws Exception {
	writeSchema(schema, new FileOutputStream(file));
}
 
Example #27
Source File: XMLUtil.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static void writeSchema(Schema schema, OutputStream outputStream) throws Exception {
	FileUtils.createFile(getSchemaString(schema), outputStream);
}
 
Example #28
Source File: SchemaUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void addSchema(String docBaseURI, Schema schema) {
    //String docBaseURI = schema.getDocumentBaseURI();
    Element schemaEle = schema.getElement();
    if (schemaList.get(docBaseURI) == null) {
        schemaList.put(docBaseURI, schemaEle);
    } else if (schemaList.get(docBaseURI) != null && schemaList.containsValue(schemaEle)) {
        // do nothing
    } else {
        String tns = schema.getDocumentBaseURI() + "#"
                     + schema.getElement().getAttribute("targetNamespace");
        if (schemaList.get(tns) == null) {
            schemaList.put(tns, schema.getElement());
        }
    }

    Map<String, List<?>> imports = CastUtils.cast(schema.getImports());
    if (imports != null && !imports.isEmpty()) {
        for (Map.Entry<String, List<?>> entry : imports.entrySet()) {
            String importNamespace = entry.getKey();
            List<SchemaImport> schemaImports = CastUtils.cast(entry.getValue());

            for (SchemaImport schemaImport : schemaImports) {
                Schema tempImport = schemaImport.getReferencedSchema();
                String key = schemaImport.getSchemaLocationURI();
                if (importNamespace == null && tempImport != null) {
                    importNamespace = tempImport.getDocumentBaseURI();
                }

                if (tempImport != null && !catalogResolved.containsKey(key)) {
                    key = tempImport.getDocumentBaseURI();
                }

                if (tempImport != null
                    && !isSchemaParsed(key, importNamespace)
                    && !schemaList.containsValue(tempImport.getElement())) {
                    addSchema(key, tempImport);
                }
            }

        }
    }
}
 
Example #29
Source File: XMLUtil.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static String getSchemaString(Schema schema) throws Exception {
	Element element = schema.getElement();
	return getElementString(element);
}
 
Example #30
Source File: SchemaUtil.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private void init(Types types) {
    Collection<Schema> schemas = WSDLUtils.findExtensibilityElements(types.getExtensibilityElements(), Schema.class);
    for (Schema schema : schemas) {
        createXmlSchema(schema.getElement(), schema.getDocumentBaseURI());
    }
}