Search in sources :

Example 1 with WSDLOperationParam

use of org.wso2.carbon.apimgt.core.models.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.core.models.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)

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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)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