use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation 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.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class WSDL11SOAPOperationExtractor method getSoapOutputParameterModel.
/**
* Gets swagger output parameter model for a given soap operation
*
* @param bindingOperation soap operation
* @return list of swagger models for the parameters
* @throws APIMgtWSDLException
*/
private List<ModelImpl> getSoapOutputParameterModel(BindingOperation bindingOperation) throws APIMgtWSDLException {
List<ModelImpl> outputParameterModelList = new ArrayList<>();
Operation operation = bindingOperation.getOperation();
if (operation != null) {
Output output = operation.getOutput();
if (output != null) {
Message message = output.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) {
outputParameterModelList.add(parameterModelMap.get(part.getElementName().getLocalPart()));
} else {
if (part.getTypeName() != null && parameterModelMap.containsKey(part.getTypeName().getLocalPart())) {
outputParameterModelList.add(parameterModelMap.get(part.getTypeName().getLocalPart()));
} else {
ModelImpl 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);
outputParameterModelList.add(model);
}
}
}
}
}
}
}
return outputParameterModelList;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation 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.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class SequenceUtils method saveRestToSoapConvertedSequence.
/**
* Saves the converted api sequence in the registry for the given resource path
*
* @param registry user registry reference
* @param sequence sequence to be saved
* @param method http method of the operation
* @param resourcePath registry resource path
* @throws APIManagementException throws errors on if the resource persistence gets unsuccessful
*/
public static void saveRestToSoapConvertedSequence(UserRegistry registry, String sequence, String method, String resourcePath, String apiResourceName) throws APIManagementException {
try {
Resource regResource;
if (apiResourceName.startsWith(SOAPToRESTConstants.SequenceGen.PATH_SEPARATOR)) {
apiResourceName = apiResourceName.substring(1);
}
if (!registry.resourceExists(resourcePath)) {
regResource = registry.newResource();
} else {
regResource = registry.get(resourcePath);
}
regResource.setContent(sequence);
regResource.addProperty(SOAPToRESTConstants.METHOD, method);
if (regResource.getProperty(SOAPToRESTConstants.Template.RESOURCE_PATH) != null) {
regResource.removeProperty(SOAPToRESTConstants.Template.RESOURCE_PATH);
}
regResource.addProperty(SOAPToRESTConstants.Template.RESOURCE_PATH, apiResourceName);
regResource.setMediaType("text/xml");
registry.put(resourcePath, regResource);
} catch (RegistryException e) {
handleException("Error occurred while accessing the registry to save api sequence", e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
handleException("Error occurred while saving api sequence", e);
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class SequenceUtils method getRestToSoapConvertedSequence.
/**
* Gets soap to rest converted sequence from the registry
* <p>
* Note: this method is directly invoked from the jaggery layer
*
* @param api API
* @param seqType to identify the sequence is whether in/out sequence
* @return converted sequences string for a given operation
* @throws APIManagementException throws exceptions on unsuccessful retrieval of resources in registry
*/
public static String getRestToSoapConvertedSequence(API api, String seqType) throws APIManagementException {
JSONObject resultJson = new JSONObject();
List<SOAPToRestSequence> sequences = api.getSoapToRestSequences();
if (sequences == null) {
handleException("Cannot find any resource policies for the api " + api.getUuid());
}
for (SOAPToRestSequence sequence : sequences) {
if (sequence.getDirection().toString().equalsIgnoreCase(seqType)) {
String content = sequence.getContent();
String resourceName = sequence.getPath();
String httpMethod = sequence.getMethod();
Map<String, String> resourceMap = new HashMap<>();
resourceMap.put(SOAPToRESTConstants.RESOURCE_ID, sequence.getUuid());
resourceMap.put(SOAPToRESTConstants.METHOD, httpMethod);
resourceMap.put(SOAPToRESTConstants.CONTENT, content);
resultJson.put(resourceName + "_" + httpMethod, resourceMap);
}
}
if (log.isDebugEnabled()) {
log.debug("Saved sequence for type " + seqType + " for api:" + api.getId().getProviderName() + "-" + api.getId().getApiName() + "-" + api.getId().getVersion() + " is: " + resultJson.toJSONString());
}
return resultJson.toJSONString();
}
Aggregations