Search in sources :

Example 6 with WSDLOperation

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

Aggregations

WSDLOperation (org.wso2.carbon.apimgt.core.models.WSDLOperation)6 HashSet (java.util.HashSet)3 HTTPBinding (javax.wsdl.extensions.http.HTTPBinding)2 HashMap (java.util.HashMap)1 Binding (javax.wsdl.Binding)1 BindingOperation (javax.wsdl.BindingOperation)1 Definition (javax.wsdl.Definition)1 HTTPOperation (javax.wsdl.extensions.http.HTTPOperation)1 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)1 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)1 URITemplateParam (org.wso2.carbon.apimgt.core.models.URITemplateParam)1 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)1 WSDLInfo (org.wso2.carbon.apimgt.core.models.WSDLInfo)1 WSDLOperationParam (org.wso2.carbon.apimgt.core.models.WSDLOperationParam)1