use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSOAPOperation.
/**
* Retrieves WSDL operation given the soap binding operation
*
* @param bindingOperation {@link BindingOperation} object
* @return a set of {@link WSDLOperation} defined in the provided Binding
*/
private WSDLSOAPOperation getSOAPOperation(BindingOperation bindingOperation) throws APIMgtWSDLException {
WSDLSOAPOperation wsdlOperation = null;
for (Object boExtElement : bindingOperation.getExtensibilityElements()) {
if (boExtElement instanceof SOAPOperation) {
SOAPOperation soapOperation = (SOAPOperation) boExtElement;
wsdlOperation = new WSDLSOAPOperation();
wsdlOperation.setName(bindingOperation.getName());
wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
wsdlOperation.setStyle(soapOperation.getStyle());
wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
} else if (boExtElement instanceof SOAP12Operation) {
SOAP12Operation soapOperation = (SOAP12Operation) boExtElement;
wsdlOperation = new WSDLSOAPOperation();
wsdlOperation.setName(bindingOperation.getName());
wsdlOperation.setSoapAction(soapOperation.getSoapActionURI());
wsdlOperation.setTargetNamespace(getTargetNamespace(bindingOperation));
wsdlOperation.setStyle(soapOperation.getStyle());
wsdlOperation.setInputParameterModel(getSoapInputParameterModel(bindingOperation));
wsdlOperation.setOutputParameterModel(getSoapOutputParameterModel(bindingOperation));
wsdlOperation.setMessageType(getSoapMessageType(bindingOperation));
}
}
return wsdlOperation;
}
use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getWsdlInfo.
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
WSDLInfo wsdlInfo = new WSDLInfo();
if (wsdlDefinition != null) {
Set<WSDLSOAPOperation> soapOperations = getSoapBindingOperations(wsdlDefinition);
wsdlInfo.setVersion(WSDL_VERSION_11);
if (!soapOperations.isEmpty()) {
wsdlInfo.setHasSoapBindingOperations(true);
wsdlInfo.setSoapBindingOperations(soapOperations);
} else {
wsdlInfo.setHasSoapBindingOperations(false);
}
wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
wsdlInfo.setHasSoap12BindingOperations(hasSoap12BindingOperations());
if (parameterModelMap.size() > 0) {
wsdlInfo.setParameterModelMap(parameterModelMap);
}
} else {
throw new APIMgtWSDLException("WSDL Definition is not initialized.");
}
return wsdlInfo;
}
use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation 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.impl.wsdl.model.WSDLSOAPOperation in project carbon-apimgt by wso2.
the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelForWSDLsWithCompositeBindings.
@Test
public void testGetSwaggerModelForWSDLsWithCompositeBindings() throws Exception {
APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/wsdl-with-composite-bindings/sampleservice.wsdl").toExternalForm());
byte[] wsdlContent = wsdlReader.getWSDL();
WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent, wsdlReader);
Set<WSDLSOAPOperation> operations = processor.getWsdlInfo().getSoapBindingOperations();
Assert.assertNotNull(operations);
Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
Assert.assertNotNull(parameterModelMap);
}
use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation in project carbon-apimgt by wso2.
the class SOAPOperationBindingUtils method populateSoapOperationParameters.
/**
* gets parameters from the soap operation and populates them in {@link WSDLSOAPOperation}
*
* @param soapOperations soap binding operations
*/
private static void populateSoapOperationParameters(Set<WSDLSOAPOperation> soapOperations) {
String[] primitiveTypes = { "string", "byte", "short", "int", "long", "float", "double", "boolean" };
List primitiveTypeList = Arrays.asList(primitiveTypes);
if (soapOperations != null) {
for (WSDLSOAPOperation operation : soapOperations) {
String resourcePath;
String operationName = operation.getName();
operation.setSoapBindingOpName(operationName);
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_POST);
if (operationName.toLowerCase().startsWith("get") && operation.getInputParameterModel() != null && operation.getInputParameterModel().size() <= 1) {
Map<String, Property> properties = null;
if (operation.getInputParameterModel().size() > 0 && operation.getInputParameterModel().get(0) != null) {
properties = operation.getInputParameterModel().get(0).getProperties();
}
if (properties == null) {
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
} else if (properties.size() <= 1) {
for (String property : properties.keySet()) {
String type = properties.get(property).getType();
if (!(type.equals(ObjectProperty.TYPE) || type.equals(ArrayProperty.TYPE) || type.equals(RefProperty.TYPE))) {
operation.setHttpVerb(HTTPConstants.HTTP_METHOD_GET);
}
}
}
}
resourcePath = operationName;
resourcePath = resourcePath.substring(0, 1).toLowerCase() + resourcePath.substring(1, resourcePath.length());
operation.setName(resourcePath);
if (log.isDebugEnabled()) {
log.debug("REST resource path for SOAP operation: " + operationName + " is: " + resourcePath);
}
List<WSDLOperationParam> params = operation.getParameters();
if (log.isDebugEnabled() && params != null) {
log.debug("SOAP operation: " + operationName + " has " + params.size() + " parameters");
}
if (params != null) {
for (WSDLOperationParam param : params) {
if (param.getDataType() != null) {
String dataTypeWithNS = param.getDataType();
String dataType = dataTypeWithNS.substring(dataTypeWithNS.indexOf(":") + 1);
param.setDataType(dataType);
if (!primitiveTypeList.contains(dataType)) {
param.setComplexType(true);
}
}
}
}
}
} else {
log.info("No SOAP operations found in the WSDL");
}
}
Aggregations