Search in sources :

Example 1 with WSDLOperationParam

use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getParameters.

/**
 * Returns parameters, given http binding operation, verb and content type
 *
 * @param bindingOperation {@link BindingOperation} object
 * @param verb             HTTP verb
 * @param contentType      Content type
 * @return parameters, given http binding operation, verb and content type
 */
private List<WSDLOperationParam> getParameters(BindingOperation bindingOperation, String verb, String contentType) {
    List<WSDLOperationParam> params = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    // or content type is not provided
    if (APIMWSDLUtils.canContainBody(verb) && !APIMWSDLUtils.hasFormDataParams(contentType)) {
        WSDLOperationParam param = new WSDLOperationParam();
        param.setName("Payload");
        param.setParamType(WSDLOperationParam.ParamTypeEnum.BODY);
        params.add(param);
        if (log.isDebugEnabled()) {
            log.debug("Adding default Param for operation:" + operation.getName() + ", contentType: " + contentType);
        }
        return params;
    }
    if (operation != null) {
        Input input = operation.getInput();
        if (input != null) {
            Message message = input.getMessage();
            if (message != null) {
                Map map = message.getParts();
                map.forEach((name, partObj) -> {
                    WSDLOperationParam param = new WSDLOperationParam();
                    param.setName(name.toString());
                    if (log.isDebugEnabled()) {
                        log.debug("Identified param for operation: " + operation.getName() + " param: " + name);
                    }
                    if (APIMWSDLUtils.canContainBody(verb)) {
                        if (log.isDebugEnabled()) {
                            log.debug("Operation " + operation.getName() + " can contain a body.");
                        }
                        // In POST, PUT operations, parameters always in body according to HTTP Binding spec
                        if (APIMWSDLUtils.hasFormDataParams(contentType)) {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.FORM_DATA);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to formData.");
                            }
                        }
                    // no else block since if content type is not form-data related, there can be only one
                    // parameter which is payload body. This is handled in the first if block which is
                    // if (canContainBody(verb) && !hasFormDataParams(contentType)) { .. }
                    } else {
                        // In GET operations, parameters always query or path as per HTTP Binding spec
                        if (isUrlReplacement(bindingOperation)) {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.PATH);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to Path.");
                            }
                        } else {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.QUERY);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to Query.");
                            }
                        }
                    }
                    Part part = (Part) partObj;
                    param.setDataType(part.getTypeName().getLocalPart());
                    if (log.isDebugEnabled()) {
                        log.debug("Param " + name + " data type was set to " + param.getDataType());
                    }
                    params.add(param);
                });
            }
        }
    }
    return params;
}
Also used : WSDLOperationParam(org.wso2.carbon.apimgt.core.models.WSDLOperationParam) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) Message(javax.wsdl.Message) Part(javax.wsdl.Part) ArrayList(java.util.ArrayList) Operation(javax.wsdl.Operation) HTTPOperation(javax.wsdl.extensions.http.HTTPOperation) BindingOperation(javax.wsdl.BindingOperation) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with WSDLOperationParam

use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getOperation.

/**
 * Retrieves WSDL operation given the binding operation and http verb
 *
 * @param bindingOperation {@link BindingOperation} object
 * @param verb             HTTP verb
 * @return WSDL operation for the given binding operation and http verb
 */
private WSDLOperation getOperation(BindingOperation bindingOperation, String verb) {
    WSDLOperation wsdlOperation = null;
    for (Object boExtElement : bindingOperation.getExtensibilityElements()) {
        if (boExtElement instanceof HTTPOperation) {
            HTTPOperation httpOperation = (HTTPOperation) boExtElement;
            if (!StringUtils.isBlank(httpOperation.getLocationURI())) {
                wsdlOperation = new WSDLOperation();
                wsdlOperation.setVerb(verb);
                wsdlOperation.setURI(APIMWSDLUtils.replaceParentheses(httpOperation.getLocationURI()));
                if (log.isDebugEnabled()) {
                    log.debug("Found HTTP Binding operation; name: " + bindingOperation.getName() + " [" + wsdlOperation.getVerb() + " " + wsdlOperation.getURI() + "]");
                }
                if (APIMWSDLUtils.canContainBody(verb)) {
                    String boContentType = getContentType(bindingOperation.getBindingInput());
                    wsdlOperation.setContentType(boContentType != null ? boContentType : TEXT_XML_MEDIA_TYPE);
                }
                List<WSDLOperationParam> paramList = getParameters(bindingOperation, verb, wsdlOperation.getContentType());
                wsdlOperation.setParameters(paramList);
            }
        }
    }
    return wsdlOperation;
}
Also used : HTTPOperation(javax.wsdl.extensions.http.HTTPOperation) WSDLOperationParam(org.wso2.carbon.apimgt.core.models.WSDLOperationParam) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation)

Example 3 with WSDLOperationParam

use of org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam 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

HTTPOperation (javax.wsdl.extensions.http.HTTPOperation)2 WSDLOperation (org.wso2.carbon.apimgt.core.models.WSDLOperation)2 WSDLOperationParam (org.wso2.carbon.apimgt.core.models.WSDLOperationParam)2 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 ObjectProperty (io.swagger.models.properties.ObjectProperty)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BindingInput (javax.wsdl.BindingInput)1 BindingOperation (javax.wsdl.BindingOperation)1 Input (javax.wsdl.Input)1 Message (javax.wsdl.Message)1 Operation (javax.wsdl.Operation)1 Part (javax.wsdl.Part)1 NodeList (org.w3c.dom.NodeList)1 WSDLOperationParam (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLOperationParam)1