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;
}
Aggregations