use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method updateEndpointsOfWSDLArchive.
/**
* Update the endpoint information of the WSDL (WSDL archive scenario) when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfWSDLArchive(API api, String environmentName, String environmentType) throws APIMgtWSDLException {
for (Map.Entry<String, Description> entry : pathToDescriptionMap.entrySet()) {
Description description = entry.getValue();
if (log.isDebugEnabled()) {
log.debug("Updating endpoints of WSDL: " + entry.getKey());
}
updateEndpointsOfSingleWSDL(api, environmentName, environmentType, description);
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(description.toElement(), wsdlFileOutputStream);
} catch (IOException | WSDLException e) {
throw new APIMgtWSDLException("Failed to create WSDL archive for API:" + api.getId().getName() + ":" + api.getId().getVersion() + " for environment " + environmentName, e, ExceptionCodes.ERROR_WHILE_CREATING_WSDL_ARCHIVE);
}
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSoapMessageType.
/**
* Gets message type for a given soap operation
*
* @param bindingOperation soap operation
* @return String for message type
* @throws APIMgtWSDLException
*/
private String getSoapMessageType(BindingOperation bindingOperation) throws APIMgtWSDLException {
Operation operation = bindingOperation.getOperation();
String messageType = "";
boolean hasRPCMessages = false;
if (operation != null) {
Input input = operation.getInput();
if (input != null) {
Message message = input.getMessage();
if (message != null) {
Map map = message.getParts();
for (Object obj : map.entrySet()) {
Map.Entry entry = (Map.Entry) obj;
Part part = (Part) entry.getValue();
if (part != null) {
if (part.getElementName() != null) {
messageType = "document";
} else if (part.getTypeName() != null) {
messageType = "rpc";
hasRPCMessages = true;
}
}
}
}
}
}
if (hasRPCMessages) {
return "rpc";
} else {
return messageType;
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSOAPBindingOperations.
/**
* Retrieves all the operations defined in the provided Binding.
*
* @param binding WSDL binding
* @return a set of {@link WSDLOperation} defined in the provided Binding
*/
private Set<WSDLSOAPOperation> getSOAPBindingOperations(Binding binding) throws APIMgtWSDLException {
Set<WSDLSOAPOperation> allBindingOperations = new HashSet<>();
if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
List extensibilityElements = binding.getExtensibilityElements();
for (Object extensibilityElement : extensibilityElements) {
if (extensibilityElement instanceof SOAPBinding || extensibilityElement instanceof SOAP12Binding) {
for (Object opObj : binding.getBindingOperations()) {
BindingOperation bindingOperation = (BindingOperation) opObj;
WSDLSOAPOperation wsdlSoapOperation = getSOAPOperation(bindingOperation);
if (wsdlSoapOperation != null) {
allBindingOperations.add(wsdlSoapOperation);
} else {
log.warn("Unable to get soap operation details from binding operation: " + bindingOperation.getName());
}
}
}
}
} else {
throw new APIMgtWSDLException("Cannot further process to get soap binding operations");
}
return allBindingOperations;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSoapInputParameterModel.
/**
* Gets swagger input parameter model for a given soap operation
*
* @param bindingOperation soap operation
* @return list of swagger models for the parameters
* @throws APIMgtWSDLException
*/
private List<ModelImpl> getSoapInputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
List<ModelImpl> inputParameterModelList = new ArrayList<>();
Operation operation = bindingOperation.getOperation();
if (operation != null) {
Input input = operation.getInput();
if (input != null) {
Message message = input.getMessage();
if (message != null) {
Map map = message.getParts();
for (Object obj : map.entrySet()) {
Map.Entry entry = (Map.Entry) obj;
Part part = (Part) entry.getValue();
if (part != null) {
if (part.getElementName() != null) {
inputParameterModelList.add(parameterModelMap.get(part.getElementName().getLocalPart()));
} else {
if (part.getTypeName() != null && parameterModelMap.containsKey(part.getTypeName().getLocalPart())) {
inputParameterModelList.add(parameterModelMap.get(part.getTypeName().getLocalPart()));
} else if (part.getTypeName() != null && parameterModelMap.containsKey(message.getQName().getLocalPart())) {
ModelImpl model = parameterModelMap.get(message.getQName().getLocalPart());
model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
parameterModelMap.put(model.getName(), model);
inputParameterModelList.add(model);
} else {
ModelImpl model;
if (parameterModelMap.get(message.getQName().getLocalPart()) != null) {
model = parameterModelMap.get(message.getQName().getLocalPart());
} else {
model = new ModelImpl();
model.setType(ObjectProperty.TYPE);
model.setName(message.getQName().getLocalPart());
}
if (getPropertyFromDataType(part.getTypeName().getLocalPart()) instanceof RefProperty) {
RefProperty property = (RefProperty) getPropertyFromDataType(part.getTypeName().getLocalPart());
property.set$ref(SOAPToRESTConstants.Swagger.DEFINITIONS_ROOT + part.getTypeName().getLocalPart());
model.addProperty(part.getName(), property);
} else {
model.addProperty(part.getName(), getPropertyFromDataType(part.getTypeName().getLocalPart()));
}
parameterModelMap.put(model.getName(), model);
inputParameterModelList.add(model);
}
}
}
}
}
}
}
return inputParameterModelList;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException in project carbon-apimgt by wso2.
the class APIMWSDLReader method getWSDLProcessorForUrl.
/**
* Returns the appropriate WSDL 1.1/WSDL 2.0 based on the url {@code url}.
*
* @param url WSDL url
* @return WSDL 1.1/2.0 processor for the provided content
* @throws APIManagementException If an error occurs while determining the processor
*/
public static WSDLProcessor getWSDLProcessorForUrl(URL url) throws APIManagementException {
WSDLProcessor wsdl11Processor = new WSDL11ProcessorImpl();
WSDLProcessor wsdl20Processor = new WSDL20ProcessorImpl();
try {
if (wsdl11Processor.canProcess(url)) {
wsdl11Processor.init(url);
return wsdl11Processor;
} else if (wsdl20Processor.canProcess(url)) {
wsdl20Processor.init(url);
return wsdl20Processor;
} else {
// no processors found if this line reaches
throw new APIManagementException("No WSDL processor found to process WSDL url: " + url, ExceptionCodes.URL_NOT_RECOGNIZED_AS_WSDL);
}
} catch (APIMgtWSDLException e) {
throw new APIManagementException("Error while instantiating wsdl processor class", e);
}
}
Aggregations