From 00e57bd800152c8dddcae1443f508a7a648639e6 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Mon, 24 Oct 2016 16:31:41 +0530 Subject: [PATCH] Fixing the empty methods for resources in the synapse configuration issue when auto publishing the apis for the REST service. --- .../publisher/APIPublisherServiceImpl.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 874bf1b726..13c9aa04ea 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -64,6 +64,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { CommonUtil.getRootSystemRegistry(tenantId)); APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner()); MultitenantUtils.getTenantDomain(api.getApiOwner()); + processHttpVerbs(api); if (provider != null) { if (provider.isDuplicateContextTemplate(api.getContext())) { throw new APIManagementException( @@ -172,6 +173,31 @@ public class APIPublisherServiceImpl implements APIPublisherService { return swaggerDefinition.toString(); } + /** + * Sometimes the httpVerb string attribute is not existing in + * the list of httpVerbs attribute of uriTemplate. In such cases when creating the api in the + * synapse configuration, it doesn't have http methods correctly assigned for the resources. + * Therefore this method takes care of such inconsistency issue. + * + * @param api The actual API model object + */ + private void processHttpVerbs(API api){ + for (URITemplate uriTemplate : api.getUriTemplates()){ + String httpVerbString = uriTemplate.getHTTPVerb(); + String[] httpVerbs = uriTemplate.getMethodsAsString().split(" "); + boolean httpVerbStringExistsMethods = false; + for (String aHttpVerb: httpVerbs){ + if (aHttpVerb.trim().equalsIgnoreCase(httpVerbString)){ + httpVerbStringExistsMethods = true; + break; + } + } + if (!httpVerbStringExistsMethods){ + uriTemplate.setHttpVerbs(httpVerbString); + } + } + } + @Override public void removeAPI(APIIdentifier id) throws APIManagementException { if (log.isDebugEnabled()) {