use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDLProcessFactory method getWSDLProcessorForPath.
/**
* Returns the appropriate WSDL 1.1 or 2.0 processor based on the file path {@code wsdlPath}.
*
* @param wsdlPath File path containing WSDL files and dependant files
* @return WSDL 1.1 or 2.0 processor for the provided content
* @throws APIMgtWSDLException If an error occurs while determining the processor
*/
public WSDLProcessor getWSDLProcessorForPath(String wsdlPath) throws APIMgtWSDLException {
for (String clazz : getWSDLProcessorClasses()) {
WSDLProcessor processor;
try {
processor = (WSDLProcessor) Class.forName(clazz).newInstance();
boolean canProcess = processor.initPath(wsdlPath);
if (canProcess) {
return processor;
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
}
// no processors found if this line reaches
throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getWSDLByteArrayOutputStream.
/**
* Retrieves a {@link ByteArrayOutputStream} for provided {@link Definition}.
*
* @param definition WSDL Definition
* @return A {@link ByteArrayOutputStream} for provided {@link Definition}
* @throws APIMgtWSDLException If an error occurs while creating {@link ByteArrayOutputStream}
*/
private ByteArrayOutputStream getWSDLByteArrayOutputStream(Definition definition) throws APIMgtWSDLException {
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
writer.writeWSDL(definition, byteArrayOutputStream);
} catch (WSDLException e) {
throw new APIMgtWSDLException("Error while stringifying WSDL definition", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
return byteArrayOutputStream;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getWsdlInfo.
@Override
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
WSDLInfo wsdlInfo = new WSDLInfo();
Map<String, String> endpointsMap = getEndpoints();
Set<WSDLOperation> operations = getHttpBindingOperations();
wsdlInfo.setEndpoints(endpointsMap);
wsdlInfo.setVersion(APIMgtConstants.WSDLConstants.WSDL_VERSION_11);
if (!operations.isEmpty()) {
wsdlInfo.setHasHttpBindingOperations(true);
wsdlInfo.setHttpBindingOperations(operations);
} else {
wsdlInfo.setHasHttpBindingOperations(false);
}
wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
return wsdlInfo;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method getUpdatedWSDLPath.
/**
* Updates the endpoints of all the WSDL files in the path based on the provided API (context) and Label (host).
*
* @param api Provided API object
* @param label Provided label object
* @return Updated WSDL file path
* @throws APIMgtWSDLException Error while updating WSDL files
*/
@Override
public String getUpdatedWSDLPath(API api, Label label) throws APIMgtWSDLException {
if (label != null) {
for (Map.Entry<String, Definition> entry : pathToDefinitionMap.entrySet()) {
Definition definition = entry.getValue();
if (log.isDebugEnabled()) {
log.debug("Updating endpoints of WSDL: " + entry.getKey());
}
updateEndpoints(label.getAccessUrls(), api, definition);
if (log.isDebugEnabled()) {
log.debug("Successfully updated endpoints of WSDL: " + entry.getKey());
}
try (FileOutputStream wsdlFileOutputStream = new FileOutputStream(new File(entry.getKey()))) {
WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter();
writer.writeWSDL(definition, wsdlFileOutputStream);
} catch (IOException | WSDLException e) {
throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getName() + ":" + api.getVersion() + " for label " + label.getName(), ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
}
}
}
return wsdlArchiveExtractedPath;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method initPath.
/**
* {@inheritDoc}
* Will return true if all the provided WSDL files in the initialized path is of 1.1 and can be successfully
* parsed by WSDL4J.
*/
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
pathToDefinitionMap = new HashMap<>();
wsdlArchiveExtractedPath = path;
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
try {
File folderToImport = new File(path);
Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
if (log.isDebugEnabled()) {
log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
}
for (File file : foundWSDLFiles) {
String absWSDLPath = file.getAbsolutePath();
if (log.isDebugEnabled()) {
log.debug("Processing WSDL file: " + absWSDLPath);
}
Definition definition = wsdlReader.readWSDL(null, absWSDLPath);
pathToDefinitionMap.put(absWSDLPath, definition);
}
if (foundWSDLFiles.size() > 0) {
canProcess = true;
}
if (log.isDebugEnabled()) {
log.debug("Successfully processed all WSDL files in path " + path);
}
} catch (WSDLException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
canProcess = false;
}
return canProcess;
}
Aggregations