use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method initModels.
/**
* Initiallize SOAP to REST Operations
*
* @return true if extracting operations was successful
*/
private boolean initModels() throws APIMgtWSDLException {
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.");
}
List schemaIncludes = schema.getIncludes();
for (Iterator iter = schemaIncludes.iterator(); iter.hasNext(); ) {
SchemaReference schemaInclude = (SchemaReference) iter.next();
Schema schemaImp = schemaInclude.getReferencedSchema();
String schemaLoc = schemaInclude.getSchemaLocationURI();
if (schemaImp != null && schemaImp.getElement() != null) {
if (schemaImp.getElement().hasChildNodes()) {
schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaImp.getElement().getChildNodes()));
} else {
log.warn("The referenced schema : " + schemaLoc + " doesn't have any defined types");
}
}
}
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;
try {
traverseTypeElement(node, null, model, currentProperty);
} catch (APIManagementException e) {
throw new APIMgtWSDLException(e);
}
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;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getBasedXSDofWSDL.
private Document getBasedXSDofWSDL(String ns) {
if (basedSchemas.containsKey(ns)) {
return basedSchemas.get(ns);
}
Document doc = null;
APIMWSDLReader reader = new APIMWSDLReader(ns + ".xsd");
try {
doc = reader.getSecuredParsedDocumentFromURL(ns + ".xsd");
} catch (APIManagementException e) {
String error = "Error occurred reading wsdl document.";
log.error(error, e);
}
basedSchemas.put(ns, doc);
return doc;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSoapBindingOperations.
/**
* Retrieves all the operations defined in the provided WSDL definition.
*
* @param definition WSDL Definition
* @return a set of {@link WSDLOperation} defined in the provided WSDL definition
*/
private Set<WSDLSOAPOperation> getSoapBindingOperations(Definition definition) throws APIMgtWSDLException {
Set<WSDLSOAPOperation> allOperations = new HashSet<>();
for (Object bindingObj : definition.getAllBindings().values()) {
if (bindingObj instanceof Binding) {
Binding binding = (Binding) bindingObj;
Set<WSDLSOAPOperation> operations = getSOAPBindingOperations(binding);
allOperations.addAll(operations);
}
}
return allOperations;
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class SOAPOperationBindingUtils method getSoapOperationMapping.
/**
* Gets soap operations to rest resources mapping for a wsdl byte content
*
* @param wsdlContent WSDL byte content
* @return swagger json string with the soap operation mapping
* @throws APIManagementException if an error occurs when generating swagger
*/
public static String getSoapOperationMapping(byte[] wsdlContent) throws APIManagementException {
WSDL11SOAPOperationExtractor processor = APIMWSDLReader.getWSDLSOAPOperationExtractor(wsdlContent);
WSDLInfo wsdlInfo = processor.getWsdlInfo();
return getGeneratedSwaggerFromWSDL(wsdlInfo);
}
use of org.wso2.carbon.apimgt.api.model.Wsdl in project carbon-apimgt by wso2.
the class SOAPOperationBindingUtils method getWSDL11SOAPOperationExtractor.
/**
* Gets WSDL processor used to extract the soap binding operations
*
* @param content WSDL content
* @param wsdlReader WSDL reader used to parse the wsdl{@link APIMWSDLReader}
* @return {@link WSDLProcessor}
* @throws APIManagementException
*/
public static WSDL11SOAPOperationExtractor getWSDL11SOAPOperationExtractor(byte[] content, APIMWSDLReader wsdlReader) throws APIManagementException {
WSDL11SOAPOperationExtractor wsdl11SOAPOperationExtractor = new WSDL11SOAPOperationExtractor(wsdlReader);
wsdl11SOAPOperationExtractor.init(content);
return wsdl11SOAPOperationExtractor;
}
Aggregations