Search in sources :

Example 6 with WSDLOperation

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

the class WSDL11ProcessorImpl method getWsdlInfo.

@Override
public WSDLInfo getWsdlInfo() throws APIMgtWSDLException {
    WSDLInfo wsdlInfo = new WSDLInfo();
    Map<String, String> endpointsMap = getEndpoints();
    Set<WSDLOperation> operations = getHttpBindingOperations();
    wsdlInfo.setEndpoints(endpointsMap);
    wsdlInfo.setVersion(APIMgtConstants.WSDLConstants.WSDL_VERSION_11);
    if (!operations.isEmpty()) {
        wsdlInfo.setHasHttpBindingOperations(true);
        wsdlInfo.setHttpBindingOperations(operations);
    } else {
        wsdlInfo.setHasHttpBindingOperations(false);
    }
    wsdlInfo.setHasSoapBindingOperations(hasSoapBindingOperations());
    return wsdlInfo;
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.core.models.WSDLInfo) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation)

Example 7 with WSDLOperation

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

the class WSDL11ProcessorImpl method getHttpBindingOperations.

/**
 * Retrieves all the operations defined in WSDL(s).
 *
 * @return a set of {@link WSDLOperation} defined in WSDL(s)
 */
private Set<WSDLOperation> getHttpBindingOperations() {
    if (wsdlDefinition != null) {
        return getHttpBindingOperations(wsdlDefinition);
    } else {
        Set<WSDLOperation> allOperations = new HashSet<>();
        for (Definition definition : pathToDefinitionMap.values()) {
            Set<WSDLOperation> operations = getHttpBindingOperations(definition);
            allOperations.addAll(operations);
        }
        return allOperations;
    }
}
Also used : Definition(javax.wsdl.Definition) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) HashSet(java.util.HashSet)

Example 8 with WSDLOperation

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

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

the class APIMWSDLUtils method getUriTemplatesForWSDLOperations.

/**
 * Generates URI templates to be assigned to an API from a set of operations extracted from WSDL.
 *
 * @param operations a Set of {@link WSDLOperation} objects
 * @return Map of URI Templates
 */
public static Map<String, UriTemplate> getUriTemplatesForWSDLOperations(Set<WSDLOperation> operations, boolean isHttpBinding) {
    Map<String, UriTemplate> uriTemplateMap = new HashMap<>();
    // add default "POST /" operation if no http binding methods required or operations are not provided
    if (!isHttpBinding || operations == null || operations.isEmpty()) {
        if (log.isDebugEnabled()) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Adding the POST / operation. ");
            stringBuilder.append("isHttpBinding: ").append(isHttpBinding).append(". ");
            stringBuilder.append("operations are null?: ").append(operations == null).append(". ");
            if (operations != null) {
                stringBuilder.append("operations are empty?: ").append(operations.isEmpty()).append(". ");
            }
            log.debug(stringBuilder.toString());
        }
        UriTemplate.UriTemplateBuilder builderForPOSTRootCtx = new UriTemplate.UriTemplateBuilder();
        builderForPOSTRootCtx.uriTemplate("/");
        builderForPOSTRootCtx.httpVerb("POST");
        builderForPOSTRootCtx.policy(APIUtils.getDefaultAPIPolicy());
        builderForPOSTRootCtx.templateId(APIUtils.generateOperationIdFromPath("/", "POST"));
        uriTemplateMap.put(builderForPOSTRootCtx.getTemplateId(), builderForPOSTRootCtx.build());
        return uriTemplateMap;
    }
    // add URI templates for operations
    for (WSDLOperation operation : operations) {
        if (log.isDebugEnabled()) {
            log.debug("Adding URI template for WSDL operation: " + operation.getVerb() + ", " + operation.getURI());
        }
        UriTemplate.UriTemplateBuilder builder = new UriTemplate.UriTemplateBuilder();
        builder.uriTemplate(operation.getURI().startsWith("/") ? operation.getURI() : "/" + operation.getURI());
        builder.httpVerb(operation.getVerb());
        builder.policy(APIUtils.getDefaultAPIPolicy());
        builder.templateId(APIUtils.generateOperationIdFromPath(builder.getUriTemplate(), operation.getVerb()));
        builder.contentType(operation.getContentType());
        List<URITemplateParam> uriTemplateParams = getUriTemplatesParamsForWSDLOperationParams(operation.getParameters());
        builder.parameters(uriTemplateParams);
        uriTemplateMap.put(builder.getTemplateId(), builder.build());
    }
    return uriTemplateMap;
}
Also used : HashMap(java.util.HashMap) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) URITemplateParam(org.wso2.carbon.apimgt.core.models.URITemplateParam) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

Example 10 with WSDLOperation

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

the class WSDL11SOAPOperationExtractor method getSOAPBindingOperations.

/**
 * Retrieves all the operations defined in the provided Binding.
 *
 * @param binding WSDL binding
 * @return a set of {@link WSDLOperation} defined in the provided Binding
 */
private Set<WSDLSOAPOperation> getSOAPBindingOperations(Binding binding) throws APIMgtWSDLException {
    Set<WSDLSOAPOperation> allBindingOperations = new HashSet<>();
    if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
        List extensibilityElements = binding.getExtensibilityElements();
        for (Object extensibilityElement : extensibilityElements) {
            if (extensibilityElement instanceof SOAPBinding || extensibilityElement instanceof SOAP12Binding) {
                for (Object opObj : binding.getBindingOperations()) {
                    BindingOperation bindingOperation = (BindingOperation) opObj;
                    WSDLSOAPOperation wsdlSoapOperation = getSOAPOperation(bindingOperation);
                    if (wsdlSoapOperation != null) {
                        allBindingOperations.add(wsdlSoapOperation);
                    } else {
                        log.warn("Unable to get soap operation details from binding operation: " + bindingOperation.getName());
                    }
                }
            }
        }
    } else {
        throw new APIMgtWSDLException("Cannot further process to get soap binding operations");
    }
    return allBindingOperations;
}
Also used : SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) BindingOperation(javax.wsdl.BindingOperation) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) WSDLSOAPOperation(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation) HashSet(java.util.HashSet)

Aggregations

WSDLOperation (org.wso2.carbon.apimgt.core.models.WSDLOperation)6 HashSet (java.util.HashSet)5 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)3 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)3 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)3 Binding (javax.wsdl.Binding)2 BindingOperation (javax.wsdl.BindingOperation)2 HTTPBinding (javax.wsdl.extensions.http.HTTPBinding)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Definition (javax.wsdl.Definition)1 Message (javax.wsdl.Message)1 HTTPOperation (javax.wsdl.extensions.http.HTTPOperation)1 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)1 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)1 OMElement (org.apache.axiom.om.OMElement)1 OMNode (org.apache.axiom.om.OMNode)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 Element (org.w3c.dom.Element)1