Search in sources :

Example 1 with WSDLSOAPOperation

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;
}
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 2 with WSDLSOAPOperation

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;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)

Example 3 with WSDLSOAPOperation

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;
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) HashSet(java.util.HashSet)

Example 4 with WSDLSOAPOperation

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);
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with WSDLSOAPOperation

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");
    }
}
Also used : WSDLOperationParam(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam) AbstractList(java.util.AbstractList) List(java.util.List) NodeList(org.w3c.dom.NodeList) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty)

Aggregations

WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)9 ModelImpl (io.swagger.models.ModelImpl)4 ArrayProperty (io.swagger.models.properties.ArrayProperty)3 ObjectProperty (io.swagger.models.properties.ObjectProperty)3 Property (io.swagger.models.properties.Property)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)3 RefProperty (io.swagger.models.properties.RefProperty)2 HashSet (java.util.HashSet)2 List (java.util.List)2 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)2 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)2 NodeList (org.w3c.dom.NodeList)2 APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)2 WSDLInfo (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo)2 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 RefModel (io.swagger.models.RefModel)1