Search in sources :

Example 96 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.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;
}
Also used : WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)

Example 97 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.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;
}
Also used : Message(javax.wsdl.Message) Part(javax.wsdl.Part) Output(javax.wsdl.Output) ArrayList(java.util.ArrayList) Operation(javax.wsdl.Operation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperation) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) RefProperty(io.swagger.models.properties.RefProperty)

Example 98 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.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);
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) WSDL11SOAPOperationExtractor(org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)

Example 99 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.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);
    }
}
Also used : Resource(org.wso2.carbon.registry.api.Resource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 100 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.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();
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) SOAPToRestSequence(org.wso2.carbon.apimgt.api.model.SOAPToRestSequence)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)79 HashMap (java.util.HashMap)55 ArrayList (java.util.ArrayList)43 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)42 Test (org.testng.annotations.Test)34 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)29 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 Map (java.util.Map)28 IOException (java.io.IOException)23 API (org.wso2.carbon.apimgt.api.model.API)22 List (java.util.List)20 JSONObject (org.json.simple.JSONObject)20 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)20 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)19 LinkedHashMap (java.util.LinkedHashMap)18 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)18 OperationPolicyData (org.wso2.carbon.apimgt.api.model.OperationPolicyData)18 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16